Bio-RNA-Barriers
view release on metacpan or search on metacpan
lib/Bio/RNA/Barriers/RateMatrix.pm view on Meta::CPAN
package Bio::RNA::Barriers::RateMatrix;
our $VERSION = '0.03';
use 5.012;
use strict;
use warnings;
use Moose;
use MooseX::StrictConstructor;
use namespace::autoclean;
use Moose::Util::TypeConstraints qw(enum subtype as where message);
use autodie qw(:all);
use overload '""' => \&stringify;
use Scalar::Util qw( reftype looks_like_number );
use List::Util qw( all uniqnum );
enum __PACKAGE__ . 'RateMatrixType', [qw(TXT BIN)];
# Natural number type directly from the Moose docs.
subtype 'PosInt',
as 'Int',
where { $_ > 0 },
message { "The number you provided, $_, was not a positive number" };
has 'file_name' => (
is => 'ro',
isa => 'Str',
predicate => 'has_file_name',
);
has 'file_type' => (
is => 'rw',
isa => __PACKAGE__ . 'RateMatrixType',
required => 1,
);
has '_file_handle' => (
is => 'ro',
isa => 'FileHandle',
init_arg => 'file_handle',
lazy => 1,
builder => '_build_file_handle',
);
# Splice rate matrix directly when reading the data. This can read big
# matrices when only keeping a few entries.
has 'splice_on_parsing' => (
is => 'ro',
isa => 'ArrayRef[PosInt]',
predicate => 'was_spliced_on_parsing',
);
has '_data' => (is => 'ro', lazy => 1, builder => '_build_data');
sub BUILD {
my $self = shift;
# Enforce data is read from handle immediately despite laziness.
$self->dim;
}
# Read the actual rate data from the input file and construct the
# matrix from it.
sub _build_data {
my $self = shift;
my $rate_matrix;
if ($self->file_type eq 'TXT') {
$rate_matrix = __PACKAGE__->read_text_rate_matrix(
$self->_file_handle,
$self->splice_on_parsing,
);
}
( run in 1.790 second using v1.01-cache-2.11-cpan-99c4e6809bf )