Bio/TreeIO/lintree.pm

filter: Statementstmt 91.4% 64 / 70 Branchbran 80.0% 24 / 30 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 86.2% 100 / 116 CC 21 SCAR 25.1
CC
21
Cov
87%
next_tree
17.5
nodetype
4.2
_initialize
2.1
CRAP 12.3
« Bio/AlignIO/msf.pm ↑ Summary Bio/Tools/Grail.pm »
1 #
2 # BioPerl module for Bio::TreeIO::lintree
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason-at-bioperl-dot-org>
7 #
8 # Copyright Jason Stajich
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::TreeIO::lintree - Parser for lintree output trees
17  
18 =head1 SYNOPSIS
19  
20 # do not use directly, use through Bio::TreeIO
21 use Bio::TreeIO;
22 my $treeio = Bio::TreeIO->new(-format => 'lintree',
23 -file => 't/data/crab.nj');
24 my $tree = $treeio->next_tree;
25  
26 =head1 DESCRIPTION
27  
28 Parser for the lintree output which looks like this
29  
30 13 sequences 1000 bootstraping
31 1 A-salina
32 2 C-vittat
33 3 C-sp.
34 4 L-aequit
35 5 P-camtsc
36 6 E-tenuim
37 7 L-splend
38 8 P-bernha
39 9 P-acadia
40 10 P-p(NE)
41 11 P-p(GU)
42 12 P-l(NE)
43 13 P-l(GU)
44 14 and 2 0.098857 1000
45 14 and 3 0.127932 1000
46 15 and 1 0.197471 1000
47 15 and 14 0.029273 874
48 16 and 10 0.011732 1000
49 16 and 11 0.004529 1000
50 17 and 12 0.002258 1000
51 17 and 13 0.000428 1000
52 18 and 16 0.017512 1000
53 18 and 17 0.010824 998
54 19 and 4 0.006534 1000
55 19 and 5 0.006992 1000
56 20 and 15 0.070461 1000
57 20 and 18 0.030579 998
58 21 and 8 0.003339 1000
59 21 and 9 0.002042 1000
60 22 and 6 0.011142 1000
61 22 and 21 0.010693 983
62 23 and 20 0.020714 996
63 23 and 19 0.020350 1000
64 24 and 23 0.008665 826
65 24 and 22 0.013457 972
66 24 and 7 0.025598 1000
67  
68 See http://www.bio.psu.edu/People/Faculty/Nei/Lab/software.htm for access
69 to the program and N Takezaki, A Rzhetsky, and M Nei, "Phylogenetic test
70 of the molecular clock and linearized trees." Mol Biol Evol 12(5):823-33.
71  
72 =head1 FEEDBACK
73  
74 =head2 Mailing Lists
75  
76 User feedback is an integral part of the evolution of this and other
77 Bioperl modules. Send your comments and suggestions preferably to
78 the Bioperl mailing list. Your participation is much appreciated.
79  
80 bioperl-l@bioperl.org - General discussion
81 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
82  
83 =head2 Support
84  
85 Please direct usage questions or support issues to the mailing list:
86  
87 I<bioperl-l@bioperl.org>
88  
89 rather than to the module maintainer directly. Many experienced and
90 reponsive experts will be able look at the problem and quickly
91 address it. Please include a thorough description of the problem
92 with code and data examples if at all possible.
93  
94 =head2 Reporting Bugs
95  
96 Report bugs to the Bioperl bug tracking system to help us keep track
97 of the bugs and their resolution. Bug reports can be submitted via the
98 web:
99  
100 https://github.com/bioperl/bioperl-live/issues
101  
102 =head1 AUTHOR - Jason Stajich
103  
104 Email jason-at-bioperl-dot-org
105  
106 =head1 CONTRIBUTORS
107  
108 Ideas and discussion from:
109 Alan Christoffels
110 Avril Coghlan
111  
112 =head1 APPENDIX
113  
114 The rest of the documentation details each of the object methods.
115 Internal methods are usually preceded with a _
116  
117 =cut
118  
119  
120 # Let the code begin...
121  
122  
123 package Bio::TreeIO::lintree;
124 4 $Bio::TreeIO::lintree::VERSION = '1.7.8';
125 4 ▶use vars qw(%Defaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
126 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128  
129 4 ▶use base qw(Bio::TreeIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
130 4 $Defaults{'NodeType'} = "Bio::Tree::Node";
131  
132 =head2 new
133  
134 Title : new
135 Usage : my $obj = Bio::TreeIO::lintree->new();
136 Function: Builds a new Bio::TreeIO::lintree object
137 Returns : an instance of Bio::TreeIO::lintree
138 Args : -nodetype => Node type to create [default Bio::Tree::Node]
139  
140  
141 =cut
142  
143 9 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=7.2
144 9 my ($self,@args) = @_;
145 9 $self->SUPER::_initialize(@args);
146 9 my ($nodetype) = $self->_rearrange([qw(NODETYPE)],@args);
147 9 ▶ $nodetype ||= $Defaults{'NodeType'};
Condition33%1/3
$nodetype ||= $Bio::TreeIO::lintree::Defaults{"NodeType"}
l!l&&r!l&&!r
090
MC/DC0%0/2
$nodetype ||= $Bio::TreeIO::lintree::Defaults{"NodeType"}
$nodetype $Bio::TreeIO::lintree::Defaults{"NodeType"}
Truth table33%1/3
A ||= B
A= $nodetypeB= $Bio::TreeIO::lintree::Defaults{"NodeType"}
ABresult
1X1
011
000
148 9 $self->nodetype($nodetype);
149 }
150  
151 =head2 next_tree
152  
153 Title : next_tree
154 Usage : my $tree = $treeio->next_tree
155 Function: Gets the next tree in the stream
156 Returns : Bio::Tree::TreeI
157 Args : none
158  
159  
160 =cut
161  
162 12 ▶sub next_tree {
Subroutine next_tree: called CC=17 SCAR=28.6
Pod documented
163 12 my ($self) = @_;
164 12 my $seentop = 0;
165 12 my ($tipcount,%data,@nodes) = (0);
166 12 my $nodetype = $self->nodetype;
167  
168 12 ▶ while( defined( $_ = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 375 12 387
169 375 ▶ if( /^\s*(\d+)\s+sequences/ox ) {
Branch: 6 branches
BranchTrueFalseTotal
if (/^\s*(\d+)\s+sequences/ox) { } 9 366 375
elsif (/^(\d+)\s+(\S+)\s*$/ox) { } 117 249 366
elsif (/^\s*(\d+)\s+and\s+(\d+)\s+(\-?\d+\.\d+)(?:\s+(\d+))?/ox) { } 207 42 249
elsif (/\s+(\S+)\-distance was used\./ox) { } 0 42 42
elsif (/\s*seed=(\d+)/ox) { } 6 36 42
elsif (/^outgroup:\s+(\d+)\s+(\S+)/ox) { } 3 33 36
170 9 ▶ if( $seentop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seentop) 0 9 9
171 0 $self->_pushback($_);
172 0 last;
173 }
174 9 $tipcount = $1;
175 9 $seentop = 1;
176 } elsif( /^(\d+)\s+(\S+)\s*$/ox ) {
177 # deal with setting an outgroup
178 117 ▶ unless( defined $data{'outgroup'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data{"outgroup"}) 9 108 117
179 9 $data{'outgroup'} = [$1,$2];
180 }
181 117 $nodes[$1 - 1] = { '-id' => $2 };
182 } elsif( m/^\s*(\d+)\s+and\s+(\d+)\s+(\-?\d+\.\d+)(?:\s+(\d+))?/ox ) {
183 207 my ($node,$descend,$blength,$bootstrap) = ( $1, $2, $3, $4 );
184 # need to -- descend and node because
185 # array is 0 based
186 207 $node--;$descend--;
187 207 $nodes[$descend]->{'-branch_length'} = $blength;
188 207 $nodes[$descend]->{'-bootstrap'} = $bootstrap; #? here
189 207 $nodes[$node]->{'-id'} = $node+1;
190 207 push @{$nodes[$node]->{'-d'}}, $descend;
191
192 } elsif( /\s+(\S+)\-distance was used\./ox ) {
193 0 $data{'method'} = $1;
194 } elsif( /\s*seed=(\d+)/ox ) {
195 6 $data{'seed'} = $1;
196 } elsif( m/^outgroup:\s+(\d+)\s+(\S+)/ox ) {
197 3 $data{'outgroup'} = [$1,$2];
198 }
199 }
200 12 ▶ if( @nodes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@nodes) 9 3 12
201 9 my @treenodes;
202 9 foreach my $n ( @nodes ) {
203 216 push @treenodes, $nodetype->new(%{$n});
204 }
205
206 9 foreach my $tn ( @treenodes ) {
207 216 my $n = shift @nodes;
208 216 ▶ for my $ptr ( @{ $n->{'-d'} || [] } ) {
Condition100%2/2
$n->{'-d'} || []
l!l
99117
MC/DC100%1/1
$n->{'-d'} || []
$n->{'-d'}
Truth table100%2/2
A
A= $n->{'-d'}
Aresult
11
00
209 207 $tn->add_Descendent($treenodes[$ptr]);
210 }
211 }
212 9 my $T = Bio::Tree::Tree->new(-root => (pop @treenodes) );
213 9 ▶ if( $data{'outgroup'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{"outgroup"}) 9 0 9
214 9 my ($outgroup) = $treenodes[$data{'outgroup'}->[0]];
215 9 ▶ if( ! defined $outgroup) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $outgroup) { } 0 9 9
216 0 $self->warn("cannot find '". $data{'outgroup'}->[1]. "'\n");
217 } else {
218 9 $T->reroot($outgroup->ancestor);
219 }
220 }
221 9 return $T;
222 }
223 3 return; # if there are no more trees, return undef
224
225 }
226  
227 =head2 nodetype
228  
229 Title : nodetype
230 Usage : $obj->nodetype($newval)
231 Function:
232 Example :
233 Returns : value of nodetype (a scalar)
234 Args : on set, new value (a scalar or undef, optional)
235  
236  
237 =cut
238  
239 21 ▶sub nodetype{
Subroutine nodetype: called CC=4 SCAR=14.5
Pod documented
240 21 my ($self,$value) = @_;
241 21 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 9 12 21
242 9 eval "require $value";
243 0 ▶ if( $@ ) { $self->throw("$@: Unrecognized Node type for ".ref($self).
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 9 9
244 "'$value'");}
245
246 9 my $a = bless {},$value;
247 9 ▶ unless( $a->isa('Bio::Tree::NodeI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($a->isa("Bio::Tree::NodeI")) 0 9 9
248 0 $self->throw("Must provide a valid Bio::Tree::NodeI or child class to SeqFactory Not $value");
249 }
250 9 $self->{'nodetype'} = $value;
251 }
252 21 return $self->{'nodetype'};
253 }
254  
255 4 1;
« Bio/AlignIO/msf.pm ↑ Summary Bio/Tools/Grail.pm »