Bio-MUST-Core
view release on metacpan or search on metacpan
lib/Bio/MUST/Core/Taxonomy/Classifier.pm view on Meta::CPAN
package Bio::MUST::Core::Taxonomy::Classifier;
# ABSTRACT: Helper class for multiple-criterion classifier based on taxonomy
$Bio::MUST::Core::Taxonomy::Classifier::VERSION = '0.252040';
use Moose;
use namespace::autoclean;
# use Smart::Comments;
use Const::Fast;
use List::AllUtils qw(indexes mesh partition_by pairmap);
use Bio::MUST::Core::Types;
use aliased 'Bio::MUST::Core::IdList';
use aliased 'Bio::MUST::Core::SeqMask';
has 'categories' => (
traits => ['Array'],
is => 'ro',
isa => 'ArrayRef[Bio::MUST::Core::Taxonomy::Category]',
required => 1,
handles => {
all_categories => 'elements',
},
);
sub all_labels {
my $self = shift;
return map { $_->label } $self->all_categories;
}
sub classify {
my $self = shift;
my $listable = shift;
# loop through cats and return the first one matching input
# this means that the cat order may affect the classification
for my $cat ($self->all_categories) {
return $cat->label if $cat->matches($listable);
}
# return undef if no suitable cat
return;
}
# "magic" name used when a pattern has no category
const my $NOCAT => '_NOCAT_';
# TODO: come with better name for method?
# TODO: provide a shortcut if only one cat?
sub tax_masks {
my $self = shift;
my $ali = shift;
# TODO: profile and optimize as ideal_mask ?!?
my $width = $ali->width;
my $regex = $ali->gapmiss_regex;
( run in 0.685 second using v1.01-cache-2.11-cpan-39bf76dae61 )