« blib/lib/Bio/Tools/Run/RepeatMasker.pm
↑ Summary
blib/lib/Bio/DB/SoapEUtilities/DocSumAdaptor.pm »
| 1 | # $Id$ | ||
| 2 | # | ||
| 3 | # BioPerl module for Bio::DB::SoapEUtilities::FetchAdaptor | ||
| 4 | # | ||
| 5 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||
| 6 | # | ||
| 7 | # Cared for by Mark A. Jensen <maj -at- fortinbras -dot- us> | ||
| 8 | # | ||
| 9 | # Copyright Mark A. Jensen | ||
| 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::DB::SoapEUtilities::FetchAdaptor - Conversion of Entrez SOAP messages to BioPerl objects | ||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | $fac = Bio::DB::SoapEUtilities->new(); | ||
| 22 | $soap_result = $fac->efetch( -db => 'protein', -id => 2597988 ); | ||
| 23 | $adp = Bio::DB::SoapEUtilities::FetchAdaptor( | ||
| 24 | -result => $soap_result, | ||
| 25 | -type => 'seq' | ||
| 26 | ); | ||
| 27 | while ( $gb_seq = $adp->next_obj ) { | ||
| 28 | # do stuff | ||
| 29 | } | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | C<FetchAdaptor> is the base class of a system, modeled after | ||
| 34 | L<Bio::SeqIO>, to parse SOAP responses from the NCBI Entrez C<efetch> | ||
| 35 | utility into germane BioPerl objects. | ||
| 36 | |||
| 37 | The user will rarely need to instantiate a C<FetchAdaptor> with | ||
| 38 | L<Bio::DB::SoapEUtilities::Result> object as in the L</SYNOPSIS>. It | ||
| 39 | usually suffices to use the C<-auto_adapt> parameter in the factory | ||
| 40 | C<run()> method: | ||
| 41 | |||
| 42 | my $fac = Bio::DB::SoapEUtilities->new(); | ||
| 43 | my $taxio = $fac->efetch(-db => 'taxonomy', -id => 1394)->run(-auto_adapt=>1); | ||
| 44 | my $sp = $taxio->next_species; # Bio::Species objects | ||
| 45 | my $seqio = $fac->efetch(-db => 'protein', -id => 730439)->run(-auto_adapt=>1); | ||
| 46 | my $seq = $seqio->next_seq; # Bio::Seq::RichSeq objects | ||
| 47 | |||
| 48 | =head1 SEE ALSO | ||
| 49 | |||
| 50 | L<Bio::DB::SoapEUtilities>, C<FetchAdaptor> subclasses | ||
| 51 | |||
| 52 | =head1 FEEDBACK | ||
| 53 | |||
| 54 | =head2 Mailing Lists | ||
| 55 | |||
| 56 | User feedback is an integral part of the evolution of this and other | ||
| 57 | Bioperl modules. Send your comments and suggestions preferably to | ||
| 58 | the Bioperl mailing list. Your participation is much appreciated. | ||
| 59 | |||
| 60 | bioperl-l@bioperl.org - General discussion | ||
| 61 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||
| 62 | |||
| 63 | =head2 Support | ||
| 64 | |||
| 65 | Please direct usage questions or support issues to the mailing list: | ||
| 66 | |||
| 67 | L<bioperl-l@bioperl.org> | ||
| 68 | |||
| 69 | rather than to the module maintainer directly. Many experienced and | ||
| 70 | reponsive experts will be able look at the problem and quickly | ||
| 71 | address it. Please include a thorough description of the problem | ||
| 72 | with code and data examples if at all possible. | ||
| 73 | |||
| 74 | =head2 Reporting Bugs | ||
| 75 | |||
| 76 | Report bugs to the Bioperl bug tracking system to help us keep track | ||
| 77 | of the bugs and their resolution. Bug reports can be submitted via | ||
| 78 | the web: | ||
| 79 | |||
| 80 | http://redmine.open-bio.org/projects/bioperl/ | ||
| 81 | |||
| 82 | =head1 AUTHOR - Mark A. Jensen | ||
| 83 | |||
| 84 | Email maj -at- fortinbras -dot- us | ||
| 85 | |||
| 86 | =head1 APPENDIX | ||
| 87 | |||
| 88 | The rest of the documentation details each of the object methods. | ||
| 89 | Internal methods are usually preceded with a _ | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||
| 93 | package Bio::DB::SoapEUtilities::FetchAdaptor; | ||
| 94 | use strict; | ||
| 95 | |||
| 96 | use Bio::Root::Root; | ||
| 97 | |||
| 98 | use base qw(Bio::Root::Root ); | ||
| 99 | |||
| 100 | =head2 new | ||
| 101 | |||
| 102 | Title : new | ||
| 103 | Usage : my $obj = new Bio::DB::SoapEUtilities::FetchAdaptor(); | ||
| 104 | Function: Builds a new Bio::DB::SoapEUtilities::FetchAdaptor object | ||
| 105 | Returns : an instance of Bio::DB::SoapEUtilities::FetchAdaptor | ||
| 106 | Args : named arguments | ||
| 107 | -som => $soap_som_object (soap message) | ||
| 108 | -type => $type ( optional, forces loading of $type adaptor ) | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | sub new { | ||
| 113 | my ($class,@args) = @_; | ||
| 114 | $class = ref($class) || $class; | ||
| 115 | if ($class =~ /.*?::FetchAdaptor::(\S+)/) { | ||
| 116 | my $self = $class->SUPER::new(@args); | ||
| 117 | $self->_initialize(@args); | ||
| 118 | return $self; | ||
| 119 | } | ||
| 120 | else { | ||
| 121 | my %args = @args; | ||
| 122 | my $result = $args{'-result'} || $args{'-RESULT'}; | ||
| 123 | $class->throw("Bio::DB::SoapEUtilities::Result argument required") unless $result; | ||
| 124 | $class->throw("RESULT argument must be a Bio::DB::SoapEUtilities::Result object") unless | ||
| 125 | ref($result) eq 'Bio::DB::SoapEUtilities::Result'; | ||
| 126 | # identify the correct adaptor module to load using Result info | ||
| 127 | my $type ||= $result->fetch_type; | ||
| 128 | $class->throw("Can't determine fetch type for this result") | ||
| 129 | unless $type; | ||
| 130 | # $type ultimately contains a FetchAdaptor subclass | ||
| 131 | return unless( $class->_load_adaptor($type, $result) ); | ||
| 132 | return "Bio::DB::SoapEUtilities::FetchAdaptor::$type"->new(@args); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | =head2 _initialize() | ||
| 137 | |||
| 138 | Title : _initialize | ||
| 139 | Usage : | ||
| 140 | Function: | ||
| 141 | Returns : | ||
| 142 | Args : | ||
| 143 | |||
| 144 | =cut | ||
| 145 | |||
| 146 | sub _initialize { | ||
| 147 | my $self = shift; | ||
| 148 | my @args = @_; | ||
| 149 | my ($result, $type) = $self->_rearrange([qw( RESULT TYPE )], @args); | ||
| 150 | $self->throw("Bio::DB::SoapEUtilities::Result argument required") unless $result; | ||
| 151 | $self->throw("RESULT argument must be a Bio::DB::SoapEUtilities::Result object") unless | ||
| 152 | ref($result) eq 'Bio::DB::SoapEUtilities::Result'; | ||
| 153 | $self->{'_type'} = $type || $result->fetch_type; | ||
| 154 | $self->{'_result'} = $result; | ||
| 155 | 1; | ||
| 156 | } | ||
| 157 | |||
| 158 | =head2 _load_adaptor() | ||
| 159 | |||
| 160 | Title : _load_adaptor | ||
| 161 | Usage : | ||
| 162 | Function: loads a FetchAdaptor subclass | ||
| 163 | Returns : | ||
| 164 | Args : adaptor type (subclass name) | ||
| 165 | |||
| 166 | =cut | ||
| 167 | |||
| 168 | sub _load_adaptor { | ||
| 169 | my ($class, $type, $result) = @_; | ||
| 170 | return unless $type; | ||
| 171 | # specials | ||
| 172 | for ($result->fetch_type) { | ||
| 173 | $_ eq 'seq' && do { | ||
| 174 | $_[1] = $type = 'species' if $result->fetch_db and | ||
| 175 | $result->fetch_db eq 'taxonomy'; | ||
| 176 | last; | ||
| 177 | }; | ||
| 178 | # else, leave $type alone | ||
| 179 | } | ||
| 180 | my $module = "Bio::DB::SoapEUtilities::FetchAdaptor::".$type; | ||
| 181 | my $ok; | ||
| 182 | eval { | ||
| 183 | $ok = $class->_load_module($module); | ||
| 184 | }; | ||
| 185 | for ($@) { | ||
| 186 | /^$/ && do { | ||
| 187 | return $ok; | ||
| 188 | }; | ||
| 189 | /Can't locate/ && do { | ||
| 190 | $class->throw("Fetch adaptor for '$type' not found"); | ||
| 191 | }; | ||
| 192 | do { # else | ||
| 193 | $class->throw("Error in fetch adaptor for '$type' : $@"); | ||
| 194 | }; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | =head2 obj_class() | ||
| 199 | |||
| 200 | Title : obj_class | ||
| 201 | Usage : $adaptor->obj_class | ||
| 202 | Function: Returns the fully qualified BioPerl classname | ||
| 203 | of the objects returned by next_obj() | ||
| 204 | Returns : scalar string (class name) | ||
| 205 | Args : none | ||
| 206 | |||
| 207 | =cut | ||
| 208 | |||
| 209 | sub obj_class { shift->throw_not_implemented } | ||
| 210 | |||
| 211 | =head2 next_obj() | ||
| 212 | |||
| 213 | Title : next_obj | ||
| 214 | Usage : $obj = $adaptor->next_obj | ||
| 215 | Function: Returns the next parsed BioPerl object from the | ||
| 216 | adaptor | ||
| 217 | Returns : object of class obj_class() | ||
| 218 | Args : none | ||
| 219 | |||
| 220 | =cut | ||
| 221 | |||
| 222 | sub next_obj { shift->throw_not_implemented } | ||
| 223 | |||
| 224 | =head2 rewind() | ||
| 225 | |||
| 226 | Title : rewind | ||
| 227 | Usage : | ||
| 228 | Function: Rewind the adaptor's iterator | ||
| 229 | Returns : | ||
| 230 | Args : none | ||
| 231 | |||
| 232 | =cut | ||
| 233 | |||
| 234 | sub rewind { shift->throw_not_implemented } | ||
| 235 | |||
| 236 | =head2 result() | ||
| 237 | |||
| 238 | Title : result | ||
| 239 | Usage : | ||
| 240 | Function: contains the SoapEUtilities::Result object | ||
| 241 | Returns : Bio::DB::SoapEUtilities::Result object | ||
| 242 | Args : none | ||
| 243 | |||
| 244 | =cut | ||
| 245 | |||
| 246 | sub result { shift->{'_result'} } | ||
| 247 | |||
| 248 | =head2 type() | ||
| 249 | |||
| 250 | Title : type | ||
| 251 | Usage : | ||
| 252 | Function: contains the fetch type of this adaptor | ||
| 253 | Returns : | ||
| 254 | Args : | ||
| 255 | |||
| 256 | =cut | ||
| 257 | |||
| 258 | sub type { shift->{'_type'} } | ||
| 259 | 1; |