| 1 |
|
| 2 |
use strict; |
| 3 |
|
| 4 |
open(INFILE, "< $ARGV[0]") or die "could not open input file! (".$ARGV[0].")\n"; |
| 5 |
open(OUTFILE, "> $ARGV[1]") or die "could not open output file! (".$ARGV[1].")\n"; |
| 6 |
open(DB, "< $ARGV[2]") or die "could not open output file! (".$ARGV[2].")\n"; |
| 7 |
|
| 8 |
my $db = join("", <DB>); |
| 9 |
|
| 10 |
|
| 11 |
while(my $line=<INFILE>) { |
| 12 |
|
| 13 |
if(substr($line,0,1) eq '#') { |
| 14 |
|
| 15 |
my @split = split(/\s+/,$line); |
| 16 |
|
| 17 |
my @GOs = split(/,/,$split[1]); |
| 18 |
|
| 19 |
for(my $i; $i < @GOs.length; $i++) { |
| 20 |
|
| 21 |
$GOs[$i] = 'GO:'.$GOs[$i]; |
| 22 |
} |
| 23 |
$split[1] = join(',',@GOs); |
| 24 |
|
| 25 |
print OUTFILE join("\t",@split)."\n"; |
| 26 |
} elsif (substr($line,0,1) eq '>') { |
| 27 |
|
| 28 |
my $pattern = $line; |
| 29 |
chomp $pattern; |
| 30 |
$pattern =~ s/-/\\|/; |
| 31 |
|
| 32 |
$db =~ /($pattern):([^\n]*)/; |
| 33 |
my $id = $1; |
| 34 |
|
| 35 |
my @GOs = split(/,/,$2); |
| 36 |
|
| 37 |
for(my $i; $i < @GOs.length; $i++) { |
| 38 |
|
| 39 |
$GOs[$i] = 'GO:'.$GOs[$i]; |
| 40 |
} |
| 41 |
my $gos = join(',',@GOs); |
| 42 |
|
| 43 |
print OUTFILE $id."\t".$gos."\n"; |
| 44 |
|
| 45 |
} else { |
| 46 |
print OUTFILE $line; |
| 47 |
} |
| 48 |
} |