/usr/share/perl5/GO/Parsers/unknown_format_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 | # $Id: unknown_format_parser.pm,v 1.9 2005/08/18 21:23:11 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::unknown_format_parser;
=head1 NAME
GO::Parsers::unknown_format_parser - base class for parsers
=head1 SYNOPSIS
do not use this class directly; use GO::Parser
=cut
=head1 DESCRIPTION
=head1 AUTHOR
=cut
use Carp;
use FileHandle;
use GO::Parser;
use base qw(GO::Parsers::base_parser Exporter);
use strict qw(subs vars refs);
sub parse_file_by_type {
shift->parse_file(@_);
}
sub parse_file {
my ($self, $file, $dtype) = @_;
$self->file($file);
my $fmt; # input file format
my $p;
# determine format based on dtype
# (legacy code - dtypes should switch to standard formars)
if ($dtype) {
# convert legacy types
if ($dtype =~ /ontology$/) {
$fmt = "go_ont";
}
elsif ($dtype =~ /defs$/) {
$fmt = "go_def";
}
elsif ($dtype =~ /xrefs$/) {
$fmt = "go_xref";
}
elsif ($dtype =~ /assocs$/) {
$fmt = "go_assoc";
}
else {
$fmt = $dtype;
}
}
if (!$p) {
# no default parser, or it has been overwritten
if (!$fmt) {
# messy guessing of format from file extension
if ($file =~ /\.go$/) {
$fmt = "go_ont";
}
if ($file =~ /\.ontology$/) {
$fmt = "go_ont";
}
if ($file =~ /defs$/) {
$fmt = "go_def";
}
if ($file =~ /2go$/) {
$fmt = "go_xref";
}
if ($file =~ /gene_association/) {
$fmt = "go_assoc";
}
if ($file =~ /\.obo$/ || $file =~ /\.obo[\.\-_]text$/) {
$fmt = "obo_text";
}
if ($file =~ /\.obo\W*xml$/) {
$fmt = "obo_xml";
}
if (!$fmt) {
# if suffix is a known parser module, use it
if ($file =~ /\.(\w+)$/) {
my $suffix = $1;
my $mod = "GO/Parsers/$suffix"."_parser.pm";
eval {
require "$mod";
};
if ($@) {
}
else {
$fmt = $suffix;
}
}
}
if (!$fmt) {
#$self->throw("I have no idea how to parse: $file\n");
open(F,$file) || $self->throw("Cannot open $file");
my $first_line = <F>;
if ($first_line =~ /^format/) {
$fmt = 'obo_text';
}
else {
$fmt = 'go_ont';
}
close(F);
}
}
$p = GO::Parser->get_parser_impl($fmt);
}
%$p = %$self;
$p->parse($file);
%$self = %$p;
$self->parser($p);
$self;
}
sub parser {
my $self = shift;
$self->{_parser} = shift if @_;
return $self->{_parser};
}
sub parse {
my $self = shift;
my $filename;
foreach $filename (@_) {
$self->parse_file($filename);
}
return;
}
# deprecated!
sub parse_ontology {
my ($self, $file) = @_;
$self->parse_file($file, 'go_ont');
}
1;
|