forked from z0on/annotatingTranscriptomes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddAnnotField.pl
executable file
·47 lines (38 loc) · 901 Bytes
/
addAnnotField.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
my $usage= "
addAnnotField:
inserts \"gene=QWERTY\" annotations into fasta headers
where QUERTY is the gene name (or cluster ID) taken from
a tab-delimited table of seq id - gene name
Arguments:
1. fasta file
2. seqID-geneName table
prints to STDOUT.
";
my $fasta=shift(@ARGV) or die $usage;
my $table=shift(@ARGV) or die $usage;
open TAB, $table or die "$usage\n\ncannot open gene names table $table\n";
open FAS, $fasta or die "$usage\n\ncannot open fasta $fasta\n";
my %seq2gene={};
my $seq;
my $gene;
while (<TAB>) {
($seq,$gene)=split(/[\t,]/,$_);
$seq=~s/\.([\w\d]).+/\.$1/;
$seq2gene{$seq}=$gene;
}
close TAB;
while (<FAS>) {
chop;
if ($_=~/^>(\S+)/) {
$seq=$1;
$seq=~s/\.([\w\d]).+/\.$1/;
if ($seq2gene{$seq}) { print "$_ gene=$seq2gene{$seq}\n";}
else {
warn "no gene for $seq\n";
print "$_ gene=$seq\n";
}
}
else { print "$_\n";}
}
close FAS;