This file is indexed.

/usr/share/perl5/GO/Parsers/go_ont_parser.pm is in libgo-perl 0.15-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# $Id: go_ont_parser.pm,v 1.17 2005/08/19 01:48:09 cmungall Exp $
#
#
# see also - http://www.geneontology.org
#          - http://www.godatabase.org/dev
#
# You may distribute this module under the same terms as perl itself

package GO::Parsers::go_ont_parser;

=head1 NAME

  GO::Parsers::go_ont_parser     - syntax parsing of GO .ontology flat files

=head1 SYNOPSIS

  do not use this class directly; use GO::Parser

=cut

=head1 DESCRIPTION

This generates Stag event streams from one of the various GO flat file
formats (ontology, defs, xref, associations). See GO::Parser for details

Examples of these files can be found at http://www.geneontology.org

A description of the event streams generated follows; Stag or an XML
handler can be used to catch these events

=head1 GO ONTOLOGY FILES

These files have the .ontology suffix. The stag-schema for the event
streams generated look like this:
 
  (ontology
   (source
     (source_type "s")
     (source_path "s")
     (source_mtime "i"))
   (term+
     (id "s")
     (name "s")
     (is_root? "i")
     (relationship+
       (type "s")
       (to "s"))
     (dbxref*
       (dbname "s")
       (acc "s"))
     (synonym* "s")
     (secondaryid* "s")
     (is_obsolete? "i"))) 


=head1 AUTHOR

=cut

use Exporter;
use base qw(GO::Parsers::base_parser);
use GO::Parsers::ParserEventNames;

use Carp;
use FileHandle;
use strict qw(vars refs);

sub dtd {
    'go_ont-parser-events.dtd';
}

sub regesc {
    my $code = shift;
    if ($code eq '|') {
        $code = '\|';
    }
    if ($code eq '*') {
        $code = '\*';
    }
    if ($code eq '?') {
        $code = '\?';
    }
    $code;
}

sub reln_regexp {
    join("|", map {" ".regesc($_)." "} keys %{shift || {}});
}

sub parse_fh {
    my ($self, $fh) = @_;

    my $file = $self->file;

    my $is_go;
    my %typemap =
      ('$'=>'is_a',
       '%'=>'is_a',
       '<'=>'part_of',
       '~'=>'derives_from',
       );
    my $reln_regexp = reln_regexp(\%typemap);
    my $lnum = 0;
    my @stack = ();
    my $obs_depth;

    my $usc = $self->replace_underscore;
    $self->start_event(OBO);
    my %rtypenameh = ();
    $self->fire_source_event($file);
    $self->handler->{ontology_type} = 
      $self->force_namespace;
    my $root_id;

  PARSELINE:
    while (<$fh>) {
        # UNICODE causes problems for XML and DB
        # delete 8th bit
        tr [\200-\377]
          [\000-\177];   # see 'man perlop', section on tr/
        # weird ascii characters should be excluded
        tr/\0-\10//d;   # remove weird characters; ascii 0-8
                        # preserve \11 (9 - tab) and \12 (10-linefeed)
        tr/\13\14//d;   # remove weird characters; 11,12
                        # preserve \15 (13 - carriage return)
        tr/\16-\37//d;  # remove 14-31 (all rest before space)
        tr/\177//d;     # remove DEL character
        my $line = $_;
	$line =~ s/\r//g;
	chomp $line;
	$line =~ s/\s+$//;
	++$lnum;
        $self->line($line);
        $self->line_no($lnum);
        if ($line =~ /^\!type:\s*(\S+)\s+(\S+)/) {
            my ($code, $name) = ($1, $2);
            $name =~ s/\s+/_/g;
            $name = lc($name);
            if ($name eq 'isa') {
                $name = 'is_a';
            }
            if ($name eq 'partof') {
                $name = 'part_of';
            }
            $typemap{$code} = $name
              unless $code eq '%';
            #$code = '\\'.$code;
            $reln_regexp = reln_regexp(\%typemap);
            next;
        }
	next if $line =~ /^\s*\!/;   # comment
	next if $line eq '\$';        # 
	next if $line eq '';        # 
	last if $line =~ /^\s*\$\s*$/;  # end of file

	# get rid of SGML directives, e.g. FADH<down>2</down>, as these confuse the relationship syntax
	$line =~ s/<\/?[A-Za-z]+>//g;
#	$line = &spellGreek ($line);
	$line =~ s/&([a-z]+);/$1/g;

        $line =~ /( *)(.*)/;
        my $body = $2;
        my $indent = length($1);

        my $is_obs = 0;
        while ((scalar @stack) &&
               $stack[$#stack]->[0] >= $indent) {
            pop @stack;
            if (defined($obs_depth) &&
                $obs_depth >= $indent) {
                # no longer under obsolete node
                $obs_depth = undef;
            }
        }

        my $rchar;
        if ($body =~ /^(\@\w+\@)(.*)/) {
            $rchar = $self->typemap($1,\%typemap);
            $body = $2;
	    $reln_regexp = ' \@\w+\@ ';
        }
	else {
            $rchar = $self->typemap(substr($body, 0, 1),\%typemap);
            $body = substr($body, 1);
        }
        # +++++++++++++++++++++++++++++++++
        # parse body / main content of line
        # +++++++++++++++++++++++++++++++++
        my $currxref;
        my @parts = split(/($reln_regexp)/, $body);
	for (my $i=0; $i < @parts; $i+=2) {
            my $part = $parts[$i];
            my ($name, @xrefs) =
              split(/\s*;\s+/, $part);
            $name = $self->unescapego($name);
            if ($usc) {
                $name =~ s/_/$usc/g;
            }
            if ($name =~ /^obsolete/i && $i==0) {
                $obs_depth = $indent;
            }
            if ($name eq "Gene_Ontology") {
                $is_go =1;
            }
            if (defined($obs_depth)) {
                # set obsolete flag if we
                # are anywhere under the obsolete node
                $is_obs = 1;
            }
            if ($indent < 2 && $is_go) {
                $self->handler->{ontology_type} = $name
                  unless $self->force_namespace;
            }
            elsif ($indent < 1) {
                $self->handler->{ontology_type} = $name
                  unless $self->force_namespace;
            }
            elsif (!$self->handler->{ontology_type}) {
                $self->handler->{ontology_type} = $name;
            }
	    else {
	    }

            my $pxrefstr = shift @xrefs;
            if (!$pxrefstr) {
		$pxrefstr = '';
                $self->parse_err("no ID");
                next PARSELINE;
            }
            # get the GO id for this line
            my ($pxref, @secondaryids) =
              split(/,\s+/, $pxrefstr);
            if ($i==0) {
                $currxref = $pxref;
                if ($currxref =~ /\s/) {
                    my $msg = "\"$pxref\" doesn't look valid";
                    $self->parse_err($msg);
                }
                my $a2t = $self->acc2name_h;
                my $prevname = $a2t->{$currxref};
                if ($prevname &&
                    $prevname ne $name) {
                    my $msg = "clash on $pxref; was '$prevname' now '$name'";
                    $self->parse_err($msg);
		    next PARSELINE;
                }
		if ($prevname && $indent) {
		    # seen before - no new data, skip to avoid repeats
		    next PARSELINE;
		}
                $a2t->{$currxref} = $name;
		$root_id = $currxref if !$indent;
                $a2t->{$currxref} = $name;
		$self->start_event(TERM);
                $self->event(ID, $currxref);
                $self->event(NAME, $name);
                $self->event(IS_OBSOLETE, $is_obs) if $is_obs;
                $self->event(IS_ROOT, 1) if !$indent;
                $self->event(NAMESPACE, $self->handler->{ontology_type}) 
		  if $self->handler->{ontology_type};
                map {
                    $self->event(ALT_ID, $_);
                } @secondaryids;
            }
	    #            map {
	    #                $self->start_event("secondaryid");
	    #                $self->event("id", $_);
	    #                $self->end_event("secondaryid");
	    #            } @secondaryids;
            if ($i == 0) {
                # first part on line has main
                # info for this term
                foreach my $xref (@xrefs) {
                    my ($db,@rest) =
                      split(/:/,$xref);
		    my $dbacc = $self->unescapego(join(":", @rest));
		    if ($db eq "synonym") {
                        $self->event(SYNONYM, [[synonym_text=>$dbacc],
                                               [type=>'related']]);
                    }
                    
		    #                    elsif ($dbacc =~ /\s/) {
		    #                        # db accessions should not have
		    #                        # spaces in them - this
		    #                        # indicates that there is a problem;
		    #                        # eg synonym spelled wrongly
		    #                        # [MetaCyc accessions have spaces!]
		    #                        my $msg =
		    #                          "ignoring $db:$dbacc - doesn't look like accession";
		    #                        $self->parse_err({msg=>$msg,
		    #                                        line_no=>$lnum,
		    #                                        line=>$line,
		    #                                        file=>$file});
		    #                    }
                    else {
                        $self->event(XREF_ANALOG, [[dbname => $db], [acc => $dbacc]]);
                    }
                }
            } else {
                # other parts on line
                # have redundant info,
                # but the relationship
                # part is useful
                my $rchar = $self->typemap($parts[$i-1],\%typemap);
		if (!$pxref) {
		    $self->parse_err("problem with $name $currxref: rel $rchar has no parent/object");
		} else {
		    $self->relationship_event($rchar, $pxref);
		}
            }
        }
	#$line =~ s/\\//g;
        # end of parse body
        if (@stack) {
            my $up = $stack[$#stack];
	    my $obj = $up->[1];
	    if (!$obj) {
		$self->parse_err("problem with $currxref: rel $rchar has no parent/object [top of stack is @$up]");
	    } else {
		$self->relationship_event($rchar, $up->[1]);
		$rtypenameh{$rchar} = 1;
	    }
        } else {
	    #            $self->event("rel", "isa", "TOP");
        }
        $self->end_event(TERM);
        push(@stack, [$indent, $currxref]);
    }
    $self->pop_stack_to_depth(1);
    foreach my $rtypename (keys %rtypenameh) {
	next if $rtypename eq 'is_a';
	$self->event(TYPEDEF, [
			       [id=>$rtypename],
			       [name=>$rtypename],
			       [domain=>$root_id],
			       [range=>$root_id],
			      ]);
    }
    $self->pop_stack_to_depth(0);
    $self->parsed_ontology(1);
}

sub relationship_event {
    my $self = shift;
    my $rchar = shift;
    my $to = shift;

    if ($rchar eq 'is_a' ||
	$rchar eq 'isa') {
	$self->event(IS_A, $to);
    }
    else {
	$self->event(RELATIONSHIP,
		     [[type => $rchar],
		      [to=>$to]]);
    }
}


sub typemap {
    my $self = shift;
    my $ch = shift;
    my %typemap = %{shift || {}};
    $ch =~ s/^ *//g;
    $ch =~ s/ *$//g;
    if ($typemap{$ch}) {
        $ch = $typemap{$ch};
    }
    elsif ($typemap{'\\'.$ch}) {
        $ch = $typemap{$ch};
    }
    elsif ($ch =~ /^\@(\w+)\@/) {
	$ch = lc($1);
    }
    else {
    }
    $ch =~ s/isa/is_a/;
    $ch =~ s/partof/part_of/;
    $ch;
}

sub unescapego {
    my $self = shift;
    my $ch = shift;
    $ch =~ s/\\//g;
    $ch;

}

1;