Bio/Matrix/IO/phylip.pm

filter: Statementstmt 57.3% 43 / 75 Branchbran 50.0% 8 / 16 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 56.7% 63 / 111 CC 16 SCAR 28.5
CC
16
Cov
56%
write_matrix
42.0
next_matrix
11.9
new
2.1
CRAP 17.2
« Bio/SeqIO/locuslink.pm ↑ Summary Bio/Search/HSP/GenericHSP.pm »
1 #
2 # BioPerl module for Bio::Matrix::IO::phylip
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::Matrix::IO::phylip - A parser for PHYLIP distance matricies
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Matrix::IO;
21 my $parser = Bio::Matrix::IO->new(-format => 'phylip',
22 -file => 't/data/phylipdist.out');
23 my $matrix = $parser->next_matrix;
24  
25 =head1 DESCRIPTION
26  
27 This is a parser for PHYLIP distance matrix output.
28  
29 =head1 FEEDBACK
30  
31 =head2 Mailing Lists
32  
33 User feedback is an integral part of the evolution of this and other
34 Bioperl modules. Send your comments and suggestions preferably to
35 the Bioperl mailing list. Your participation is much appreciated.
36  
37 bioperl-l@bioperl.org - General discussion
38 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
39  
40 =head2 Support
41  
42 Please direct usage questions or support issues to the mailing list:
43  
44 I<bioperl-l@bioperl.org>
45  
46 rather than to the module maintainer directly. Many experienced and
47 reponsive experts will be able look at the problem and quickly
48 address it. Please include a thorough description of the problem
49 with code and data examples if at all possible.
50  
51 =head2 Reporting Bugs
52  
53 Report bugs to the Bioperl bug tracking system to help us keep track
54 of the bugs and their resolution. Bug reports can be submitted via
55 the web:
56  
57 https://github.com/bioperl/bioperl-live/issues
58  
59 =head1 AUTHOR - Jason Stajich
60  
61 Email jason-at-bioperl-dot.org
62  
63 =head1 APPENDIX
64  
65 The rest of the documentation details each of the object methods.
66 Internal methods are usually preceded with a _
67  
68 =cut
69  
70  
71 # Let the code begin...
72  
73  
74 package Bio::Matrix::IO::phylip;
75 2 $Bio::Matrix::IO::phylip::VERSION = '1.7.8';
76 2 ▶use vars qw($DEFAULTPROGRAM);
Subroutine BEGIN: called CC=1 SCAR=0.0
77 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 2 $DEFAULTPROGRAM = 'phylipdist';
80  
81 2 ▶use Bio::Matrix::PhylipDist;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 2 ▶use base qw(Bio::Matrix::IO);
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 =head2 new
86  
87 Title : new
88 Usage : my $obj = Bio::Matrix::IO::phylip->new();
89 Function: Builds a new Bio::Matrix::IO::phylip object
90 Returns : an instance of Bio::Matrix::IO::phylip
91 Args :
92  
93  
94 =cut
95  
96 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
97 1 my($class,@args) = @_;
98  
99 1 my $self = $class->SUPER::new(@args);
100 1 my ($prog) = $self->_rearrange([qw(PROGRAM)], @args);
101 1 ▶ $self->{'_program'} = $prog || $DEFAULTPROGRAM;
Condition33%1/3
$prog || $Bio::Matrix::IO::phylip::DEFAULTPROGRAM
l!l&&r!l&&!r
100
MC/DC0%0/2
$prog || $Bio::Matrix::IO::phylip::DEFAULTPROGRAM
$prog $Bio::Matrix::IO::phylip::DEFAULTPROGRAM
Truth table33%1/3
A || B
A= $progB= $Bio::Matrix::IO::phylip::DEFAULTPROGRAM
ABresult
1X1
011
000
102 1 return $self;
103 }
104  
105  
106 =head2 next_matrix
107  
108 Title : next_matrix
109 Usage : my $matrix = $parser->next_matrix
110 Function: Get the next result set from parser data
111 Returns : L<Bio::Matrix::PhylipDist>
112 Args : none
113  
114  
115 =cut
116  
117 1 ▶sub next_matrix {
Subroutine next_matrix: called CC=10 SCAR=24.8
Pod documented
118 1 my ($self) = @_;
119 1 my @names;
120 my @values;
121 1 my $entry;
122 1 my $size = 0;
123 1 ▶ while ($entry=$self->_readline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry = $self->_readline) 6 1 7
124 6 ▶ if($#names >=0 && $entry =~/^\s+\d+\n$/){
Branch: 3 branches
BranchTrueFalseTotal
if ($#names >= 0 and $entry =~ /^\s+\d+\n$/) { } 0 6 6
elsif ($entry =~ /^\s+(\d+)\n$/) { } 1 5 6
elsif ($entry =~ s/^\s+(\-?\d+\.\d+)/$1/) { } 0 5 5
Condition66%2/3
$#names >= 0 and $entry =~ /^\s+\d+\n$/
!ll&&!rl&&r
240
MC/DC0%0/2
$#names >= 0 and $entry =~ /^\s+\d+\n$/
$#names >= 0 $entry =~ /^\s+\d+\n$/
Truth table66%2/3
A and B
A= $#names >= 0B= $entry =~ /^\s+\d+\n$/
ABresult
0X0
100
111
125 0 $self->_pushback($entry);
126 0 last;
127 } elsif($entry=~/^\s+(\d+)\n$/){
128 1 $size = $1;
129 1 next;
130 } elsif( $entry =~ s/^\s+(\-?\d+\.\d+)/$1/ ) {
131 0 my (@line) = split( /\s+/,$entry);
132 0 push @{$values[-1]}, @line;
133 0 next;
134 }
135 5 my ($n,@line) = split( /\s+/,$entry);
136
137 5 push @names, $n;
138 5 push @values, [@line];
139 }
140 1 ▶ if( scalar @names != $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @names != $size) 0 1 1
141 0 $self->warn("The number of entries ".(scalar @names).
142 " is not the same $size");
143 }
144 1 ▶ $#names>=0 || return;
Branch: 1 branch
BranchTrueFalseTotal
$#names >= 0 or return 1 0 1
145 1 my %dist;
146 1 my $i=0;
147 1 foreach my $name(@names){
148 5 my $j=0;
149 5 foreach my $n(@names) {
150 25 $dist{$name}{$n} = [$i,$j];
151 25 $j++;
152 }
153 5 $i++;
154 }
155 my $matrix = Bio::Matrix::PhylipDist->new
156 1 (-matrix_name => $self->{'_program'},
157 -matrix => \%dist,
158 -names => \@names,
159 -values => \@values);
160 1 return $matrix;
161 }
162  
163 =head2 write_matrix
164  
165 Title : write_matrix
166 Usage : $matio->write_matrix($matrix)
167 Function: Write out a matrix in the phylip distance format
168 Returns : none
169 Args : L<Bio::Matrix::PhylipDist>
170  
171  
172 =cut
173  
174 0 ▶sub write_matrix {
Subroutine write_matrix: not called CC=6 SCAR=37.4
Pod documented
175 0 my ($self,@matricies) = @_;
176 0 foreach my $matrix ( @matricies ) {
177 0 my @names = @{$matrix->names};
178 0 my @values = @{$matrix->_values};
179 0 my %matrix = %{$matrix->_matrix};
180 0 my $str;
181 0 $str.= (" "x 4). scalar(@names)."\n";
182 0 foreach my $name (@names){
183 0 my $newname = $name. (" " x (15-length($name)));
184 0 ▶ if( length($name) >= 15 ) { $newname .= " " }
Branch: 1 branch
BranchTrueFalseTotal
if (length $name >= 15) 0 0 0
185 0 $str.=$newname;
186 0 my $count = 0;
187 0 foreach my $n (@names){
188 0 my ($i,$j) = @{$matrix{$name}{$n}};
189 0 ▶ if($count < $#names){
Branch: 1 branch
BranchTrueFalseTotal
if ($count < $#names) { } 0 0 0
190 0 $str.= $values[$i][$j]. " ";
191 }
192 else {
193 0 $str.= $values[$i][$j];
194 }
195 0 $count++;
196 }
197 0 $str.="\n";
198 }
199 0 $self->_print($str);
200 }
201 }
202  
203  
204 2 1;
« Bio/SeqIO/locuslink.pm ↑ Summary Bio/Search/HSP/GenericHSP.pm »