line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::LITE::Taxonomy::RDP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Bio::LITE::Taxonomy::RDP - Lightweight and efficient RDP taxonomic manager |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Bio::LITE::Taxonomy::RDP; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $taxRDP = Bio::LITE::Taxonomy::RDP->new ( |
12
|
|
|
|
|
|
|
bergeyXML => "/path/to/BergeyTrainingTree.xml", |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @tax = $taxRDP->get_taxonomy (22075); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $level = $taxRDP->get_level_from_name("Bacillaceae 1"); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This module provides easy and efficient access to the RDP taxonomy with minimal dependencies and without intermediary databases. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This module is not part of the Bioperl bundle. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SEE ALSO |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
L |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
L |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 AUTHOR |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Miguel Pignatelli |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Any comments or suggestions should be addressed to emepyc@gmail.com |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 LICENSE |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Copyright 2009 Miguel Pignatelli, all rights reserved. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
23916
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
48
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
49
|
1
|
|
|
1
|
|
5
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
54
|
|
50
|
1
|
|
|
1
|
|
417
|
use XML::Simple qw(:strict); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
use Bio::LITE::Taxonomy; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
#if (do {(sprintf "%vd",$^V) =~ /5\.(\d\d)/; $1} >= 10}) { |
55
|
|
|
|
|
|
|
# import base qw(Taxonomy); |
56
|
|
|
|
|
|
|
#} else { |
57
|
|
|
|
|
|
|
# import parent qw(Taxonomy); |
58
|
|
|
|
|
|
|
#} |
59
|
|
|
|
|
|
|
use base qw(Bio::LITE::Taxonomy); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
our $VERSION = 0.03; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub new |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
my ($class,%args) = @_; |
66
|
|
|
|
|
|
|
my %opts; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
defined $args{'bergeyXML'} or croak "Need the file bergeyTrainingTree.xml"; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$opts{bergeyXML} = $args{bergeyXML}; |
71
|
|
|
|
|
|
|
my $self = bless \%opts, $class; |
72
|
|
|
|
|
|
|
$self->_build_taxonomy(); |
73
|
|
|
|
|
|
|
return $self; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _build_taxonomy |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
my $bergeysXML = $self->{bergeyXML}; |
80
|
|
|
|
|
|
|
my $xmlfh; |
81
|
|
|
|
|
|
|
if ((UNIVERSAL::isa($bergeysXML, 'GLOB')) or (ref \$bergeysXML eq 'GLOB')) { |
82
|
|
|
|
|
|
|
$xmlfh = $bergeysXML; # Note: Check permissions |
83
|
|
|
|
|
|
|
} else { |
84
|
|
|
|
|
|
|
open $xmlfh, "<", $bergeysXML or croak $!; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
my @bergeysxml = <$xmlfh>; |
87
|
|
|
|
|
|
|
my $bergeysTree = XMLin( |
88
|
|
|
|
|
|
|
(shift @bergeysxml && join "", ("",@bergeysxml,"")), # bergeysXML is not a comformant XML file |
89
|
|
|
|
|
|
|
ForceArray => 0, |
90
|
|
|
|
|
|
|
KeyAttr => ["taxid"] |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->_parse_tree($bergeysTree); |
94
|
|
|
|
|
|
|
close($xmlfh) unless ((UNIVERSAL::isa($bergeysXML, 'GLOB')) or (ref \$bergeysXML eq 'GLOB')); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _parse_tree |
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
my ($self, $bergeysTree) = @_; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my %names; |
103
|
|
|
|
|
|
|
my %allowed_levels; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
for my $taxid (keys %{$bergeysTree->{TreeNode}}) { |
106
|
|
|
|
|
|
|
$bergeysTree->{TreeNode}->{$taxid}->{parent} = $bergeysTree->{TreeNode}->{$taxid}->{parentTaxid}; |
107
|
|
|
|
|
|
|
$bergeysTree->{TreeNode}->{$taxid}->{level} = $bergeysTree->{TreeNode}->{$taxid}->{rank}; |
108
|
|
|
|
|
|
|
delete @{$bergeysTree->{TreeNode}->{$taxid}}{qw/parentTaxid rank leaveCount genusIndex/}; |
109
|
|
|
|
|
|
|
$bergeysTree->{TreeNode}->{$taxid}->{name} =~ s/"//g; |
110
|
|
|
|
|
|
|
$bergeysTree->{TreeNode}->{$taxid}->{name} = "root" if ($bergeysTree->{TreeNode}->{$taxid}->{name} eq "Root"); |
111
|
|
|
|
|
|
|
$names{$bergeysTree->{TreeNode}->{$taxid}->{name}} = $taxid; |
112
|
|
|
|
|
|
|
$allowed_levels{$bergeysTree->{TreeNode}->{$taxid}->{level}} = 1; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
$self->{nodes} = $bergeysTree->{TreeNode}; |
115
|
|
|
|
|
|
|
$self->{names} = { %names }; |
116
|
|
|
|
|
|
|
$self->{allowed_levels} = { %allowed_levels }; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |