Bio-MUST-Core
view release on metacpan or search on metacpan
lib/Bio/MUST/Core/PostPred.pm view on Meta::CPAN
package Bio::MUST::Core::PostPred;
# ABSTRACT: Posterior predictive tests for sequences
$Bio::MUST::Core::PostPred::VERSION = '0.252040';
use Moose;
use namespace::autoclean;
use autodie;
use feature qw(say);
# use Smart::Comments;
use Statistics::Descriptive;
use Tie::IxHash;
use Bio::MUST::Core::Types;
use aliased 'Bio::MUST::Core::PostPred::Composition';
# private hash containing test statistics by sequence (and globally)
# Note: this hash is actually a Tie::IxHash (see factory methods)
has '_stats_for' => (
traits => ['Hash'],
is => 'ro',
isa => 'HashRef[ArrayRef[Num]]',
required => 1,
handles => {
all_ids => 'keys',
stats_for => 'get',
},
);
# private hash containing test Z-scores by sequence (and globally)
# Note: this hash is actually a Tie::IxHash (see builder)
has '_zscore_for' => (
traits => ['Hash'],
is => 'ro',
isa => 'HashRef[Num]',
init_arg => undef,
lazy => 1,
builder => '_build_zscore_for',
handles => {
zscore_for => 'get',
},
);
## no critic (ProhibitUnusedPrivateSubroutines)
# TODO: switch to BUILD to compute p-values as well
# TODO: explore other Statistics:: modules on CPAN
sub _build_zscore_for {
my $self = shift;
tie my %zscore_for, 'Tie::IxHash';
# loop through all ids (including $GLOBAL id if any)
for my $id ($self->all_ids) {
# compute std-dev from simulated stat dist
# Note: the first value MUST BE the observed test stat
my ($obs, @sims) = @{ $self->stats_for($id) };
my $stat = Statistics::Descriptive::Full->new();
$stat->add_data(@sims);
my $mean = $stat->mean;
( run in 0.958 second using v1.01-cache-2.11-cpan-39bf76dae61 )