Bio/Matrix/IO/mlagan.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 66.6% 8 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 85.2% 52 / 61 CC 10 SCAR 15.6
CC
10
Cov
87%
write_matrix
6.4
next_matrix
5.0
BEGIN
1.0
CRAP 4.8
« Bio/Tools/Geneid.pm ↑ Summary Bio/Search/Result/ResultI.pm »
1 #
2 # BioPerl module for Bio::Matrix::IO::mlagan
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Sendu Bala <bix@sendu.me.uk>
7 #
8 # Copyright Sendu Bala
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::mlagan - A parser for the mlagan substitution matrix
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Matrix::IO;
21 my $parser = Bio::Matrix::IO->new(-format => 'mlagan',
22 -file => 'nucmatrix.txt');
23 my $matrix = $parser->next_matrix;
24 my $gap_open = $parser->gap_open;
25 my $gap_continue = $parser->gap_continue;
26  
27 =head1 DESCRIPTION
28  
29 Use to read in and write out substitution matrix files suitable for use by
30 mlagan.
31  
32 =head1 FEEDBACK
33  
34 =head2 Mailing Lists
35  
36 User feedback is an integral part of the evolution of this and other
37 Bioperl modules. Send your comments and suggestions preferably to
38 the Bioperl mailing list. Your participation is much appreciated.
39  
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42  
43 =head2 Support
44  
45 Please direct usage questions or support issues to the mailing list:
46  
47 I<bioperl-l@bioperl.org>
48  
49 rather than to the module maintainer directly. Many experienced and
50 reponsive experts will be able look at the problem and quickly
51 address it. Please include a thorough description of the problem
52 with code and data examples if at all possible.
53  
54 =head2 Reporting Bugs
55  
56 Report bugs to the Bioperl bug tracking system to help us keep track
57 of the bugs and their resolution. Bug reports can be submitted via
58 the web:
59  
60 https://github.com/bioperl/bioperl-live/issues
61  
62 =head1 AUTHOR - Sendu Bala
63  
64 Email bix@sendu.me.uk
65  
66 =head1 APPENDIX
67  
68 The rest of the documentation details each of the object methods.
69 Internal methods are usually preceded with a _
70  
71 =cut
72  
73 # Let the code begin...
74  
75 package Bio::Matrix::IO::mlagan;
76 2 $Bio::Matrix::IO::mlagan::VERSION = '1.7.8';
77 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 2 ▶use Bio::Matrix::Mlagan;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 2 ▶use base qw(Bio::Matrix::IO);
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 =head2 new
83  
84 Title : new
85 Usage : my $obj = Bio::Matrix::IO::mlagan->new();
86 Function: Builds a new Bio::Matrix::IO::mlagan object
87 Returns : an instance of Bio::Matrix::IO::mlagan
88 Args :
89  
90 =cut
91  
92 =head2 next_matrix
93  
94 Title : next_matrix
95 Usage : my $matrix = $obj->next_matrix();
96 Function: parses a matrix file
97 Returns : L<Bio::Matrix::Mlagan>
98 Args : none
99  
100 =cut
101  
102 2 ▶sub next_matrix {
Subroutine next_matrix: called CC=5 SCAR=16.2
Pod documented
103 2 my $self = shift;
104
105 2 my (@matrix, $gap_open, $gap_cont);
106 2 ▶ while (defined ($_ = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 18 0 18
107 18 ▶ if (/^[ACGTN\.]/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^[ACGTN\.]/) { } 12 6 18
elsif (/^[-\d]/) { } 2 4 6
108 12 my (undef, @values) = split;
109 12 push(@matrix, \@values);
110 }
111 elsif (/^[-\d]/) {
112 2 ($gap_open, $gap_cont) = split;
113 2 last;
114 }
115 }
116
117 2 ▶ @matrix == 6 || $self->throw("Something wrong with file, was it the correct format?");
Branch: 1 branch
BranchTrueFalseTotal
@matrix == 6 or $self->throw("Something wrong with file, was it the correct format?") 2 0 2
118
119 2 my $matrix = Bio::Matrix::Mlagan->new(-values => \@matrix,
120 -gap_open => $gap_open,
121 -gap_continue => $gap_cont);
122
123 2 return $matrix;
124 }
125  
126 =head2 write_matrix
127  
128 Title : write_matrix
129 Usage : $obj->write_matrix($matrix)
130 Function: Write out a matrix in mlagan format
131 Returns : n/a
132 Args : L<Bio::Matrix::Generic>
133  
134 =cut
135  
136 1 ▶sub write_matrix {
Subroutine write_matrix: called CC=6 SCAR=18.6
Pod documented
137 1 my ($self, $matrix) = @_;
138 1 ▶ $matrix || $self->throw("Matrix required as input");
Branch: 1 branch
BranchTrueFalseTotal
$matrix or $self->throw("Matrix required as input") 1 0 1
139 1 my $gap_open = $matrix->gap_open;
140 1 my $gap_continue = $matrix->gap_continue;
141
142 1 ▶ unless (defined $gap_open && defined $gap_continue) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $gap_open and defined $gap_continue) 0 1 1
Condition33%1/3
defined $gap_open and defined $gap_continue
!ll&&!rl&&r
001
MC/DC0%0/2
defined $gap_open and defined $gap_continue
defined $gap_open defined $gap_continue
Truth table33%1/3
A and B
A= defined $gap_openB= defined $gap_continue
ABresult
0X0
100
111
143 0 $self->throw("gap_open() and gap_continue() in the supplied matrix object must both be set");
144 }
145
146 1 $self->_print(" A C G T . N\n");
147
148 1 foreach my $char (qw(A C G T . N)) {
149 6 my @row = $matrix->get_row($char);
150 6 my $row = $char;
151 6 foreach my $val (@row) {
152 36 $row .= " " x (5 - length($val)) . $val;
153 }
154
155 6 $self->_print($row."\n");
156 }
157
158 1 $self->_print("\n$gap_open $gap_continue");
159
160 1 return;
161 }
162  
163 2 1;
« Bio/Tools/Geneid.pm ↑ Summary Bio/Search/Result/ResultI.pm »