annotate complete_names.pl @ 2:bba379e32116 draft

Uploaded
author dereeper
date Tue, 08 Jan 2019 10:14:49 -0500
parents
children 637ed4e3aa1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
bba379e32116 Uploaded
dereeper
parents:
diff changeset
1 use strict;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
2
bba379e32116 Uploaded
dereeper
parents:
diff changeset
3 my $fasta = $ARGV[0];
bba379e32116 Uploaded
dereeper
parents:
diff changeset
4 my $phylip = $ARGV[1];
bba379e32116 Uploaded
dereeper
parents:
diff changeset
5 my $out = $ARGV[2];
bba379e32116 Uploaded
dereeper
parents:
diff changeset
6
bba379e32116 Uploaded
dereeper
parents:
diff changeset
7 my @ids;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
8 open(F,$fasta) or die "Can not open file $fasta";
bba379e32116 Uploaded
dereeper
parents:
diff changeset
9 while(<F>){
bba379e32116 Uploaded
dereeper
parents:
diff changeset
10 if (/>(.*)/){
bba379e32116 Uploaded
dereeper
parents:
diff changeset
11 my $id = $1;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
12 push(@ids,$id);
bba379e32116 Uploaded
dereeper
parents:
diff changeset
13 }
bba379e32116 Uploaded
dereeper
parents:
diff changeset
14 }
bba379e32116 Uploaded
dereeper
parents:
diff changeset
15 close(F);
bba379e32116 Uploaded
dereeper
parents:
diff changeset
16
bba379e32116 Uploaded
dereeper
parents:
diff changeset
17 open(O,">$out") or die "Can not open and write into file $out";
bba379e32116 Uploaded
dereeper
parents:
diff changeset
18 open(P,$phylip) or die "Can not open file $phylip";
bba379e32116 Uploaded
dereeper
parents:
diff changeset
19 my $numline = 0;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
20 while(<P>){
bba379e32116 Uploaded
dereeper
parents:
diff changeset
21 my $line = $_;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
22 $numline++;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
23 if (/^([\w\-]+)\s+/ && $numline > 1){
bba379e32116 Uploaded
dereeper
parents:
diff changeset
24 my $reported_id = $1;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
25 print "ok";
bba379e32116 Uploaded
dereeper
parents:
diff changeset
26 my $id = $ids[$numline-2];
bba379e32116 Uploaded
dereeper
parents:
diff changeset
27 $line =~s/$reported_id/$id/g;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
28 print O $line;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
29 }
bba379e32116 Uploaded
dereeper
parents:
diff changeset
30 else{
bba379e32116 Uploaded
dereeper
parents:
diff changeset
31 print O $line;
bba379e32116 Uploaded
dereeper
parents:
diff changeset
32 }
bba379e32116 Uploaded
dereeper
parents:
diff changeset
33 }
bba379e32116 Uploaded
dereeper
parents:
diff changeset
34 close(P);
bba379e32116 Uploaded
dereeper
parents:
diff changeset
35 close(O);