Bio/Matrix/IO.pm

filter: Statementstmt 55.1% 32 / 58 Branchbran 22.2% 4 / 18 Conditioncond 18.7% 3 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 42.8% 6 / 14 Podpod 100% 5 / 5 totaltotal 41.6% 50 / 120 CC 16 SCAR 22.0
CC
16
Cov
42%
_guess_format
20.0
READLINE
20.0
new
8.6
CRAP 9.0
« Bio/AlignIO/largemultifasta.pm ↑ Summary Bio/Location/Simple.pm »
1 #
2 # BioPerl module for Bio::Matrix::IO
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 - A factory for Matrix parsing
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Matrix::IO;
21 my $parser = Bio::Matrix::IO->new(-format => 'scoring',
22 -file => 'BLOSUMN50');
23  
24 my $matrix = $parser->next_matrix;
25  
26 =head1 DESCRIPTION
27  
28 This is a general factory framework for writing parsers for Matricies.
29 This includes parsing output from distance output like PHYLIP's
30 ProtDist. Additionally it should be possible to fit parsers for PWM
31 and PSSMs once their Matrix objects are written.
32  
33 =head1 FEEDBACK
34  
35 =head2 Mailing Lists
36  
37 User feedback is an integral part of the evolution of this and other
38 Bioperl modules. Send your comments and suggestions preferably to
39 the Bioperl mailing list. Your participation is much appreciated.
40  
41 bioperl-l@bioperl.org - General discussion
42 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
43  
44 =head2 Support
45  
46 Please direct usage questions or support issues to the mailing list:
47  
48 I<bioperl-l@bioperl.org>
49  
50 rather than to the module maintainer directly. Many experienced and
51 reponsive experts will be able look at the problem and quickly
52 address it. Please include a thorough description of the problem
53 with code and data examples if at all possible.
54  
55 =head2 Reporting Bugs
56  
57 Report bugs to the Bioperl bug tracking system to help us keep track
58 of the bugs and their resolution. Bug reports can be submitted via
59 the web:
60  
61 https://github.com/bioperl/bioperl-live/issues
62  
63 =head1 AUTHOR - Jason Stajich
64  
65 Email jason-at-bioperl-dot-org
66  
67 =head1 APPENDIX
68  
69 The rest of the documentation details each of the object methods.
70 Internal methods are usually preceded with a _
71  
72 =cut
73  
74  
75 # Let the code begin...
76  
77  
78 package Bio::Matrix::IO;
79 5 $Bio::Matrix::IO::VERSION = '1.7.8';
80 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82  
83 5 ▶use base qw(Bio::Root::IO);
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 =head2 new
86  
87 Title : new
88 Usage : my $obj = Bio::Matrix::IO->new();
89 Function: Builds a new Bio::Matrix::IO object
90 Returns : an instance of Bio::Matrix::IO
91 Args :
92  
93  
94 =cut
95  
96 12 ▶sub new {
Subroutine new: called CC=7 SCAR=21.5
Pod documented
97 12 my($caller,@args) = @_;
98 12 ▶ my $class = ref($caller) || $caller;
Condition33%1/3
ref $caller || $caller
l!l&&r!l&&!r
0120
MC/DC0%0/2
ref $caller || $caller
ref $caller $caller
Truth table33%1/3
A || B
A= ref $callerB= $caller
ABresult
1X1
011
000
99
100 # or do we want to call SUPER on an object if $caller is an
101 # object?
102 12 ▶ if( $class =~ /Bio::Matrix::IO::(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /Bio::Matrix::IO::(\S+)/) { } 6 6 12
103 6 my ($self) = $class->SUPER::new(@args);
104 6 $self->_initialize(@args);
105 6 return $self;
106 } else {
107  
108 6 my %param = @args;
109 6 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
110 my $format = $param{'-format'} ||
111 6 ▶ $class->_guess_format( $param{'-file'} || $ARGV[0] ) ||
Condition25%2/8
$param{'-format'} || $class->_guess_format($param{'-file'} || $ARGV[0]) || 'scoring'
l!l
60
$param{"-format"} or $class->_guess_format($param{"-file"} || $ARGV[0])
l!l&&r!l&&!r
600
$param{'-file'} || $ARGV[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$param{'-format'} || $class->_guess_format($param{'-file'} || $ARGV[0]) || 'scoring'
$param{"-format"} $class->_guess_format($param{"-file"} || $ARGV[0])
MC/DC0%0/2
$param{'-file'} || $ARGV[0]
$param{'-file'} $ARGV[0]
Truth table33%1/3
A or B
A= $param{"-format"}B= $class->_guess_format($param{"-file"} || $ARGV[0])
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $param{'-file'}B= $ARGV[0]
ABresult
1X1
011
000
112 'scoring';
113 6 $format = "\L$format"; # normalize capitalization to lower case
114  
115 # normalize capitalization
116 6 ▶ return unless( $class->_load_format_module($format) );
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_load_format_module($format) 0 6 6
117 6 return "Bio::Matrix::IO::$format"->new(@args);
118 }
119 }
120  
121 =head2 newFh
122  
123 Title : newFh
124 Usage : $fh = Bio::Matrix::IO->newFh(-file=>$filename,-format=>'Format')
125 Function: does a new() followed by an fh()
126 Example : $fh = Bio::Matrix::IO->newFh(-file=>$filename,-format=>'Format')
127 $matrix = <$fh>; # read a matrix object
128 print $fh $matrix; # write a matrix object
129 Returns : filehandle tied to the Bio::SeqIO::Fh class
130 Args :
131  
132 =cut
133  
134 0 ▶sub newFh {
Subroutine newFh: not called CC=2 SCAR=17.9
Pod documented
135 0 my $class = shift;
136 0 ▶ return unless my $self = $class->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless my $self = $class->new(@_) 0 0 0
137 0 return $self->fh;
138 }
139  
140 =head2 fh
141  
142 Title : fh
143 Usage : $obj->fh
144 Function: Get a filehandle type access to the matrix parser
145 Example : $fh = $obj->fh; # make a tied filehandle
146 $matrix = <$fh>; # read a matrix object
147 print $fh $matrix; # write a matrix object
148 Returns : filehandle tied to Bio::Matrix::IO class
149 Args : none
150  
151 =cut
152  
153  
154 0 ▶sub fh {
Subroutine fh: not called CC=2 SCAR=17.9
Pod documented
155 0 my $self = shift;
156 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
157 0 my $s = Symbol::gensym;
158 0 tie $$s,$class,$self;
159 0 return $s;
160 }
161  
162  
163 =head2 format
164  
165 Title : format
166 Usage : $format = $obj->format()
167 Function: Get the matrix format
168 Returns : matrix format
169 Args : none
170  
171 =cut
172  
173 # format() method inherited from Bio::Root::IO
174  
175  
176 =head2 next_matrix
177  
178 Title : next_matrix
179 Usage : my $matrix = $matixio->next_matrix;
180 Function: Parse the next matrix from the data stream
181 Returns : L<Bio::Matrix::MatrixI> type object or undef when finished
182 Args : none
183  
184  
185 =cut
186  
187 0 ▶sub next_matrix{
Subroutine next_matrix: not called CC=1 SCAR=6.9
Pod documented
188 0 my ($self) = @_;
189 0 $self->throw_not_implemented();
190 }
191  
192 =head2 write_matrix
193  
194 Title : write_matrix
195 Usage : $io->write_matrix($matrix)
196 Function: Writes a matrix out to the data stream
197 Returns : none
198 Args : Array of Bio::Matrix::MatrixI object
199 - note that not all matricies can be converted to
200 each format, beware with mixing matrix types and output formats
201  
202 =cut
203  
204 0 ▶sub write_matrix{
Subroutine write_matrix: not called CC=1 SCAR=6.9
Pod documented
205 0 my ($self) = @_;
206 0 $self->throw_not_implemented();
207 }
208  
209 6 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
210 6 my ($self,@args) = @_;
211 6 $self->_initialize_io(@args);
212 }
213  
214 =head2 _load_format_module
215  
216 Title : _load_format_module
217 Usage : *INTERNAL Matrix::IO stuff*
218 Function: Loads up (like use) a module at run time on demand
219  
220 =cut
221  
222 6 ▶sub _load_format_module {
Subroutine _load_format_module: called CC=2 SCAR=7.1
223 6 my ($self,$format) = @_;
224 6 my $module = "Bio::Matrix::IO::" . $format;
225 6 my $ok;
226
227 6 eval {
228 6 $ok = $self->_load_module($module);
229 };
230 6 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 6 6
231 0 print STDERR <<END;
232 $self: $format cannot be found
233 Exception $@
234 For more information about the Matrix::IO system please see the
235 Matrix::IO docs. This includes ways of checking for formats at
236 compile time, not run time
237 END
238 ;
239 }
240 6 return $ok;
241 }
242  
243  
244 =head2 _guess_format
245  
246 Title : _guess_format
247 Usage : $obj->_guess_format($filename)
248 Returns : guessed format of filename (lower case)
249 Args : filename
250  
251 =cut
252  
253 0 ▶sub _guess_format {
Subroutine _guess_format: not called CC=4 SCAR=30.0
254 0 my $class = shift;
255 0 ▶ return unless $_ = shift;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ = shift() 0 0 0
256 0 ▶ return 'scoring' if /BLOSUM|PAM$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /BLOSUM|PAM$/i 0 0 0
257 0 ▶ return 'phylip' if /\.dist$/i;
Branch: 1 branch
BranchTrueFalseTotal
if /\.dist$/i 0 0 0
258 }
259  
260 6 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
261 6 my $self = shift;
262 6 $self->close();
263 }
264  
265 0 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: not called CC=1 SCAR=6.9
266 0 my $class = shift;
267 0 return bless {'matrixio' => shift},$class;
268 }
269  
270 0 ▶sub READLINE {
Subroutine READLINE: not called CC=4 SCAR=30.0
271 0 my $self = shift;
272 0 ▶ return $self->{'matrixio'}->next_tree() || undef unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
Condition0%0/2
$self->{'matrixio'}->next_tree || undef
l!l
00
MC/DC0%0/1
$self->{'matrixio'}->next_tree || undef
$self->{'matrixio'}->next_tree
Truth table0%0/2
A
A= $self->{'matrixio'}->next_tree
Aresult
11
00
273 0 my (@list,$obj);
274 0 ▶ push @list,$obj while $obj = $self->{'treeio'}->next_tree();
Branch: 1 branch
BranchTrueFalseTotal
$obj = $self->{"treeio"}->next_tree and do { push @list, $obj } 0 0 0
275 0 return @list;
276 }
277  
278 0 ▶sub PRINT {
Subroutine PRINT: not called CC=1 SCAR=6.9
279 0 my $self = shift;
280 0 $self->{'matrixio'}->write_tree(@_);
281 }
282  
283 5 1;
« Bio/AlignIO/largemultifasta.pm ↑ Summary Bio/Location/Simple.pm »