#!/usr/bin/perl -w use strict; my %opt=@ARGV; my $opt_l=$opt{'-l'}; ## list of gene IDs open (LIST, "$opt_l") || die "cannot open list of gene IDs"; my @list = ; foreach my $thing (@list) { chomp $thing; #write R script to convert newick trees to nexus trees open (OUT, ">ape_nexus_convert.R"); my $script = "#!/usr/bin/env Rscript\nlibrary(\"ape\")\nmytree <- read.tree(\"RAxML_bootstrap.$thing\")\nwrite.nexus(myt ree, file = \"$thing.R.nexus\")\nq()"; print OUT $script; close OUT; #execute R script `chmod 755 ape_nexus_convert.R`; `./ape_nexus_convert.R`; `rm ape_nexus_convert.R`; open(I,"$thing.R.nexus")|| die "cannot open nexus file\n"; open(O, ">$thing.nexus") || die "cannot open outfile\n"; my $check = 0; my $count = 0; #tweak file format while () { if ($_ =~ /TREE \* UNTITLED = \[&U\]/) {$count ++;} $_ =~ s/TREE \* UNTITLED = \[&U\]/tree rep\.$count =/; if ($_ =~ /BEGIN TAXA/){$check =1;} if ($_ =~ /BEGIN TREES/) {$check = 0;} if (!$check) {print O $_}; } `rm $thing.R.nexus`; }