2
|
1 use strict;
|
|
2
|
|
3 my $fasta = $ARGV[0];
|
|
4 my $phylip = $ARGV[1];
|
|
5 my $out = $ARGV[2];
|
|
6
|
|
7 my @ids;
|
|
8 open(F,$fasta) or die "Can not open file $fasta";
|
|
9 while(<F>){
|
|
10 if (/>(.*)/){
|
|
11 my $id = $1;
|
|
12 push(@ids,$id);
|
|
13 }
|
|
14 }
|
|
15 close(F);
|
|
16
|
|
17 open(O,">$out") or die "Can not open and write into file $out";
|
|
18 open(P,$phylip) or die "Can not open file $phylip";
|
|
19 my $numline = 0;
|
|
20 while(<P>){
|
|
21 my $line = $_;
|
|
22 $numline++;
|
|
23 if (/^([\w\-]+)\s+/ && $numline > 1){
|
|
24 my $reported_id = $1;
|
|
25 my $id = $ids[$numline-2];
|
|
26 $line =~s/$reported_id/$id/g;
|
|
27 print O $line;
|
|
28 }
|
|
29 else{
|
|
30 print O $line;
|
|
31 }
|
|
32 }
|
|
33 close(P);
|
|
34 close(O);
|