blib/lib/Bio/DB/SoapEUtilities/FetchAdaptor/species.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 11 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 105 CC 10 SCAR 35.0
CC
10
Cov
0%
_read_species
72.0
next_obj
12.0
_initialize
2.0
CRAP 33.1
1 # $Id$
2 #
3 # BioPerl module for Bio::DB::SoapEUtilities::FetchAdaptor::species
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::species - Fetch adaptor for
18 'taxonomy' efetch SOAP messages
19  
20 =head1 SYNOPSIS
21  
22 Imported by L<Bio::DB::SoapEUtilities::FetchAdaptor> as required.
23  
24 =head1 DESCRIPTION
25  
26 Returns an iterator over L<Bio::Species> objects:
27  
28 my $fac = Bio::DB::SoapEUtilities->new;
29 my $taxio = $fac->efetch(-db => 'taxonomy', -id => 1394)->run(-auto_adapt=>1);
30 my $sp = $taxio->next_species;
31 $sp->binomial; # returns 'Bacillus caldolyticus'
32  
33 To find out the object type returned:
34
35 $class = $seqio->obj_class; # $class is 'Bio::Species'
36  
37 as for all L<Bio::DB::SoapEUtilities::FetchAdaptor> objects.
38  
39 =head1 SEE ALSO
40  
41 L<Bio::DB::SoapEUtilities>, L<Bio::DB::SoapEUtilities::FetchAdaptor>
42  
43 =head1 FEEDBACK
44  
45 =head2 Mailing Lists
46  
47 User feedback is an integral part of the evolution of this and other
48 Bioperl modules. Send your comments and suggestions preferably to
49 the Bioperl mailing list. Your participation is much appreciated.
50  
51 bioperl-l@bioperl.org - General discussion
52 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
53  
54 =head2 Support
55  
56 Please direct usage questions or support issues to the mailing list:
57  
58 L<bioperl-l@bioperl.org>
59  
60 rather than to the module maintainer directly. Many experienced and
61 reponsive experts will be able look at the problem and quickly
62 address it. Please include a thorough description of the problem
63 with code and data examples if at all possible.
64  
65 =head2 Reporting Bugs
66  
67 Report bugs to the Bioperl bug tracking system to help us keep track
68 of the bugs and their resolution. Bug reports can be submitted via
69 the web:
70  
71 http://redmine.open-bio.org/projects/bioperl/
72  
73 =head1 AUTHOR - Mark A. Jensen
74  
75 Email maj -at- fortinbras -dot- us
76  
77 =head1 APPENDIX
78  
79 The rest of the documentation details each of the object methods.
80 Internal methods are usually preceded with a _
81  
82 =cut
83  
84 # Let the code begin...
85  
86  
87 package Bio::DB::SoapEUtilities::FetchAdaptor::species;
88 use strict;
89  
90 # Object preamble - inherits from Bio::Root::Root
91  
92 use Bio::Root::Root;
93 use Bio::Species;
94  
95 use base qw(Bio::DB::SoapEUtilities::FetchAdaptor Bio::Root::Root );
96  
97 sub _initialize {
98 my ($self, @args) = @_;
99 $self->SUPER::_initialize(@args);
100 # my ($builder, $seqfac ) = $self->_rearrange( [qw(SEQBUILDER
101 # SEQFACTORY)], @args );
102 $self->{'_obj_class'} = 'Bio::Species' ;
103 $self->{'_idx'} = 1;
104 1;
105 }
106  
107 sub rewind { shift->{'_idx'} = 1 }
108  
109 sub obj_class { shift->{'_obj_class'} }
110  
111 sub next_species { shift->next_obj }
112  
113 sub next_obj {
114 my $self = shift;
115 my $stem = "//TaxaSet/[".$self->{'_idx'}."]";
116 # my $stem = "//Body/".$self->result->result_type."/[".$self->{'_idx'}."]";
117 my $som = $self->result->som;
118  
119 return unless defined $som->valueof($stem);
120 my $get = sub { $som->valueof("$stem/".shift) };
121 my $toplev = $som->valueof("$stem");
122 my $get_tl = sub { $toplev->{ shift @_ } };
123 my $sp = _read_species($get_tl);
124 $self->warn("FetchAdaptor::species - parse error, no Bio::Species returned") unless $sp;
125 ($self->{_idx})++;
126 return $sp;
127 }
128 1;
129  
130 # mostly ripped from Bio::SeqIO::genbank...
131  
132 sub _read_species {
133 my ($get) = @_;
134
135 my @unkn_names = ('other', 'unknown organism', 'not specified', 'not shown',
136 'Unspecified', 'Unknown', 'None', 'unclassified',
137 'unidentified organism', 'not supplied');
138 # dictionary of synonyms for taxid 32644
139 my @unkn_genus = ('unknown','unclassified','uncultured','unidentified');
140 # all above can be part of valid species name
141  
142 my( $sub_species, $species, $genus, $sci_name, $common,
143 $abbr_name, $organelle);
144  
145 $sci_name = $get->('ScientificName') || return;
146  
147 # no "source" elt like gb format./maj
148  
149 # parse out organelle, common name, abbreviated name if present;
150 # this should catch everything, but falls back to
151 # entire GBSeq_taxonomy element just in case
152 # if ($get->('source') =~ m{^
153 # (mitochondrion|chloroplast|plastid)?
154 # \s*(.*?)
155 # \s*(?: \( (.*?) \) )?\.?
156 # $}xms ) {
157 # ($organelle, $abbr_name, $common) = ($1, $2, $3); # optional
158 # } else {
159 # $abbr_name = $get->('source'); # nothing caught; this is a backup!
160 # }
161  
162 # # Convert data in classification lines into classification array.
163 my @class = split(/; /, $get->('Lineage'));
164  
165 # do we have a genus?
166 my $possible_genus = quotemeta($class[-1])
167 . ($class[-2] ? "|" . quotemeta($class[-2]) : '');
168 if ($sci_name =~ /^($possible_genus)/) {
169 $genus = $1;
170 ($species) = $sci_name =~ /^$genus\s+(.+)/;
171 }
172 else {
173 $species = $sci_name;
174 }
175  
176 # is this organism of rank species or is it lower?
177 # (we don't catch everything lower than species, but it doesn't matter -
178 # this is just so we abide by previous behaviour whilst not calling a
179 # species a subspecies)
180 if ($species && $species =~ /subsp\.|var\./) {
181 ($species, $sub_species) = $species =~ /(.+)\s+((?:subsp\.|var\.).+)/;
182 }
183  
184 # Don't make a species object if it's empty or "Unknown" or "None"
185 # return unless $genus and $genus !~ /^(Unknown|None)$/oi;
186 # Don't make a species object if it belongs to taxid 32644
187 my $src = $get->('ScientificName');
188 return unless ($species || $genus) and
189 !grep { $_ eq $src } @unkn_names;
190  
191 # Bio::Species array needs array in Species -> Kingdom direction
192 push(@class, $sci_name);
193 @class = reverse @class;
194  
195 my $make = Bio::Species->new();
196 $make->scientific_name($sci_name);
197 $make->classification(@class) if @class > 0;
198 $make->common_name( $get->('CommonName'));
199 $make->name('abbreviated', $abbr_name) if $abbr_name;
200 $make->organelle($organelle) if $organelle;
201 $make->ncbi_taxid( $get->('TaxId') );
202 $make->division( $get->('Division') );
203 return $make;
204 }
205  
206 1;