-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathpf2g.pl
executable file
·93 lines (84 loc) · 2.02 KB
/
pf2g.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
# Script pf2g.pl
# Description: Takes a list of pfam IDs and maps them to go terms
# Author: Steven Ahrendt
# email: [email protected]
# Date: 10.23.13
##################################
use warnings;
use strict;
use Data::Dumper;
use Getopt::Long;
#####-----Global Variables-----#####
my $input; # command line input
my @pfamlist;
my $pfam2go = "/rhome/sahrendt/Data/GO/pfam2go"; # pfam2go mapping file
my ($help,$verb);
my %PFGOMAP;
GetOptions ('i|input=s' => \$input,
'g|go=s' => \$pfam2go,
'h|help' => \$help,
'v|verbose' => \$verb);
my $usage = "pf2g.pl -i pfamlist [-g pfam2go]\n";
die $usage if $help;
die $usage if (!$input);
if(open(LIST,"<$input"))
{
@pfamlist = <LIST>;
chomp @pfamlist;
close(LIST);
}
else
{
warn "Assuming $input is PFAM ID, not file\n";
push (@pfamlist,$input);
}
## Setup hash for pfam2go data
makeHash($pfam2go);
## Print the GO IDs
printIDs(\@pfamlist);
warn "Done.\n";
exit(0);
#####-----Subroutines-----#####
sub printIDs {
my @list = @{$_[0]};
foreach my $PFID (@list)
{
$PFID =~ s/\.\d+//; # chomp off decimal number
#print "$PFID\n";
if (exists $PFGOMAP{$PFID})
{
my $numGO = scalar @{$PFGOMAP{$PFID}{"GO"}{"ids"}};
for(my $i=0;$i<$numGO;$i++)
{
print $PFGOMAP{$PFID}{"GO"}{"ids"}[$i],"\n";
}
}
else
{
warn "$PFID\n";
}
}
}
sub makeHash {
my $file = shift;
open(P2G, '<', $file) or die "Can't open $file: $!\n";
while(my $line = <P2G>)
{
chomp $line;
next if ($line =~ m/^!/);
#print $line,"\n";
#my ($PID,$Pdesc,$GOdesc,$GOID);
my ($pf,$go) = split(/>/,$line);
#print join("--",$pf,$go),"\n";
my ($tmp,$PID,$Pdesc,@tmp2) = split(/[:| ]/,$pf);
#print $PID,"--",$Pdesc,"\n";
my ($GOdesc,$GOID) = split(/ ; /,$go);
$GOdesc =~ s/^\s//;
#print " $GOID--$GOdesc\n";
$PFGOMAP{$PID}{"desc"} = $Pdesc;
push (@{$PFGOMAP{$PID}{"GO"}{"ids"}}, $GOID);
push (@{$PFGOMAP{$PID}{"GO"}{"desc"}},$GOdesc);
}
close(P2G);
}