line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GOBO::Parsers::GAFParser; |
2
|
1
|
|
|
1
|
|
63413
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use strict; |
4
|
|
|
|
|
|
|
extends 'GOBO::Parsers::Parser'; |
5
|
|
|
|
|
|
|
with 'GOBO::Parsers::GraphParser'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use GOBO::Node; |
8
|
|
|
|
|
|
|
use GOBO::Gene; |
9
|
|
|
|
|
|
|
use GOBO::Evidence; |
10
|
|
|
|
|
|
|
use GOBO::Annotation; |
11
|
|
|
|
|
|
|
use GOBO::ClassExpression; |
12
|
|
|
|
|
|
|
use Carp; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub parse_header { |
15
|
|
|
|
|
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
my $g = $self->graph; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
while($_ = $self->next_line) { |
19
|
|
|
|
|
|
|
if (/^\!.*/) { |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
|
|
|
|
|
|
$self->unshift_line($_); |
23
|
|
|
|
|
|
|
# set the parse_header to 1 |
24
|
|
|
|
|
|
|
$self->parsed_header(1); |
25
|
|
|
|
|
|
|
return; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
# we are still in the header and have reached the end of the file |
29
|
|
|
|
|
|
|
$self->parsed_header(1); |
30
|
|
|
|
|
|
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub parse_body { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
my $g = $self->graph; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
while($_ = $self->next_line) { |
38
|
|
|
|
|
|
|
if (/^\!/) { |
39
|
|
|
|
|
|
|
print STDERR "Warning! header in unexpected location: $_\n"; |
40
|
|
|
|
|
|
|
next; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
chomp; |
43
|
|
|
|
|
|
|
my @vals = split(/\t/); |
44
|
|
|
|
|
|
|
my ($genedb, |
45
|
|
|
|
|
|
|
$geneacc, |
46
|
|
|
|
|
|
|
$genesymbol, |
47
|
|
|
|
|
|
|
$qualifier, |
48
|
|
|
|
|
|
|
$termacc, |
49
|
|
|
|
|
|
|
$ref, |
50
|
|
|
|
|
|
|
$evcode, |
51
|
|
|
|
|
|
|
$with, |
52
|
|
|
|
|
|
|
$aspect, |
53
|
|
|
|
|
|
|
$genename, |
54
|
|
|
|
|
|
|
$genesyn, |
55
|
|
|
|
|
|
|
$genetype, |
56
|
|
|
|
|
|
|
$genetaxa, |
57
|
|
|
|
|
|
|
$assocdate, |
58
|
|
|
|
|
|
|
$source_db, |
59
|
|
|
|
|
|
|
$annotxp, # experimental! |
60
|
|
|
|
|
|
|
$geneproduct |
61
|
|
|
|
|
|
|
) = @vals; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
if (!$genesymbol) { |
64
|
|
|
|
|
|
|
confess("No symbol in line: $_"); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $geneid = "$genedb:$geneacc"; |
68
|
|
|
|
|
|
|
my $gene = $g->noderef($geneid); |
69
|
|
|
|
|
|
|
my @taxa = split(/[\|\;]/,$genetaxa); |
70
|
|
|
|
|
|
|
@taxa = map {s/^taxon:/NCBITaxon:/;$_} @taxa; |
71
|
|
|
|
|
|
|
my $taxon = shift @taxa; |
72
|
|
|
|
|
|
|
if (!$gene->label) { |
73
|
|
|
|
|
|
|
bless $gene, 'GOBO::Gene'; |
74
|
|
|
|
|
|
|
$gene->label($genesymbol); |
75
|
|
|
|
|
|
|
$gene->add_synonyms(split(/\|/,$genesyn)); |
76
|
|
|
|
|
|
|
# TODO; split |
77
|
|
|
|
|
|
|
$gene->taxon($g->noderef($taxon)); |
78
|
|
|
|
|
|
|
$gene->type($g->noderef($genetype)); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
my $cnode = $g->term_noderef($termacc); |
81
|
|
|
|
|
|
|
if (!$cnode->namespace) { |
82
|
|
|
|
|
|
|
$cnode->namespace(_aspect2ns($aspect)); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my %qualh = map {lc($_)=>1} (split(/[\|]\s*/,$qualifier || '')); |
86
|
|
|
|
|
|
|
my $ev = new GOBO::Evidence(type=>$g->term_noderef($evcode)); |
87
|
|
|
|
|
|
|
# TODO: discriminate between pipes and commas |
88
|
|
|
|
|
|
|
# (semicolon is there for legacy reasons - check if this can be removed) |
89
|
|
|
|
|
|
|
my @with_objs = map {$g->noderef($_)} split(/\s*[\|\;\,]\s*/, $with); |
90
|
|
|
|
|
|
|
$ev->supporting_entities(\@with_objs); |
91
|
|
|
|
|
|
|
my @refs = split(/\|/,$ref); |
92
|
|
|
|
|
|
|
my $provenance = $g->noderef(pop @refs); # last is usually PMID |
93
|
|
|
|
|
|
|
$provenance->add_xrefs([@refs]); |
94
|
|
|
|
|
|
|
my $annot = |
95
|
|
|
|
|
|
|
new GOBO::Annotation(node=>$gene, |
96
|
|
|
|
|
|
|
target=>$cnode, |
97
|
|
|
|
|
|
|
provenance=>$provenance, |
98
|
|
|
|
|
|
|
source=>$g->noderef($source_db), |
99
|
|
|
|
|
|
|
date=>$assocdate, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
if ($geneproduct) { |
102
|
|
|
|
|
|
|
$geneproduct =~ s/\s+//g; |
103
|
|
|
|
|
|
|
if ($geneproduct) { |
104
|
|
|
|
|
|
|
$annot->specific_node($g->noderef($geneproduct)); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
# if >1 taxon supplied, additional taxon specifies target species |
108
|
|
|
|
|
|
|
if (@taxa) { |
109
|
|
|
|
|
|
|
my $xp = |
110
|
|
|
|
|
|
|
GOBO::ClassExpression::RelationalExpression->new(relation=>'target_taxon', |
111
|
|
|
|
|
|
|
target=>$g->noderef($taxon)); |
112
|
|
|
|
|
|
|
$annot->add_target_differentia($xp); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
$annot->evidence($ev); |
116
|
|
|
|
|
|
|
foreach my $qk (keys %qualh) { |
117
|
|
|
|
|
|
|
$annot->add_qualifier($g->noderef($qk)); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
if ($qualh{not}) { |
120
|
|
|
|
|
|
|
$annot->negated(1); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
if ($annotxp) { |
123
|
|
|
|
|
|
|
$annotxp =~ s/\s+//g; |
124
|
|
|
|
|
|
|
if ($annotxp) { |
125
|
|
|
|
|
|
|
my $xp = GOBO::ClassExpression->parse_idexpr($g,$annotxp); |
126
|
|
|
|
|
|
|
$annot->add_target_differentia($xp); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
$g->add_annotation($annot); |
130
|
|
|
|
|
|
|
#push(@{$g->annotations},$annot); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
return; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# the following is specific to GO |
136
|
|
|
|
|
|
|
sub _aspect2ns { |
137
|
|
|
|
|
|
|
my $aspect = shift; |
138
|
|
|
|
|
|
|
return 'molecular_function' if $aspect eq 'F'; |
139
|
|
|
|
|
|
|
return 'biological_process' if $aspect eq 'P'; |
140
|
|
|
|
|
|
|
return 'cellular_component' if $aspect eq 'C'; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |