-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOG_from_ClassDescriptions.pl
executable file
·150 lines (121 loc) · 4.2 KB
/
COG_from_ClassDescriptions.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env perl
#
#
# Anne de Jong
#
# November , 2016
#
# GSEA-pro; Make COG functional categories
# Use description of several classes to get the COG functional categories
#
#
use warnings;
use strict;
use lib "/usr/molgentools/lib";
use anne_files ;
use anne_misc ;
my $sessiondir = '.';
my $genome = "/var/genomes/g2d_mirror/Lactococcus_lactis_subsp_cremoris_MG1363/ASM942v1_genomic" ;
my $usage = "/usr/molgentools/gsea_pro/COG_from_ClassDescriptions.pl -i genome_base_name
GSEA-pro; Derive COG functional classes from IPR and GO description match
More info at https://www.ncbi.nlm.nih.gov/COG/
download cognames2003-2014.tab and fun2003-2014.tab from ftp://ftp.ncbi.nih.gov/pub/COG/COG2014/data/
parameters:
-i genome base name [e.g. $genome]
e.g. /usr/molgentools/gsea_pro/COG_from_ClassDescriptions.pl -i /var/genomes/g2d_mirror/Lactococcus_lactis_subsp_cremoris_MG1363/ASM942v1_genomic
";
# -------------------------------------------- main -----------------------------------------------------------------------------------------------
parseparam();
my %cognames = get_cognames('/usr/molgentools/gsea_pro/cognames2003-2014.tab');
my %cogfun = get_cogfun('/usr/molgentools/gsea_pro/fun2003-2014.tab');
my @lines = screen_class_4_matches("$genome.g2d.IPR") ; # find matches in the IPR class
push @lines, screen_class_4_matches("$genome.g2d.GO") ; # add matches from the GO class
push @lines, screen_class_4_matches("$genome.g2d.KEGG") ; # add matches from the KEGG class
push @lines, screen_class_4_matches("$genome.g2d.Pfam") ; # add matches from the PFAM class
@lines = anne_files::unique_array(@lines) ; # remove replicates
print "\tTotal locus tags with COG functional category: ".(scalar @lines)."\n" ;
anne_files::write_lines("$genome.g2d.COG", sort @lines) ;
# -------------------------------------------- functions -----------------------------------------------------------------------------------------------
sub screen_class_4_matches {
my $classfile = shift ;
if (!-e $classfile) { print "\tFile not found $classfile\n"; exit(); }
my %class = get_interpro($classfile) ;
my @results ;
foreach my $key (sort keys %class) {
my $cogKey = find_match($class{$key}{description}) ;
if ($cogKey ne '' and defined($cogfun{$cognames{$cogKey}{func_cat}})) {
push @results, "$class{$key}{locus}\t$cognames{$cogKey}{func_cat}\t$cogfun{$cognames{$cogKey}{func_cat}}" ; }
}
print "\tCOGs from $classfile: ".(scalar @results)."\n" ;
return @results ;
}
sub find_match {
# does the description match the cognames description
my $result = '';
my $description = lc(shift) ;
$description =~ s/\+|\s+|\-|\)|\(|\\|\///g ;
foreach my $key (keys %cognames) {
if ($cognames{$key}{description} =~ m/$description/) {
$result = $key ;
last();
}
}
return $result ;
}
sub get_cognames {
my $filename = shift ;
my @lines = anne_files::read_lines($filename) ;
my %results ;
foreach my $line (@lines) {
if ($line !~ m/^#/) { # doen not start with remark char #
my @items = split "\t", $line ;
if (defined($items[2])) {
my $key = $items[0] ;
$results{$key}{func_cat} = $items[1] ;
$results{$key}{description} = lc($items[2]) ;
$results{$key}{description} =~ s/\s+|\-|\)|\(|\\|\///g ;
}
}
}
return %results ;
}
sub get_cogfun {
my $filename = shift ;
my @lines = anne_files::read_lines($filename) ;
my %results ;
foreach my $line (@lines) {
if ($line !~ m/^#/) { # doen not start with remark char #
my @items = split "\t", $line ;
if (defined($items[1])) {
$results{$items[0]} = $items[1] ;
}
}
}
return %results ;
}
sub get_interpro {
my $filename = shift ;
my @lines = anne_files::read_lines($filename) ;
my %results ;
my $count = 0 ;
foreach my $line (@lines) {
my @items = split "\t", $line ;
if (defined($items[2])) {
$count++;
$results{$count}{locus} = $items[0] ;
$results{$count}{IPR} = $items[1] ;
$results{$count}{description} = $items[2] ;
}
}
return %results ;
}
sub parseparam {
my $var ;
my @arg = @ARGV ;
while(@arg) {
$var = shift(@arg) ;
$sessiondir = shift(@arg) if($var eq '-s') ;
$genome = shift(@arg) if($var eq '-i') ;
}
die $usage if (!$genome) ;
}