lib/Bio/MUST/Core/PostPred.pm

filter: Statementstmt 100% 52 / 52 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 100% 64 / 64 CC 4 SCAR 4.5
CC
4
Cov
100%
_make_test
3.0
_build_zscore_for
2.0
BEGIN
1.0
CRAP 1.6
« lib/Bio/MUST/Core/SeqMask/Pmsf.pm ↑ Summary lib/Bio/MUST/Core/Ali/Stash.pm »
1 package Bio::MUST::Core::PostPred;
2 # ABSTRACT: Posterior predictive tests for sequences
3 18 $Bio::MUST::Core::PostPred::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 # use Smart::Comments;
11  
12 18 ▶use Statistics::Descriptive;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 18 ▶use Bio::MUST::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶use aliased 'Bio::MUST::Core::PostPred::Composition';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 # private hash containing test statistics by sequence (and globally)
20 # Note: this hash is actually a Tie::IxHash (see factory methods)
21 18 has '_stats_for' => (
22 traits => ['Hash'],
23 is => 'ro',
24 isa => 'HashRef[ArrayRef[Num]]',
25 required => 1,
26 handles => {
27 all_ids => 'keys',
28 stats_for => 'get',
29 },
30 );
31  
32  
33 # private hash containing test Z-scores by sequence (and globally)
34 # Note: this hash is actually a Tie::IxHash (see builder)
35 18 has '_zscore_for' => (
36 traits => ['Hash'],
37 is => 'ro',
38 isa => 'HashRef[Num]',
39 init_arg => undef,
40 lazy => 1,
41 builder => '_build_zscore_for',
42 handles => {
43 zscore_for => 'get',
44 },
45 );
46  
47 ## no critic (ProhibitUnusedPrivateSubroutines)
48  
49 # TODO: switch to BUILD to compute p-values as well
50 # TODO: explore other Statistics:: modules on CPAN
51  
52 1 ▶sub _build_zscore_for {
Subroutine _build_zscore_for: called CC=2 SCAR=6.9
53 1 my $self = shift;
54  
55 1 tie my %zscore_for, 'Tie::IxHash';
56  
57 # loop through all ids (including $GLOBAL id if any)
58 1 for my $id ($self->all_ids) {
59  
60 # compute std-dev from simulated stat dist
61 # Note: the first value MUST BE the observed test stat
62 81 my ($obs, @sims) = @{ $self->stats_for($id) };
63 81 my $stat = Statistics::Descriptive::Full->new();
64 81 $stat->add_data(@sims);
65 81 my $mean = $stat->mean;
66 81 my $sd = $stat->standard_deviation;
67  
68 # compute and store zscore
69 81 my $zscore = ($obs - $mean) / $sd;
70 81 $zscore_for{$id} = $zscore;
71 }
72  
73 1 return \%zscore_for;
74 }
75  
76 ## use critic
77  
78  
79 # PostPred factory methods
80  
81  
82 1 ▶sub comp_test { ## no critic (RequireArgUnpacking)
Subroutine comp_test: called CC=1 SCAR=0.0
Pod documented
83 1 return shift->_make_test(Composition, @_);
84 }
85  
86  
87 1 ▶sub _make_test {
Subroutine _make_test: called CC=3 SCAR=11.0
88 1 my $class = shift;
89 1 my $type = shift;
90 1 my $alis = shift;
91  
92 1 tie my %stats_for, 'Tie::IxHash';
93  
94 # loop through Ali objects to compute the required test statistic
95 # Note: the first Ali MUST BE the real one and the others the simulations
96 1 for my $ali ( @{$alis} ) {
97  
98 # get test statistics for Ali
99 51 my $test = $type->new( seqs => $ali );
100  
101 # accumulate test statistics by seq
102 4131 push @{ $stats_for{$_} }, $test->stat_for($_)
103 51 for $test->all_ids;
104 }
105  
106 1 return $class->new( _stats_for => \%stats_for );
107 }
108  
109 18 __PACKAGE__->meta->make_immutable;
110 18 1;
111  
112 __END__
« lib/Bio/MUST/Core/SeqMask/Pmsf.pm ↑ Summary lib/Bio/MUST/Core/Ali/Stash.pm »