0
|
1 # $Id: SeqAnalysisParserFactory.pm,v 1.9 2002/12/01 00:05:20 jason Exp $
|
|
2 #
|
|
3 # BioPerl module for Bio::Factory::SeqAnalysisParserFactory
|
|
4 #
|
|
5 # Cared for by Jason Stajich <jason@bioperl.org>,
|
|
6 # and Hilmar Lapp <hlapp@gmx.net>
|
|
7 #
|
|
8 # Copyright Jason Stajich, Hilmar Lapp
|
|
9 #
|
|
10 # You may distribute this module under the same terms as perl itself
|
|
11
|
|
12 # POD documentation - main docs before the code
|
|
13
|
|
14 =head1 NAME
|
|
15
|
|
16 Bio::Factory::SeqAnalysisParserFactory - class capable of
|
|
17 creating SeqAnalysisParserI compliant parsers
|
|
18
|
|
19 =head1 SYNOPSIS
|
|
20
|
|
21 # initialize an object implementing this interface, e.g.
|
|
22 $factory = Bio::Factory::SeqAnalysisParserFactory->new();
|
|
23 # find out the methods it knows about
|
|
24 print "registered methods: ",
|
|
25 join(', ', keys($factory->driver_table())), "\n";
|
|
26 # obtain a parser object
|
|
27 $parser = $factory->get_parser(-input=>$inputobj,
|
|
28 -params=>[@params],
|
|
29 -method => $method);
|
|
30 # $parser is an object implementing Bio::SeqAnalysisParserI
|
|
31 # annotate sequence with features produced by parser
|
|
32 while(my $feat = $parser->next_feature()) {
|
|
33 $seq->add_SeqFeature($feat);
|
|
34 }
|
|
35
|
|
36 =head1 DESCRIPTION
|
|
37
|
|
38 This is a factory class capable of instantiating SeqAnalysisParserI
|
|
39 implementing parsers.
|
|
40
|
|
41 The concept behind this class and the interface it implements
|
|
42 (Bio::Factory::SeqAnalysisParserFactoryI) is a generic analysis result parsing
|
|
43 in high-throughput automated sequence annotation pipelines. See
|
|
44 Bio::SeqAnalysisParserI for more documentation of this concept.
|
|
45
|
|
46 You can always find out the methods an instance of this class knows
|
|
47 about by the way given in the SYNOPSIS section. By default, and
|
|
48 assuming that the documentation is up-to-date, this will comprise of
|
|
49 genscan, mzef, estscan, blast, hmmer, gff, and sim4 (all case-insensitive).
|
|
50
|
|
51 =head1 FEEDBACK
|
|
52
|
|
53 =head2 Mailing Lists
|
|
54
|
|
55 User feedback is an integral part of the evolution of this
|
|
56 and other Bioperl modules. Send your comments and suggestions preferably
|
|
57 to one of the Bioperl mailing lists.
|
|
58 Your participation is much appreciated.
|
|
59
|
|
60 bioperl-l@bioperl.org - General discussion
|
|
61 http://bio.perl.org/MailList.html - About the mailing lists
|
|
62
|
|
63 =head2 Reporting Bugs
|
|
64
|
|
65 Report bugs to the Bioperl bug tracking system to help us keep track
|
|
66 the bugs and their resolution.
|
|
67 Bug reports can be submitted via email or the web:
|
|
68
|
|
69 bioperl-bugs@bio.perl.org
|
|
70 http://bugzilla.bioperl.org/
|
|
71
|
|
72 =head1 AUTHOR - Hilmar Lapp, Jason Stajich
|
|
73
|
|
74 Email Hilmar Lapp E<lt>hlapp@gmx.netE<gt>, Jason Stajich E<lt>jason@bioperl.orgE<gt>
|
|
75
|
|
76 =head1 APPENDIX
|
|
77
|
|
78 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
|
|
79
|
|
80 =cut
|
|
81
|
|
82 package Bio::Factory::SeqAnalysisParserFactory;
|
|
83 use strict;
|
|
84
|
|
85 use Bio::Factory::SeqAnalysisParserFactoryI;
|
|
86 use Bio::Factory::DriverFactory;
|
|
87
|
|
88 use vars qw(@ISA);
|
|
89 @ISA = qw(Bio::Factory::DriverFactory Bio::Factory::SeqAnalysisParserFactoryI);
|
|
90
|
|
91 BEGIN {
|
|
92 Bio::Factory::DriverFactory->register_driver
|
|
93 (
|
|
94 "genscan" => "Bio::Tools::Genscan",
|
|
95 "mzef" => "Bio::Tools::MZEF",
|
|
96 "estscan" => "Bio::Tools::ESTScan",
|
|
97 "bplite" => "Bio::Tools::BPlite",
|
|
98 "blast" => "Bio::Tools::BPlite",
|
|
99 "hmmer" => "Bio::Tools::HMMER::Result",
|
|
100 "gff" => "Bio::Tools::GFF",
|
|
101 "sim4" => "Bio::Tools::Sim4::Results",
|
|
102 "epcr" => "Bio::Tools::EPCR",
|
|
103 "exonerate" => "Bio::Tools::Exonerate",
|
|
104 );
|
|
105 }
|
|
106
|
|
107 sub new {
|
|
108 my ($class, @args) = @_;
|
|
109 my $self = $class->SUPER::new(@args);
|
|
110
|
|
111 # no per-object initialization right now - registration of default drivers
|
|
112 # is only done once when the module is loaded
|
|
113 return $self;
|
|
114 }
|
|
115
|
|
116 =head2 get_parser
|
|
117
|
|
118 Title : get_parser
|
|
119 Usage : $factory->get_parser(-input=>$inputobj,
|
|
120 [ -params=>[@params] ],
|
|
121 -method => $method)
|
|
122 Function: Creates and returns a parser object for the given input and method.
|
|
123 Both file names and streams (filehandles) are allowed.
|
|
124
|
|
125 Parameters (-params argument) are passed on to the parser object
|
|
126 and therefore are specific to the parser to be created.
|
|
127 Example :
|
|
128 Returns : A Bio::SeqAnalysisParserI implementing object. Exception if
|
|
129 creation of the parser object fails.
|
|
130 Args : B<input> - object/file where analysis results are coming from,
|
|
131 B<params> - parameter to use when parsing/running analysis
|
|
132 B<method> - method of analysis
|
|
133
|
|
134 =cut
|
|
135
|
|
136 sub get_parser {
|
|
137 my ($self, @args) = @_;
|
|
138 my $parser;
|
|
139 my $module;
|
|
140
|
|
141 my ($input, $params, $method) =
|
|
142 $self->_rearrange([qw(INPUT PARAMS METHOD)], @args);
|
|
143
|
|
144 # retrieve module name for requested method
|
|
145 $method = lc $method; # method is case-insensitive
|
|
146 $module = $self->get_driver($method);
|
|
147 if(! defined($module)) {
|
|
148 $self->throw("Analysis parser driver for method $method not registered.");
|
|
149 }
|
|
150 # load module
|
|
151 $self->_load_module($module); # throws an exception on failure to load
|
|
152 # make sure parameters is not undef
|
|
153 $params = [] if( !defined $params );
|
|
154 # figure out input method (file or stream)
|
|
155 my $inputmethod = '-file';
|
|
156 if( ref($input) =~ /GLOB/i ) {
|
|
157 $inputmethod = '-fh';
|
|
158 }
|
|
159 # instantiate parser and return the result
|
|
160 $parser = $module->new($inputmethod => $input, @$params);
|
|
161 if(! $parser->isa('Bio::SeqAnalysisParserI')) {
|
|
162 $self->throw("Driver $module registered for method $method does not implement Bio::SeqAnalyisParserI. How come?");
|
|
163 }
|
|
164 return $parser;
|
|
165 }
|
|
166
|
|
167 1;
|