| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: unknown_format_parser.pm,v 1.9 2005/08/18 21:23:11 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::unknown_format_parser; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
GO::Parsers::unknown_format_parser - base class for parsers |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
do not use this class directly; use GO::Parser |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 AUTHOR |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
|
26
|
|
|
|
|
|
|
|
|
27
|
6
|
|
|
6
|
|
40
|
use Carp; |
|
|
6
|
|
|
|
|
13
|
|
|
|
6
|
|
|
|
|
507
|
|
|
28
|
6
|
|
|
6
|
|
34
|
use FileHandle; |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
51
|
|
|
29
|
6
|
|
|
6
|
|
3171
|
use GO::Parser; |
|
|
6
|
|
|
|
|
14
|
|
|
|
6
|
|
|
|
|
198
|
|
|
30
|
6
|
|
|
6
|
|
33
|
use base qw(GO::Parsers::base_parser Exporter); |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
2415
|
|
|
31
|
6
|
|
|
6
|
|
48
|
use strict qw(subs vars refs); |
|
|
6
|
|
|
|
|
13
|
|
|
|
6
|
|
|
|
|
5119
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub parse_file_by_type { |
|
34
|
0
|
|
|
0
|
0
|
0
|
shift->parse_file(@_); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
sub parse_file { |
|
37
|
6
|
|
|
6
|
0
|
18
|
my ($self, $file, $dtype) = @_; |
|
38
|
6
|
|
|
|
|
73
|
$self->file($file); |
|
39
|
6
|
|
|
|
|
40
|
my $fmt; # input file format |
|
40
|
|
|
|
|
|
|
my $p; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# determine format based on dtype |
|
43
|
|
|
|
|
|
|
# (legacy code - dtypes should switch to standard formars) |
|
44
|
6
|
50
|
|
|
|
24
|
if ($dtype) { |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# convert legacy types |
|
47
|
0
|
0
|
|
|
|
0
|
if ($dtype =~ /ontology$/) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$fmt = "go_ont"; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
elsif ($dtype =~ /defs$/) { |
|
51
|
0
|
|
|
|
|
0
|
$fmt = "go_def"; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
elsif ($dtype =~ /xrefs$/) { |
|
54
|
0
|
|
|
|
|
0
|
$fmt = "go_xref"; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
elsif ($dtype =~ /assocs$/) { |
|
57
|
0
|
|
|
|
|
0
|
$fmt = "go_assoc"; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
else { |
|
60
|
0
|
|
|
|
|
0
|
$fmt = $dtype; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
6
|
50
|
|
|
|
32
|
if (!$p) { |
|
64
|
|
|
|
|
|
|
# no default parser, or it has been overwritten |
|
65
|
6
|
50
|
|
|
|
18
|
if (!$fmt) { |
|
66
|
|
|
|
|
|
|
# messy guessing of format from file extension |
|
67
|
6
|
50
|
|
|
|
32
|
if ($file =~ /\.go$/) { |
|
68
|
0
|
|
|
|
|
0
|
$fmt = "go_ont"; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
6
|
100
|
|
|
|
41
|
if ($file =~ /\.ontology$/) { |
|
71
|
1
|
|
|
|
|
2
|
$fmt = "go_ont"; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
6
|
50
|
|
|
|
22
|
if ($file =~ /defs$/) { |
|
74
|
0
|
|
|
|
|
0
|
$fmt = "go_def"; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
6
|
50
|
|
|
|
25
|
if ($file =~ /2go$/) { |
|
77
|
0
|
|
|
|
|
0
|
$fmt = "go_xref"; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
6
|
50
|
|
|
|
23
|
if ($file =~ /gene_association/) { |
|
80
|
0
|
|
|
|
|
0
|
$fmt = "go_assoc"; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
6
|
100
|
66
|
|
|
52
|
if ($file =~ /\.obo$/ || $file =~ /\.obo[\.\-_]text$/) { |
|
83
|
5
|
|
|
|
|
15
|
$fmt = "obo_text"; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
6
|
50
|
|
|
|
21
|
if ($file =~ /\.obo\W*xml$/) { |
|
86
|
0
|
|
|
|
|
0
|
$fmt = "obo_xml"; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
6
|
50
|
|
|
|
37
|
if (!$fmt) { |
|
89
|
|
|
|
|
|
|
# if suffix is a known parser module, use it |
|
90
|
0
|
0
|
|
|
|
0
|
if ($file =~ /\.(\w+)$/) { |
|
91
|
0
|
|
|
|
|
0
|
my $suffix = $1; |
|
92
|
0
|
|
|
|
|
0
|
my $mod = "GO/Parsers/$suffix"."_parser.pm"; |
|
93
|
0
|
|
|
|
|
0
|
eval { |
|
94
|
0
|
|
|
|
|
0
|
require "$mod"; |
|
95
|
|
|
|
|
|
|
}; |
|
96
|
0
|
0
|
|
|
|
0
|
if ($@) { |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
else { |
|
99
|
0
|
|
|
|
|
0
|
$fmt = $suffix; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
6
|
50
|
|
|
|
18
|
if (!$fmt) { |
|
104
|
|
|
|
|
|
|
#$self->throw("I have no idea how to parse: $file\n"); |
|
105
|
0
|
0
|
|
|
|
0
|
open(F,$file) || $self->throw("Cannot open $file"); |
|
106
|
0
|
|
|
|
|
0
|
my $first_line = ; |
|
107
|
0
|
0
|
|
|
|
0
|
if ($first_line =~ /^format/) { |
|
108
|
0
|
|
|
|
|
0
|
$fmt = 'obo_text'; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
else { |
|
111
|
0
|
|
|
|
|
0
|
$fmt = 'go_ont'; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
|
|
|
|
0
|
close(F); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
6
|
|
|
|
|
44
|
$p = GO::Parser->get_parser_impl($fmt); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
6
|
|
|
|
|
88
|
%$p = %$self; |
|
119
|
6
|
|
|
|
|
66
|
$p->parse($file); |
|
120
|
6
|
|
|
|
|
461
|
%$self = %$p; |
|
121
|
6
|
|
|
|
|
44
|
$self->parser($p); |
|
122
|
6
|
|
|
|
|
26
|
$self; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub parser { |
|
126
|
6
|
|
|
6
|
0
|
18
|
my $self = shift; |
|
127
|
6
|
50
|
|
|
|
32
|
$self->{_parser} = shift if @_; |
|
128
|
6
|
|
|
|
|
17
|
return $self->{_parser}; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub parse { |
|
133
|
6
|
|
|
6
|
1
|
768
|
my $self = shift; |
|
134
|
6
|
|
|
|
|
11
|
my $filename; |
|
135
|
6
|
|
|
|
|
19
|
foreach $filename (@_) { |
|
136
|
6
|
|
|
|
|
22
|
$self->parse_file($filename); |
|
137
|
|
|
|
|
|
|
} |
|
138
|
6
|
|
|
|
|
28
|
return; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# deprecated! |
|
143
|
|
|
|
|
|
|
sub parse_ontology { |
|
144
|
0
|
|
|
0
|
0
|
|
my ($self, $file) = @_; |
|
145
|
0
|
|
|
|
|
|
$self->parse_file($file, 'go_ont'); |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |