2 # BioPerl module for InterProParser
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Peter Dimitrov <dimitrov@gnf.org>
8 # Copyright Peter Dimitrov
9 # (c) Peter Dimitrov, dimitrov@gnf.org, 2002.
10 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
12 # You may distribute this module under the same terms as perl itself.
13 # Refer to the Perl Artistic License (see the license accompanying this
14 # software package, or see http://www.perl.com/language/misc/Artistic.html)
15 # for the terms under which you may use, modify, and redistribute this module.
17 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
18 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 # POD documentation - main docs before the code
25 Bio::OntologyIO::InterProParser - Parser for InterPro xml files.
29 # don't use this module directly - use Bio::OntologyIO with instead
30 my $ipp = Bio::OntologyIO->new( -format => 'interpro',
31 -file => 't/data/interpro.xml',
32 -ontology_engine => 'simple' );
36 Use InterProParser to parse InterPro files in xml format. Typical
37 use is the interpro.xml file published by EBI. The xml records
38 should follow the format described in interpro.dtd, although the dtd
39 file is not needed, and the XML file will not be validated against it.
45 User feedback is an integral part of the evolution of this and other
46 Bioperl modules. Send your comments and suggestions preferably to
47 the Bioperl mailing list. Your participation is much appreciated.
49 bioperl-l@bioperl.org - General discussion
50 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
54 Please direct usage questions or support issues to the mailing list:
56 I<bioperl-l@bioperl.org>
58 rather than to the module maintainer directly. Many experienced and
59 reponsive experts will be able look at the problem and quickly
60 address it. Please include a thorough description of the problem
61 with code and data examples if at all possible.
65 Report bugs to the Bioperl bug tracking system to help us keep track
66 of the bugs and their resolution. Bug reports can be submitted via the
69 https://github.com/bioperl/bioperl-live/issues
71 =head1 AUTHOR - Peter Dimitrov
73 Email dimitrov@gnf.org
77 The rest of the documentation details each of the object methods.
78 Internal methods are usually preceded with a _
83 # Let the code begin...
86 package Bio
::OntologyIO
::InterProParser
;
89 use XML
::Parser
::PerlSAX
;
90 use Bio
::Ontology
::SimpleOntologyEngine
;
91 use Bio
::Ontology
::TermFactory
;
92 use Bio
::OntologyIO
::Handlers
::InterProHandler
;
94 use base
qw(Bio::OntologyIO);
100 Function: Initializes objects needed for parsing.
101 Example : $ipp = Bio::OntologyIO::InterProParser->new(
102 -file => 't/data/interpro.xml',
103 -ontology_engine => 'simple' )
105 Returns : Object of class Bio::OntologyIO::InterProParser.
109 -ontology_engine - type of ontology engine. Should satisfy the
110 OntologyEngine interface requirements. Currently
111 the only option is 'simple'. In the future
112 Graph.pm based engine will be added to the
118 # in reality we let OntologyIO handle the first pass initialization
119 # and instead override _initialize().
123 $self->SUPER::_initialize
(@_);
125 my ($eng,$eng_type,$name) =
126 $self->_rearrange([qw(ENGINE
131 my $ip_h = Bio
::OntologyIO
::Handlers
::InterProHandler
->new(
132 -ontology_name
=> $name);
135 $eng_type = 'simple' unless $eng_type;
136 if(lc($eng_type) eq 'simple') {
137 $eng = Bio
::Ontology
::SimpleOntologyEngine
->new();
139 $self->throw("ontology engine type '$eng_type' ".
140 "not implemented yet");
143 if($eng->isa("Bio::Ontology::OntologyI")) {
144 $ip_h->ontology($eng);
145 $eng = $eng->engine() if $eng->can('engine');
147 $self->{_ontology_engine
} = $eng;
148 $ip_h->ontology_engine($eng);
150 $self->{_parser
} = XML
::Parser
::PerlSAX
->new( Handler
=> $ip_h );
151 $self->{_interpro_handler
} = $ip_h;
153 # default term object factory
154 $self->term_factory(Bio
::Ontology
::TermFactory
->new(
155 -type
=> "Bio::Ontology::InterProTerm"))
156 unless $self->term_factory();
157 $ip_h->term_factory($self->term_factory());
165 Function: Performs the actual parsing.
166 Example : $ipp->parse();
177 $ret = $self->{_parser
}->parse( Source
=> {
178 SystemId
=> $self->file() } );
179 } elsif ($self->_fh()) {
180 $ret = $self->{_parser
}->parse( Source
=> {
181 ByteStream
=> $self->_fh() } );
184 $self->throw("Only filenames and filehandles are understood here.\n");
187 $self->_is_parsed(1);
193 Title : next_ontology
194 Usage : $ipp->next_ontology()
195 Function: Parses the input file and returns the next InterPro ontology
198 Usually there will be only one ontology returned from an
201 Example : $ipp->next_ontology();
202 Returns : Returns the ontology as a Bio::Ontology::OntologyEngineI
206 See L<Bio::Ontology::OntologyEngineI>.
213 $self->parse() unless $self->_is_parsed();
214 # there is only one ontology in an InterPro source file
215 if(exists($self->{'_ontology_engine'})) {
216 my $ont = $self->{_interpro_handler
}->ontology();
217 delete $self->{_ontology_engine
};
226 Usage : $obj->_is_parsed($newval)
229 Returns : value of _is_parsed (a scalar)
230 Args : on set, new value (a scalar or undef, optional)
237 return $self->{'_is_parsed'} = shift if @_;
238 return $self->{'_is_parsed'};
241 =head2 secondary_accessions_map
243 Title : secondary_accessions_map
244 Usage : $obj->secondary_accessions_map()
245 Function: This method is merely for convenience, and one should
246 normally use the InterProTerm secondary_ids method to
247 access the secondary accessions.
248 Example : $map = $interpro_parser->secondary_accessions_map;
249 Returns : Reference to a hash that maps InterPro identifier to an
250 array reference of secondary accessions following the
252 Args : Empty hash reference
256 sub secondary_accessions_map
{
259 return $self->{_interpro_handler
}->{secondary_accessions_map
};