| 1 | # | ||||||||||
| 2 | # BioPerl module for Bio::Factory::SeqAnalysisParserFactory | ||||||||||
| 3 | # | ||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||
| 5 | # | ||||||||||
| 6 | # Cared for by Jason Stajich <jason@bioperl.org>, | ||||||||||
| 7 | # and Hilmar Lapp <hlapp@gmx.net> | ||||||||||
| 8 | # | ||||||||||
| 9 | # Copyright Jason Stajich, Hilmar Lapp | ||||||||||
| 10 | # | ||||||||||
| 11 | # You may distribute this module under the same terms as perl itself | ||||||||||
| 12 | |||||||||||
| 13 | # POD documentation - main docs before the code | ||||||||||
| 14 | |||||||||||
| 15 | =head1 NAME | ||||||||||
| 16 | |||||||||||
| 17 | Bio::Factory::SeqAnalysisParserFactory - class capable of creating | ||||||||||
| 18 | SeqAnalysisParserI compliant parsers | ||||||||||
| 19 | |||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||
| 21 | |||||||||||
| 22 | # initialize an object implementing this interface, e.g. | ||||||||||
| 23 | $factory = Bio::Factory::SeqAnalysisParserFactory->new(); | ||||||||||
| 24 | # find out the methods it knows about | ||||||||||
| 25 | print "registered methods: ", | ||||||||||
| 26 | join(', ', keys %{$factory->driver_table}), "\n"; | ||||||||||
| 27 | # obtain a parser object | ||||||||||
| 28 | $parser = $factory->get_parser(-input=>$inputobj, | ||||||||||
| 29 | -params=>[@params], | ||||||||||
| 30 | -method => $method); | ||||||||||
| 31 | # $parser is an object implementing Bio::SeqAnalysisParserI | ||||||||||
| 32 | # annotate sequence with features produced by parser | ||||||||||
| 33 | while(my $feat = $parser->next_feature()) { | ||||||||||
| 34 | $seq->add_SeqFeature($feat); | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | =head1 DESCRIPTION | ||||||||||
| 38 | |||||||||||
| 39 | This is a factory class capable of instantiating SeqAnalysisParserI | ||||||||||
| 40 | implementing parsers. | ||||||||||
| 41 | |||||||||||
| 42 | The concept behind this class and the interface it implements | ||||||||||
| 43 | (Bio::Factory::SeqAnalysisParserFactoryI) is a generic analysis result | ||||||||||
| 44 | parsing in high-throughput automated sequence annotation | ||||||||||
| 45 | pipelines. See Bio::SeqAnalysisParserI for more documentation of this | ||||||||||
| 46 | concept. | ||||||||||
| 47 | |||||||||||
| 48 | You can always find out the methods an instance of this class knows | ||||||||||
| 49 | about by the way given in the SYNOPSIS section. By default, and | ||||||||||
| 50 | assuming that the documentation is up-to-date, this will comprise of | ||||||||||
| 51 | genscan, mzef, estscan, blast, hmmer, gff, and sim4 (all | ||||||||||
| 52 | case-insensitive). | ||||||||||
| 53 | |||||||||||
| 54 | =head1 FEEDBACK | ||||||||||
| 55 | |||||||||||
| 56 | =head2 Mailing Lists | ||||||||||
| 57 | |||||||||||
| 58 | User feedback is an integral part of the evolution of this | ||||||||||
| 59 | and other Bioperl modules. Send your comments and suggestions preferably | ||||||||||
| 60 | to one of the Bioperl mailing lists. | ||||||||||
| 61 | Your participation is much appreciated. | ||||||||||
| 62 | |||||||||||
| 63 | bioperl-l@bioperl.org - General discussion | ||||||||||
| 64 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||
| 65 | |||||||||||
| 66 | =head2 Support | ||||||||||
| 67 | |||||||||||
| 68 | Please direct usage questions or support issues to the mailing list: | ||||||||||
| 69 | |||||||||||
| 70 | I<bioperl-l@bioperl.org> | ||||||||||
| 71 | |||||||||||
| 72 | rather than to the module maintainer directly. Many experienced and | ||||||||||
| 73 | reponsive experts will be able look at the problem and quickly | ||||||||||
| 74 | address it. Please include a thorough description of the problem | ||||||||||
| 75 | with code and data examples if at all possible. | ||||||||||
| 76 | |||||||||||
| 77 | =head2 Reporting Bugs | ||||||||||
| 78 | |||||||||||
| 79 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||
| 80 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||
| 81 | web: | ||||||||||
| 82 | |||||||||||
| 83 | https://github.com/bioperl/bioperl-live/issues | ||||||||||
| 84 | |||||||||||
| 85 | =head1 AUTHOR - Hilmar Lapp, Jason Stajich | ||||||||||
| 86 | |||||||||||
| 87 | Email Hilmar Lapp E<lt>hlapp@gmx.netE<gt>, Jason Stajich E<lt>jason@bioperl.orgE<gt> | ||||||||||
| 88 | |||||||||||
| 89 | =head1 APPENDIX | ||||||||||
| 90 | |||||||||||
| 91 | The rest of the documentation details each of the object | ||||||||||
| 92 | methods. Internal methods are usually preceded with a _ | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | package Bio::Factory::SeqAnalysisParserFactory; | ||||||||||
| 97 | 2 | $Bio::Factory::SeqAnalysisParserFactory::VERSION = '1.7.8'; | |||||||||
| 98 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 99 | |||||||||||
| 100 | |||||||||||
| 101 | 2 | ▶ | use base qw(Bio::Factory::DriverFactory Bio::Factory::SeqAnalysisParserFactoryI); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 102 | |||||||||||
| 103 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 104 | 2 | Bio::Factory::DriverFactory->register_driver | |||||||||
| 105 | ( | ||||||||||
| 106 | "genscan" => "Bio::Tools::Genscan", | ||||||||||
| 107 | "mzef" => "Bio::Tools::MZEF", | ||||||||||
| 108 | "estscan" => "Bio::Tools::ESTScan", | ||||||||||
| 109 | "hmmer" => "Bio::Tools::HMMER::Result", | ||||||||||
| 110 | "gff" => "Bio::Tools::GFF", | ||||||||||
| 111 | "sim4" => "Bio::Tools::Sim4::Results", | ||||||||||
| 112 | "epcr" => "Bio::Tools::EPCR", | ||||||||||
| 113 | "exonerate" => "Bio::Tools::Exonerate", | ||||||||||
| 114 | ); | ||||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 118 | 1 | my ($class, @args) = @_; | |||||||||
| 119 | 1 | my $self = $class->SUPER::new(@args); | |||||||||
| 120 | |||||||||||
| 121 | # no per-object initialization right now - registration of default drivers | ||||||||||
| 122 | # is only done once when the module is loaded | ||||||||||
| 123 | 1 | return $self; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | =head2 get_parser | ||||||||||
| 127 | |||||||||||
| 128 | Title : get_parser | ||||||||||
| 129 | Usage : $factory->get_parser(-input=>$inputobj, | ||||||||||
| 130 | [ -params=>[@params] ], | ||||||||||
| 131 | -method => $method) | ||||||||||
| 132 | Function: Creates and returns a parser object for the given input and method. | ||||||||||
| 133 | Both file names and streams (filehandles) are allowed. | ||||||||||
| 134 | |||||||||||
| 135 | Parameters (-params argument) are passed on to the parser object | ||||||||||
| 136 | and therefore are specific to the parser to be created. | ||||||||||
| 137 | Example : | ||||||||||
| 138 | Returns : A Bio::SeqAnalysisParserI implementing object. Exception if | ||||||||||
| 139 | creation of the parser object fails. | ||||||||||
| 140 | Args : B<input> - object/file where analysis results are coming from, | ||||||||||
| 141 | B<params> - parameter to use when parsing/running analysis | ||||||||||
| 142 | B<method> - method of analysis | ||||||||||
| 143 | |||||||||||
| 144 | =cut | ||||||||||
| 145 | |||||||||||
| 146 | 3 | ▶ | sub get_parser { | ||||||||
|
Subroutine
get_parser: called CC=5 SCAR=17.3
Pod
documented
| |||||||||||
| 147 | 3 | my ($self, @args) = @_; | |||||||||
| 148 | 3 | my $parser; | |||||||||
| 149 | my $module; | ||||||||||
| 150 | |||||||||||
| 151 | 3 | my ($input, $params, $method) = | |||||||||
| 152 | $self->_rearrange([qw(INPUT PARAMS METHOD)], @args); | ||||||||||
| 153 | |||||||||||
| 154 | # retrieve module name for requested method | ||||||||||
| 155 | 3 | $method = lc $method; # method is case-insensitive | |||||||||
| 156 | 3 | $module = $self->get_driver($method); | |||||||||
| 157 | 3 | ▶ | if(! defined($module)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | 0 | $self->throw("Analysis parser driver for method $method not registered."); | |||||||||
| 159 | } | ||||||||||
| 160 | # load module | ||||||||||
| 161 | 3 | $self->_load_module($module); # throws an exception on failure to load | |||||||||
| 162 | # make sure parameters is not undef | ||||||||||
| 163 | 3 | ▶ | $params = [] if( !defined $params ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 164 | # figure out input method (file or stream) | ||||||||||
| 165 | 3 | my $inputmethod = '-file'; | |||||||||
| 166 | 3 | ▶ | if( ref($input) =~ /GLOB/i ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 167 | 0 | $inputmethod = '-fh'; | |||||||||
| 168 | } | ||||||||||
| 169 | # instantiate parser and return the result | ||||||||||
| 170 | 3 | $parser = $module->new($inputmethod => $input, @$params); | |||||||||
| 171 | 3 | ▶ | if(! $parser->isa('Bio::SeqAnalysisParserI')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 172 | 0 | $self->throw("Driver $module registered for method $method does not ". | |||||||||
| 173 | "implement Bio::SeqAnalyisParserI. How come?"); | ||||||||||
| 174 | } | ||||||||||
| 175 | 3 | return $parser; | |||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | |||||||||||
| 179 | =head2 register_driver | ||||||||||
| 180 | |||||||||||
| 181 | Title : register_driver | ||||||||||
| 182 | Usage : $factory->register_driver("genscan", "Bio::Tools::Genscan"); | ||||||||||
| 183 | Function: Registers a driver a factory class should be able to instantiate. | ||||||||||
| 184 | |||||||||||
| 185 | This method can be called both as an instance and as a | ||||||||||
| 186 | class method. | ||||||||||
| 187 | |||||||||||
| 188 | Returns : | ||||||||||
| 189 | Args : Key of the driver (string) and the module implementing the driver | ||||||||||
| 190 | (string). | ||||||||||
| 191 | |||||||||||
| 192 | =cut | ||||||||||
| 193 | |||||||||||
| 194 | =head2 driver_table | ||||||||||
| 195 | |||||||||||
| 196 | Title : driver_table | ||||||||||
| 197 | Usage : $table = $factory->driver_table(); | ||||||||||
| 198 | Function: Returns a reference to the hash table storing associations of | ||||||||||
| 199 | methods with drivers. | ||||||||||
| 200 | |||||||||||
| 201 | You use this table to look up registered methods (keys) and | ||||||||||
| 202 | drivers (values). | ||||||||||
| 203 | |||||||||||
| 204 | In this implementation the table is class-specific and | ||||||||||
| 205 | therefore shared by all instances. You can override this in | ||||||||||
| 206 | a derived class, but note that this method can be called | ||||||||||
| 207 | both as an instance and a class method. | ||||||||||
| 208 | |||||||||||
| 209 | This will be the table used by the object internally. You | ||||||||||
| 210 | should definitely know what you're doing if you modify the | ||||||||||
| 211 | table's contents. Modifications are shared by _all_ | ||||||||||
| 212 | instances, those present and those yet to be created. | ||||||||||
| 213 | |||||||||||
| 214 | Returns : A reference to a hash table. | ||||||||||
| 215 | Args : | ||||||||||
| 216 | |||||||||||
| 217 | |||||||||||
| 218 | =cut | ||||||||||
| 219 | |||||||||||
| 220 | |||||||||||
| 221 | 2 | 1; | |||||||||