Bio/Align/PairwiseStatistics.pm

filter: Statementstmt 85.5% 65 / 76 Branchbran 71.4% 30 / 42 Conditioncond 52.6% 20 / 38 MC/DCmcdc 27.2% 6 / 22 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 70.0% 133 / 190 CC 38 SCAR 29.8
CC
38
Cov
74%
score_nuc
31.9
number_of_differences
10.7
number_of_comparable_bases
6.0
CRAP 19.8
« Bio/Search/Iteration/GenericIteration.pm ↑ Summary Bio/AlignIO/clustalw.pm »
1 #
2 # BioPerl module for Bio::Align::PairwiseStatistics
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason@bioperl.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::Align::PairwiseStatistics - Base statistic object for Pairwise Alignments
17  
18 =head1 SYNOPSIS
19  
20 use strict;
21 my $stats = Bio::Align::PairwiseStatistics->new();
22  
23 # get alignment object of two sequences somehow
24 my $pwaln;
25 print $stats->number_of_comparable_bases($pwaln);
26 my $score = $stats->score_nuc($pwaln);
27  
28  
29 =head1 DESCRIPTION
30  
31 Calculate pairwise statistics.
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 the
59 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::Align::PairwiseStatistics;
79 5 $Bio::Align::PairwiseStatistics::VERSION = '1.7.8';
80 5 ▶use vars qw($GapChars);
Subroutine BEGIN: called CC=1 SCAR=0.0
81 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83  
84 5 ▶BEGIN { $GapChars = '(\.|\-)'; }
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 5 ▶use base qw(Bio::Root::Root Bio::Align::StatisticsI);
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 =head2 number_of_comparable_bases
89  
90 Title : number_of_comparable_bases
91 Usage : my $bases = $stat->number_of_comparable_bases($aln);
92 Function: Returns the count of the number of bases that can be
93 compared (L) in this alignment ( length - gaps)
94 Returns : integer
95 Args : L<Bio::Align::AlignI>
96  
97  
98 =cut
99  
100 8 ▶sub number_of_comparable_bases{
Subroutine number_of_comparable_bases: called CC=4 SCAR=17.9
Pod documented
101 8 my ($self,$aln) = @_;
102 8 ▶ if ( ! defined $aln || ! $aln->isa('Bio::Align::AlignI') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $aln && $aln->isa('Bio::Align::AlignI')) { } 0 8 8
elsif ($aln->num_sequences != 2) { } 0 8 8
Condition33%1/3
defined $aln && $aln->isa('Bio::Align::AlignI')
!ll&&!rl&&r
008
MC/DC0%0/2
defined $aln && $aln->isa('Bio::Align::AlignI')
defined $aln $aln->isa('Bio::Align::AlignI')
Truth table33%1/3
A && B
A= defined $alnB= $aln->isa('Bio::Align::AlignI')
ABresult
0X0
100
111
103 0 $self->throw("Must provide a Bio::Align::AlignI compliant object to ".
104 "Bio::Align::PairwiseStatistics");
105 0 return 0;
106 } elsif ( $aln->num_sequences != 2 ) {
107 0 $self->throw("Only pairwise calculations supported. Found ".
108 $aln->num_sequences." sequences in alignment\n");
109 }
110 8 my $L = $aln->length - $self->number_of_gaps($aln);
111 8 return $L;
112 }
113  
114 =head2 number_of_differences
115  
116 Title : number_of_differences
117 Usage : my $nd = $stat->number_of_distances($aln);
118 Function: Returns the number of differences between two sequences
119 Returns : integer
120 Args : L<Bio::Align::AlignI>
121  
122  
123 =cut
124  
125 2 ▶sub number_of_differences{
Subroutine number_of_differences: called CC=10 SCAR=23.7
Pod documented
126 2 my ($self,$aln) = @_;
127 2 ▶ if( ! defined $aln || ! $aln->isa('Bio::Align::AlignI') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $aln && $aln->isa('Bio::Align::AlignI')) { } 0 2 2
elsif ($aln->num_sequences != 2) { } 0 2 2
Condition33%1/3
defined $aln && $aln->isa('Bio::Align::AlignI')
!ll&&!rl&&r
002
MC/DC0%0/2
defined $aln && $aln->isa('Bio::Align::AlignI')
defined $aln $aln->isa('Bio::Align::AlignI')
Truth table33%1/3
A && B
A= defined $alnB= $aln->isa('Bio::Align::AlignI')
ABresult
0X0
100
111
128 0 $self->throw("Must provide a Bio::Align::AlignI compliant object to ".
129 "Bio::Align::PairwiseStatistics");
130 } elsif ( $aln->num_sequences != 2 ) {
131 0 $self->throw("Only pairwise calculations supported. Found ".
132 $aln->num_sequences." sequences in alignment\n");
133 }
134 2 my (@seqs);
135 2 foreach my $seq ( $aln->each_seq ) {
136 4 push @seqs, [ split(//,$seq->seq())];
137 }
138 2 my $firstseq = shift @seqs;
139 #my $secondseq = shift @seqs;
140 2 my $diffcount = 0;
141 2 ▶ for (my $i = 0;$i<$aln->length; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $aln->length) 383 2 385
142 383 ▶ next if ( $firstseq->[$i] =~ /^$GapChars$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $firstseq->[$i] =~ /^$Bio::Align::PairwiseStatistics::GapChars$/ 27 356 383
143 356 foreach my $seq ( @seqs ) {
144 356 ▶ next if ( $seq->[$i] =~ /^$GapChars$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $seq->[$i] =~ /^$Bio::Align::PairwiseStatistics::GapChars$/ 13 343 356
145 343 ▶ if( $firstseq->[$i] ne $seq->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($firstseq->[$i] ne $seq->[$i]) 40 303 343
146 40 $diffcount++;
147 }
148 }
149 }
150 2 return $diffcount;
151 }
152  
153 =head2 number_of_gaps
154  
155 Title : number_of_gaps
156 Usage : my $nd = $stat->number_of_gaps($aln);
157 Function: Returns the number of gapped positions among sequences in alignment
158 Returns : integer
159 Args : L<Bio::Align::AlignI>
160  
161  
162 =cut
163  
164 10 ▶sub number_of_gaps{
Subroutine number_of_gaps: called CC=4 SCAR=17.2
Pod documented
165 10 my ($self,$aln) = @_;
166 10 ▶ if ( ! defined $aln || ! $aln->isa('Bio::Align::AlignI') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $aln && $aln->isa('Bio::Align::AlignI')) { } 0 10 10
elsif ($aln->num_sequences != 2) { } 0 10 10
Condition33%1/3
defined $aln && $aln->isa('Bio::Align::AlignI')
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $aln && $aln->isa('Bio::Align::AlignI')
defined $aln $aln->isa('Bio::Align::AlignI')
Truth table33%1/3
A && B
A= defined $alnB= $aln->isa('Bio::Align::AlignI')
ABresult
0X0
100
111
167 0 $self->throw("Must provide a Bio::Align::AlignI compliant object to ".
168 "Bio::Align::PairwiseStatistics");
169 } elsif ( $aln->num_sequences != 2 ) {
170 0 $self->throw("Only pairwise calculations supported. Found ".
171 $aln->num_sequences." sequences in alignment\n");
172 }
173 10 my $gapline = $aln->gap_line;
174 # this will count the number of '-' characters
175 10 return $gapline =~ tr/-/-/;
176 }
177  
178  
179 =head2 score_nuc
180  
181 Title : score_nuc
182 Usage : my $score = $stat->score_nuc($aln);
183 or
184 my $score = $stat->score_nuc(
185 -aln =>$aln,
186 -match => 1,
187 -mismatch => -1,
188 -gap_open => -1,
189 -gap_ext => -1
190 );
191 Function: Calculate the score of an alignment of 2 nucleic acid sequences. The
192 scoring parameters can be specified. Otherwise the blastn default
193 parameters are used: match = 2, mismatch = -3, gap opening = -5, gap
194 extension = -2
195 Returns : alignment score (number)
196 Args : L<Bio::Align::AlignI>
197 match score [optional]
198 mismatch score [optional]
199 gap opening score [optional]
200 gap extension score [optional]
201  
202 =cut
203  
204 4 ▶sub score_nuc {
Subroutine score_nuc: called CC=23 SCAR=34.6
Pod documented
205 4 my ($self, @args) = @_;
206 4 my ( $aln, $match, $mismatch, $gap_open, $gap_ext) = $self->_rearrange( [qw(
207 ALN MATCH MISMATCH GAP_OPEN GAP_EXT)], @args );
208 4 ▶ if ( ! defined $aln || ! $aln->isa('Bio::Align::AlignI') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $aln && $aln->isa('Bio::Align::AlignI')) { } 0 4 4
elsif ($aln->num_sequences != 2) { } 0 4 4
Condition33%1/3
defined $aln && $aln->isa('Bio::Align::AlignI')
!ll&&!rl&&r
004
MC/DC0%0/2
defined $aln && $aln->isa('Bio::Align::AlignI')
defined $aln $aln->isa('Bio::Align::AlignI')
Truth table33%1/3
A && B
A= defined $alnB= $aln->isa('Bio::Align::AlignI')
ABresult
0X0
100
111
209 0 $self->throw("Must provide a Bio::Align::AlignI compliant object to ".
210 "Bio::Align::PairwiseStatistics");
211 } elsif ( $aln->num_sequences != 2 ) {
212 0 $self->throw("Only pairwise calculations supported. Found ".
213 $aln->num_sequences." sequences in alignment\n");
214 }
215 4 my $seq1 = $aln->get_seq_by_pos(1);
216 4 my $seq2 = $aln->get_seq_by_pos(2);
217 4 ▶ if (! ( ($seq1->alphabet eq 'dna' || $seq1->alphabet eq 'rna') &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($seq1->alphabet eq "dna" || $seq1->alphabet eq "rna" and $seq2->alphabet eq "dna" || $seq2->alphabet eq "rna") 0 4 4
Condition33%3/9
$seq1->alphabet eq "dna" || $seq1->alphabet eq "rna" and $seq2->alphabet eq "dna" || $seq2->alphabet eq "rna"
!ll&&!rl&&r
004
$seq1->alphabet eq "dna" or $seq1->alphabet eq "rna"
l!l&&r!l&&!r
400
$seq2->alphabet eq "dna" or $seq2->alphabet eq "rna"
l!l&&r!l&&!r
400
MC/DC0%0/4
$seq1->alphabet eq "dna" || $seq1->alphabet eq "rna" and $seq2->alphabet eq "dna" || $seq2->alphabet eq "rna"
$seq1->alphabet eq "dna" $seq1->alphabet eq "rna" $seq2->alphabet eq "dna" $seq2->alphabet eq "rna"
Truth table14%1/7
A or B and C or D
A= $seq1->alphabet eq "dna"B= $seq1->alphabet eq "rna"C= $seq2->alphabet eq "dna"D= $seq2->alphabet eq "rna"
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
218 ($seq2->alphabet eq 'dna' || $seq2->alphabet eq 'rna') )) {
219 0 $self->throw("Can only score nucleic acid alignments");
220 }
221 4 ▶ $match ||= 2; # Blastn scoring defaults
Condition100%2/2
$match ||= 2
l!l
22
MC/DC100%1/1
$match ||= 2
$match
Truth table100%2/2
A
A= $match
Aresult
11
00
222 4 ▶ $mismatch ||= -3;
Condition100%2/2
$mismatch ||= -3
l!l
22
MC/DC100%1/1
$mismatch ||= -3
$mismatch
Truth table100%2/2
A
A= $mismatch
Aresult
11
00
223 4 ▶ $gap_open ||= -5;
Condition100%2/2
$gap_open ||= -5
l!l
22
MC/DC100%1/1
$gap_open ||= -5
$gap_open
Truth table100%2/2
A
A= $gap_open
Aresult
11
00
224 4 ▶ $gap_ext ||= -2;
Condition100%2/2
$gap_ext ||= -2
l!l
22
MC/DC100%1/1
$gap_ext ||= -2
$gap_ext
Truth table100%2/2
A
A= $gap_ext
Aresult
11
00
225 4 my $score = 0;
226 4 my $prevres1 = '-';
227 4 my $prevres2 = '-';
228 4 ▶ for (my $pos = 1 ; $pos <= $aln->length ; $pos++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $aln->length) 766 4 770
229 766 my $res1 = $seq1->subseq($pos, $pos);
230 766 my $res2 = $seq2->subseq($pos, $pos);
231 766 ▶ if (!($res1 eq '-' || $res2 eq '-')) { # no gap
Branch: 1 branch
BranchTrueFalseTotal
if (not $res1 eq '-' || $res2 eq '-') { } 686 80 766
Condition100%3/3
$res1 eq '-' || $res2 eq '-'
l!l&&r!l&&!r
5426686
MC/DC100%2/2
$res1 eq '-' || $res2 eq '-'
$res1 eq '-' $res2 eq '-'
Truth table100%3/3
A || B
A= $res1 eq '-'B= $res2 eq '-'
ABresult
1X1
011
000
232 686 ▶ if ($res1 eq $res2) { # same residue
Branch: 1 branch
BranchTrueFalseTotal
if ($res1 eq $res2) { } 606 80 686
233 606 $score += $match;
234 } else { # other residue
235 80 $score += $mismatch;
236 }
237 } else { # open or ext gap?
238 80 my $open = 0;
239 80 ▶ if (!($res1 eq '-' && $res2 eq '-')) { # exactly one gap
Branch: 1 branch
BranchTrueFalseTotal
if (not $res1 eq '-' && $res2 eq '-') { } 80 0 80
Condition66%2/3
$res1 eq '-' && $res2 eq '-'
!ll&&!rl&&r
26540
MC/DC0%0/2
$res1 eq '-' && $res2 eq '-'
$res1 eq '-' $res2 eq '-'
Truth table66%2/3
A && B
A= $res1 eq '-'B= $res2 eq '-'
ABresult
0X0
100
111
240 80 my $prevres = $prevres1;
241 80 ▶ $prevres = $prevres2 if $res2 eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $res2 eq "-" 26 54 80
242 80 ▶ $open = 1 unless $prevres eq '-';
Branch: 1 branch
BranchTrueFalseTotal
unless $prevres eq "-" 32 48 80
243 } else { # 2 gaps
244 0 ▶ $open = 1 unless $prevres1 eq '-' && $prevres2 eq '-';
Branch: 1 branch
BranchTrueFalseTotal
unless $prevres1 eq "-" and $prevres2 eq "-" 0 0 0
Condition0%0/3
$prevres1 eq "-" and $prevres2 eq "-"
!ll&&!rl&&r
000
MC/DC0%0/2
$prevres1 eq "-" and $prevres2 eq "-"
$prevres1 eq "-" $prevres2 eq "-"
Truth table0%0/3
A and B
A= $prevres1 eq "-"B= $prevres2 eq "-"
ABresult
0X0
100
111
245 }
246 80 ▶ if ($open) {
Branch: 1 branch
BranchTrueFalseTotal
if ($open) { } 32 48 80
247 32 $score += $gap_open; # gap opening
248 } else {
249 48 $score += $gap_ext; # gap extension
250 }
251 }
252 766 $prevres1 = $res1;
253 766 $prevres2 = $res2;
254 }
255 4 return $score;
256 }
257  
258 5 1;
« Bio/Search/Iteration/GenericIteration.pm ↑ Summary Bio/AlignIO/clustalw.pm »