lib/Bio/MUST/Core/SeqMask/Pmsf.pm

filter: Statementstmt 100% 53 / 53 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 98.6% 71 / 72 CC 4 SCAR 4.5
CC
4
Cov
98%
chi_square_stats
3.0
load
2.0
BEGIN
1.0
CRAP 1.6
« lib/Bio/MUST/Core/Ali/Temporary.pm ↑ Summary lib/Bio/MUST/Core/PostPred.pm »
1 package Bio::MUST::Core::SeqMask::Pmsf;
2 # ABSTRACT: Posterior mean site frequencies (PMSF) for sequence sites
3 18 $Bio::MUST::Core::SeqMask::Pmsf::VERSION = '0.252040';
4 18 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 18 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 18 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use Const::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use List::AllUtils qw(sum each_arrayref);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 18 extends 'Bio::MUST::Core::SeqMask';
15  
16 18 ▶use Bio::MUST::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶use aliased 'Bio::MUST::Core::SeqMask::Rates';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 # override superclass' Bool type
21 # Note: mask indices are as follow: [site][AA]
22 # mask values are freqs
23 18 has '+mask' => (
24 isa => 'ArrayRef[ArrayRef[Num]]',
25 );
26  
27 # TODO: mask non-applicable methods from superclass? (Liskov principle)
28  
29 18 const my $PREC => 10;
30  
31  
32 1 ▶sub chi_square_stats {
Subroutine chi_square_stats: called CC=3 SCAR=11.0
Pod documented
33 1 my $self = shift;
34 1 my $othr = shift;
35  
36 # check that both pmsf objects are the same length
37 # potential bugs could come from constant sites etc
38 1 my $s_width = $self->mask_len;
39 1 my $o_width = $othr->mask_len;
40 1 ▶ carp "[BMC] Warning: PMSF widths do not match: $s_width vs. $o_width!"
Branch: 1 branch
BranchTrueFalseTotal
unless $s_width == $o_width 0 1 1
41 unless $s_width == $o_width;
42  
43 1 my @stats;
44  
45 1 my $ea = each_arrayref [ $self->all_states ], [ $othr->all_states ];
46 1 ▶ while (my ($s_freqs, $o_freqs) = $ea->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$ea()) 34607 1 34608
47 push @stats, 0 + ( sprintf "%.${PREC}f", sum map {
48 34607 ( $o_freqs->[$_] - $s_freqs->[$_] )**2 / $s_freqs->[$_]
49 } 0..$#$o_freqs );
50 } # Note: trick to get identical results across platforms
51 # https://stackoverflow.com/questions/21204733/a-better-chi-square-test-for-perl
52  
53 1 return Rates->new( mask => \@stats );
54 }
55  
56  
57 # I/O methods
58  
59  
60 2 ▶sub load {
Subroutine load: called CC=2 SCAR=6.9
Pod documented
61 2 my $class = shift;
62 2 my $infile = shift;
63  
64 2 open my $in, '<', $infile;
65  
66 2 my $mask = $class->new();
67  
68 LINE:
69 2 ▶ while (my $line = <$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in)) 69214 2 69216
70 69214 chomp $line;
71  
72 # skip empty lines, header line and process comment lines
73 # next LINE if $line =~ $EMPTY_LINE
74 # || $mask->is_comment($line);
75  
76 # split line on whitespace and ignore first value (site number)
77 69214 my (undef, @fields) = split /\s+/xms, $line;
78  
79 # store AA freqs all at once
80 69214 $mask->add_state( \@fields );
81 }
82  
83 2 return $mask;
84 }
85  
86 18 __PACKAGE__->meta->make_immutable;
87 18 1;
88  
89 __END__
« lib/Bio/MUST/Core/Ali/Temporary.pm ↑ Summary lib/Bio/MUST/Core/PostPred.pm »