Bio-MUST-Core
view release on metacpan or search on metacpan
lib/Bio/MUST/Core/SeqMask/Weights.pm view on Meta::CPAN
package Bio::MUST::Core::SeqMask::Weights;
# ABSTRACT: Random weights for resampling sequence sites
$Bio::MUST::Core::SeqMask::Weights::VERSION = '0.252040';
use Moose;
use namespace::autoclean;
use autodie;
use feature qw(say);
# use Smart::Comments;
use List::AllUtils qw(sample);
use POSIX;
extends 'Bio::MUST::Core::SeqMask';
use Bio::MUST::Core::Types;
# override superclass' Bool type
# Note: mask indices are as follow: [site]
# mask values are integer weights (>= 0)
has '+mask' => (
isa => 'ArrayRef[Int]',
);
# TODO: mask non-applicable methods from superclass? (Liskov principle)
sub bootstrap_masks {
my $class = shift;
my $ali = shift;
my $args = shift // {}; # HashRef (should not be empty...)
my $rep_n = $args->{rep} // 100;
my $width = $ali->width;
my $k = $args->{width} // $width;
# convert fractional len to conservative integer (if needed)
$k = ceil($k * $width) if 0 < $k && $k <= 1;
my @masks;
for my $i (1..$rep_n) {
my @weights = (0) x $width;
$weights[ int(rand $width) ]++ for 1..$k; # bootstrap sites
push @masks, $class->new( mask => \@weights );
}
return @masks;
}
sub jackknife_masks {
my $class = shift;
my $ali = shift;
my $args = shift // {}; # HashRef (should not be empty...)
my $rep_n = $args->{rep} // 100;
my $width = $ali->width;
my $k = $args->{width} // 0.5;
# convert fractional len to conservative integer (if needed)
( run in 2.220 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )