line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: go_xref_parser.pm,v 1.9 2010/02/15 17:34:57 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
|
|
|
|
|
|
|
package GO::Parsers::go_xref_parser; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
GO::Parsers::go_xref_parser - syntax parsing of GO xref flat files (eg eg2go, metacyc2go) |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
do not use this class directly; use GO::Parser |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This generates Stag event streams from one of the various GO flat file |
24
|
|
|
|
|
|
|
formats (ontology, defs, xref, associations). See GO::Parser for details |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Examples of these files can be found at http://www.geneontology.org |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
A description of the event streams generated follows; Stag or an XML |
29
|
|
|
|
|
|
|
handler can be used to catch these events |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 GO XREF FILES |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
These files have a filename *2go; eg metacyc2go |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
(dbxrefs |
36
|
|
|
|
|
|
|
(termdbxref+ |
37
|
|
|
|
|
|
|
(termacc "s") |
38
|
|
|
|
|
|
|
(dbxref |
39
|
|
|
|
|
|
|
(xref_dbname "s") |
40
|
|
|
|
|
|
|
(xref_key "s")))) |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 AUTHOR |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
81
|
|
49
|
1
|
|
|
1
|
|
7
|
use FileHandle; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
50
|
1
|
|
|
1
|
|
547
|
use strict qw(vars refs); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
51
|
1
|
|
|
1
|
|
5
|
use base qw(GO::Parsers::base_parser); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
474
|
|
52
|
1
|
|
|
1
|
|
690
|
use GO::Parsers::ParserEventNames; # XML constants |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2096
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub dtd { |
55
|
0
|
|
|
0
|
0
|
0
|
'go_xref-parser-events.dtd'; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub parse_fh { |
59
|
1
|
|
|
1
|
0
|
167
|
my ($self, $fh) = @_; |
60
|
1
|
|
|
|
|
4
|
my $file = $self->file; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
7
|
my $lnum = 0; |
63
|
1
|
|
|
|
|
11
|
$self->start_event(OBO); |
64
|
1
|
|
|
|
|
798
|
while (<$fh>) { |
65
|
720
|
|
|
|
|
24087
|
chomp; |
66
|
|
|
|
|
|
|
|
67
|
720
|
|
|
|
|
1135
|
tr [\200-\377] |
68
|
|
|
|
|
|
|
[\000-\177]; # see 'man perlop', section on tr/ |
69
|
|
|
|
|
|
|
# weird ascii characters should be excluded |
70
|
720
|
|
|
|
|
1091
|
tr/\0-\10//d; # remove weird characters; ascii 0-8 |
71
|
|
|
|
|
|
|
# preserve \11 (9 - tab) and \12 (10-linefeed) |
72
|
720
|
|
|
|
|
940
|
tr/\13\14//d; # remove weird characters; 11,12 |
73
|
|
|
|
|
|
|
# preserve \15 (13 - carriage return) |
74
|
720
|
|
|
|
|
938
|
tr/\16-\37//d; # remove 14-31 (all rest before space) |
75
|
720
|
|
|
|
|
955
|
tr/\177//d; # remove DEL character |
76
|
|
|
|
|
|
|
|
77
|
720
|
|
|
|
|
757
|
$lnum++; |
78
|
720
|
100
|
|
|
|
1645
|
next if /^\!/; |
79
|
716
|
50
|
|
|
|
2535
|
next if /^$/; |
80
|
716
|
|
|
|
|
2329
|
$self->line($_); |
81
|
716
|
|
|
|
|
4744
|
$self->line_no($lnum); |
82
|
716
|
|
|
|
|
5674
|
my ($ext, @goids) = split(' > ',$_); |
83
|
716
|
50
|
|
|
|
3825
|
if ($ext =~ /^([\w\-]+):?(\S+)(.*)/) { |
84
|
716
|
|
|
|
|
2492
|
my ($db,$dbacc,$name) = ($1,$2,$3); |
85
|
716
|
100
|
|
|
|
2295
|
$name =~ s/^\s+// if $name; |
86
|
716
|
|
|
|
|
1347
|
$dbacc =~ s/\s/\%20/g; |
87
|
716
|
|
|
|
|
1296
|
foreach my $goid (@goids) { |
88
|
716
|
50
|
|
|
|
4090
|
if ($goid =~ /(.*)\s+\;\s+(.*)/) { |
89
|
716
|
|
|
|
|
1299
|
my $goacc = $2; |
90
|
716
|
50
|
|
|
|
2287
|
if ($self->acc_not_found($goacc)) { |
91
|
0
|
|
|
|
|
0
|
$self->parse_err("No such ID: $goacc"); |
92
|
0
|
|
|
|
|
0
|
next; |
93
|
|
|
|
|
|
|
} |
94
|
716
|
|
|
|
|
2018
|
$self->start_event(TERM); |
95
|
716
|
|
|
|
|
20322
|
$self->event(ID, $goacc); |
96
|
716
|
|
|
|
|
64042
|
$self->start_event(XREF_ANALOG); |
97
|
716
|
|
|
|
|
18605
|
$self->event(ACC, $dbacc); |
98
|
716
|
|
|
|
|
74095
|
$self->event(DBNAME, $db); |
99
|
716
|
100
|
|
|
|
55717
|
if ($name) { |
100
|
467
|
|
|
|
|
1193
|
$self->event(NAME, $name) |
101
|
|
|
|
|
|
|
} |
102
|
716
|
|
|
|
|
36281
|
$self->end_event(XREF_ANALOG); |
103
|
716
|
|
|
|
|
36759
|
$self->end_event(TERM); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { |
106
|
0
|
|
|
|
|
0
|
$self->parse_err("would not extract GO ID from: $goid"); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
0
|
|
|
|
|
0
|
$self->parse_err("bad external ID: $ext in line: $_"); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
1
|
|
|
|
|
51
|
$self->end_event(OBO); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |