line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Basic.pm,v 1.4 2005/03/30 21:15:48 cmungall Exp $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# see also - http://www.geneontology.org |
5
|
|
|
|
|
|
|
# - http://www.godatabase.org/dev |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# You may distribute this module under the same terms as perl itself |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
GO::Basic - basic procedural interface to go-perl |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use GO::Basic; |
16
|
|
|
|
|
|
|
parse_obo(shift @ARGV); |
17
|
|
|
|
|
|
|
find_term(name=>"cytosol"); |
18
|
|
|
|
|
|
|
print $term->acc(); # OO usage |
19
|
|
|
|
|
|
|
print acc(); # procedural usage |
20
|
|
|
|
|
|
|
get_parent; |
21
|
|
|
|
|
|
|
print name(); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
package GO::Basic; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
11206
|
use Exporter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
33
|
1
|
|
|
1
|
|
754
|
use GO::Model::Graph; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
72
|
|
34
|
1
|
|
|
1
|
|
612
|
use GO::Parser; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
35
|
1
|
|
|
1
|
|
6
|
use FileHandle; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
36
|
1
|
|
|
1
|
|
264
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
37
|
1
|
|
|
1
|
|
5
|
use base qw(GO::Model::Root Exporter); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
82
|
|
38
|
1
|
|
|
1
|
|
6
|
use vars qw(@EXPORT); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1138
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our $graph; |
41
|
|
|
|
|
|
|
our $terms; |
42
|
|
|
|
|
|
|
our $term; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
@EXPORT = |
45
|
|
|
|
|
|
|
qw( |
46
|
|
|
|
|
|
|
parse |
47
|
|
|
|
|
|
|
parse_obo |
48
|
|
|
|
|
|
|
parse_goflat |
49
|
|
|
|
|
|
|
parse_def |
50
|
|
|
|
|
|
|
parse_assoc |
51
|
|
|
|
|
|
|
term |
52
|
|
|
|
|
|
|
terms |
53
|
|
|
|
|
|
|
acc |
54
|
|
|
|
|
|
|
accs |
55
|
|
|
|
|
|
|
name |
56
|
|
|
|
|
|
|
names |
57
|
|
|
|
|
|
|
graph |
58
|
|
|
|
|
|
|
find_term |
59
|
|
|
|
|
|
|
find_terms |
60
|
|
|
|
|
|
|
get_parents |
61
|
|
|
|
|
|
|
get_rparents |
62
|
|
|
|
|
|
|
get_children |
63
|
|
|
|
|
|
|
get_rchildren |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
1
|
0
|
11
|
sub parse_obo { parse(@_, {fmt=>'obo'}) } |
67
|
0
|
|
|
0
|
0
|
0
|
sub parse_goflat { parse(@_, {fmt=>'go_ont'}) } |
68
|
0
|
|
|
0
|
0
|
0
|
sub parse_def { parse(@_, {fmt=>'go_def'}) } |
69
|
0
|
|
|
0
|
0
|
0
|
sub parse_assoc { parse(@_, {fmt=>'go_assoc'}) } |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub parse { |
72
|
1
|
|
|
1
|
0
|
4
|
my $opt = {format=>'obo'}; |
73
|
|
|
|
|
|
|
my @files = |
74
|
|
|
|
|
|
|
map { |
75
|
1
|
100
|
|
|
|
3
|
if (ref($_)) { |
|
2
|
|
|
|
|
5
|
|
76
|
1
|
50
|
|
|
|
3
|
if (ref($_) eq 'HASH') { |
77
|
1
|
|
|
|
|
3
|
my %h = %$_; |
78
|
1
|
|
|
|
|
6
|
$opt->{$_} = $h{$_} foreach keys %h; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
0
|
|
|
|
|
0
|
throw("bad argument: $_"); |
82
|
|
|
|
|
|
|
} |
83
|
1
|
|
|
|
|
4
|
(); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
1
|
|
|
|
|
3
|
$_; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} @_; |
89
|
1
|
|
|
|
|
12
|
my $parser = GO::Parser->new({format=>$opt->{fmt}, |
90
|
|
|
|
|
|
|
use_cache=>$opt->{use_cache}, |
91
|
|
|
|
|
|
|
handler=>'obj'}); |
92
|
1
|
|
|
|
|
14
|
$parser->parse($_) foreach @files; |
93
|
1
|
|
|
|
|
64
|
$graph = $parser->handler->graph; |
94
|
1
|
|
|
|
|
64
|
$graph; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub find_terms { |
98
|
3
|
50
|
|
3
|
0
|
13
|
@_ < 1 && throw("must pass an argument!"); |
99
|
3
|
100
|
|
|
|
16
|
my %constr = @_==1 ? (name=>shift) : @_; |
100
|
3
|
|
|
|
|
8
|
check_for_graph(); |
101
|
3
|
|
|
|
|
18
|
$terms = $graph->term_query(\%constr); |
102
|
3
|
|
|
|
|
94
|
return $terms; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub find_term { |
106
|
3
|
|
|
3
|
0
|
461
|
find_terms(@_); |
107
|
3
|
100
|
|
|
|
16
|
if (@$terms) { |
108
|
2
|
50
|
|
|
|
9
|
if (@$terms > 1) { |
109
|
0
|
|
|
|
|
0
|
message(">1 terms returned!"); |
110
|
|
|
|
|
|
|
} |
111
|
2
|
|
|
|
|
7
|
$term = $terms->[0]; |
112
|
2
|
|
|
|
|
7
|
return $term; |
113
|
|
|
|
|
|
|
} |
114
|
1
|
|
|
|
|
6
|
return; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub term { |
118
|
2
|
|
|
2
|
0
|
15
|
check_for_term(); |
119
|
2
|
|
|
|
|
11
|
return $term; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub terms { |
123
|
0
|
|
|
0
|
0
|
0
|
check_for_terms(); |
124
|
0
|
|
|
|
|
0
|
return @$terms; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub next_term { |
128
|
0
|
|
|
0
|
0
|
0
|
$term = shift @$terms; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub graph { |
132
|
0
|
|
|
0
|
0
|
0
|
check_for_graph(); |
133
|
0
|
|
|
|
|
0
|
return $graph; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub acc { |
137
|
3
|
|
|
3
|
0
|
18
|
check_for_term(); |
138
|
3
|
|
|
|
|
9
|
return $term->acc; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub accs { |
142
|
0
|
|
|
0
|
0
|
0
|
check_for_terms(); |
143
|
0
|
|
|
|
|
0
|
return map {$_->acc} @$terms; |
|
0
|
|
|
|
|
0
|
|
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub name { |
147
|
0
|
|
|
0
|
0
|
0
|
check_for_term(); |
148
|
0
|
|
|
|
|
0
|
return $term->name; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub names { |
152
|
4
|
|
|
4
|
0
|
14
|
check_for_terms(); |
153
|
4
|
|
|
|
|
6
|
return map {$_->name} @$terms; |
|
13
|
|
|
|
|
30
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub definition { |
158
|
0
|
|
|
0
|
0
|
0
|
check_for_term(); |
159
|
0
|
|
|
|
|
0
|
return $term->definition; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub check_for_term { |
163
|
8
|
50
|
|
8
|
0
|
22
|
$term || throw("no term selected!"); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
sub check_for_terms { |
166
|
4
|
50
|
|
4
|
0
|
13
|
$terms || throw("no term set selected!"); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
sub check_for_graph { |
169
|
6
|
50
|
|
6
|
0
|
21
|
$graph || throw("no graph selected!"); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub get_parents { |
173
|
1
|
|
|
1
|
0
|
4
|
check_for_graph(); |
174
|
1
|
|
|
|
|
3
|
check_for_term(); |
175
|
1
|
|
|
|
|
6
|
$terms = $graph->get_parent_terms($term->acc); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub get_rparents { |
179
|
1
|
|
|
1
|
0
|
3
|
check_for_graph(); |
180
|
1
|
|
|
|
|
3
|
check_for_term(); |
181
|
1
|
|
|
|
|
3
|
$terms = $graph->get_recursive_parent_terms($term->acc); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub get_children { |
185
|
0
|
|
|
0
|
0
|
0
|
check_for_graph(); |
186
|
0
|
|
|
|
|
0
|
check_for_term(); |
187
|
0
|
|
|
|
|
0
|
$terms = $graph->get_child_terms($term->acc); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub get_rchildren { |
191
|
1
|
|
|
1
|
0
|
8
|
check_for_graph(); |
192
|
1
|
|
|
|
|
4
|
check_for_term(); |
193
|
1
|
|
|
|
|
4
|
$terms = $graph->get_recursive_child_terms($term->acc); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub throw { |
197
|
0
|
|
|
0
|
0
|
|
confess "@_"; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub message { |
201
|
0
|
|
|
0
|
0
|
|
print STDERR "@_\n"; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1; |