Bio/DB/Taxonomy/silva.pm

filter: Statementstmt 100% 34 / 34 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 96.1% 50 / 52 CC 7 SCAR 13.7
CC
7
Cov
96%
_build_taxonomy
6.0
new
2.0
BEGIN
1.0
CRAP 3.9
« Bio/Search/HSP/PSLHSP.pm ↑ Summary Bio/SeqFeature/Gene/Exon.pm »
1 #
2 # BioPerl module for Bio::DB::Taxonomy::silva
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Copyright Florent Angly
7 #
8 # You may distribute this module under the same terms as perl itself
9  
10  
11 =head1 NAME
12  
13 Bio::DB::Taxonomy::silva - Use the Silva taxonomy
14  
15 =head1 SYNOPSIS
16  
17 use Bio::DB::Taxonomy;
18  
19 my $db = Bio::DB::Taxonomy->new(
20 -source => 'silva',
21 -taxofile => 'SSURef_108_tax_silva_trunc.fasta',
22 );
23  
24 =head1 DESCRIPTION
25  
26 This is an implementation of Bio::DB::Taxonomy which stores and accesses the
27 Silva taxonomy. Internally, Bio::DB::Taxonomy::silva keeps the taxonomy
28 into memory by using Bio::DB::Taxonomy::list. As a consequence, note that the
29 IDs assigned to the taxonomy nodes, e.g. sv72, are arbitrary, contrary to the
30 pre-defined IDs that NCBI assigns to taxons. Note also that no rank names or
31 common names are assigned to the taxa of Bio::DB::Taxonomy::silva.
32  
33 The latest Silva taxonomy (2011) contains about 126,000 taxa and occupies
34 about 124 MB of memory once parsed into a Bio::DB::Taxonomy::silva object.
35 Obviously, it can take a little while to load.
36  
37 The taxonomy file SSURef_108_tax_silva_trunc.fasta that this module uses is
38 available from L<http://www.arb-silva.de/no_cache/download/archive/release_108/Exports/>.
39  
40 =head1 FEEDBACK
41  
42 =head2 Mailing Lists
43  
44 User feedback is an integral part of the evolution of this and other
45 Bioperl modules. Send your comments and suggestions preferably to
46 the Bioperl mailing list. Your participation is much appreciated.
47  
48 bioperl-l@bioperl.org - General discussion
49 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
50  
51 =head2 Support
52  
53 Please direct usage questions or support issues to the mailing list:
54  
55 I<bioperl-l@bioperl.org>
56  
57 rather than to the module maintainer directly. Many experienced and
58 reponsive experts will be able look at the problem and quickly
59 address it. Please include a thorough description of the problem
60 with code and data examples if at all possible.
61  
62 =head2 Reporting Bugs
63  
64 Report bugs to the Bioperl bug tracking system to help us keep track
65 of the bugs and their resolution. Bug reports can be submitted via
66 the web:
67  
68 https://github.com/bioperl/bioperl-live/issues
69  
70 =head1 AUTHOR - Florent Angly
71  
72 florent.angly@gmail.com
73  
74 =head1 APPENDIX
75  
76 The rest of the documentation details each of the object methods.
77 Internal methods are usually preceded with a _
78  
79 =cut
80  
81  
82 package Bio::DB::Taxonomy::silva;
83 2 $Bio::DB::Taxonomy::silva::VERSION = '1.7.8';
84 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 2 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 2 ▶use base qw(Bio::DB::Taxonomy Bio::DB::Taxonomy::list);
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 2 $Bio::DB::Taxonomy::list::prefix = 'sv';
90  
91  
92 =head2 new
93  
94 Title : new
95 Usage : my $obj = Bio::DB::Taxonomy::silva->new();
96 Function: Builds a new Bio::DB::Taxonomy::silva object
97 Returns : an instance of Bio::DB::Taxonomy::silva
98 Args : -taxofile => name of the FASTA file containing the taxonomic information,
99 typically 'SSURef_108_tax_silva_trunc.fasta' (mandatory)
100  
101 =cut
102  
103 2 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
104 # Override Bio::DB::Taxonomy
105 2 my($class, @args) = @_;
106 2 my $self = $class->SUPER::new(@args);
107 2 my ($taxofile) = $self->_rearrange([qw(TAXOFILE)], @args);
108
109 2 ▶ if ( $taxofile ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($taxofile) 1 1 2
110 1 $self = $self->_build_taxonomy($taxofile);
111 }
112  
113 2 return $self;
114 }
115  
116  
117 1 ▶sub _build_taxonomy {
Subroutine _build_taxonomy: called CC=6 SCAR=17.9
118 1 my ($self, $taxofile) = @_;
119  
120 1 my $taxonomy = Bio::DB::Taxonomy::list->new();
121 1 my %taxas;
122 1 my $desc_re = qr/^>\S+?(?:\s+(.+))?$/;
123  
124 # One could open the file using Bio::SeqIO::fasta, but it is slower and we
125 # only need the sequence descriptions
126  
127 1 ▶ open my $in, '<', $taxofile or $self->throw("Could not read file '$taxofile': $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $taxofile or $self->throw("Could not read file '${taxofile}': $!") 1 0 1
128  
129 # Populate taxonomy with taxonomy obtained from sequence description
130 1 ▶ while (my $line = <$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in)) 162 1 163
131  
132 162 ▶ next if $line !~ $desc_re;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /$desc_re/ 105 57 162
133 57 my $taxo_string = $1;
134 57 ▶ next if not $taxo_string;
Branch: 1 branch
BranchTrueFalseTotal
unless $taxo_string 0 57 57
135  
136 # Example of taxonomy string:
137 # 1/ Bacteria;Firmicutes;Bacilli;Lactobacillales;Enterococcaceae;Enterococcus;Enterococcus faecium DO
138 # 2/ Eukaryota;Metazoa;Chordata;Craniata;Vertebrata;Euteleostomi;Mammalia;Eutheria;Euarchontoglires;Glires;
139 # Rodentia;Sciurognathi;Muroidea;Muridae;Murinae;Rattus;;Rattus norvegicus (Norway rat)
140
141 # Skip already seen taxas
142 57 ▶ next if exists $taxas{$taxo_string};
Branch: 1 branch
BranchTrueFalseTotal
if exists $taxas{$taxo_string} 15 42 57
143 42 $taxas{$taxo_string} = undef;
144  
145 # Strip the common name (could save it if Bio::DB::Taxonomy::list supported it)
146 42 $taxo_string =~ s/ \(.*\)$//;
147  
148 # Save lineage
149 # Unfortunately, we cannot easily add ranks since they vary from 2 to 23 for every entry
150 42 my @names = split /;/, $taxo_string;
151 42 $taxonomy->add_lineage(
152 -names => \@names,
153 );
154  
155 }
156  
157 1 close $in;
158  
159 1 return $taxonomy;
160 }
161  
162  
163 2 1;
« Bio/Search/HSP/PSLHSP.pm ↑ Summary Bio/SeqFeature/Gene/Exon.pm »