Bio-MUST-Core
view release on metacpan or search on metacpan
lib/Bio/MUST/Core/Taxonomy/Criterion.pm view on Meta::CPAN
package Bio::MUST::Core::Taxonomy::Criterion;
# ABSTRACT: Helper class for multiple-criterion classifier based on taxonomy
$Bio::MUST::Core::Taxonomy::Criterion::VERSION = '0.252040';
use Moose;
use namespace::autoclean;
use List::AllUtils qw(sum count_by uniq_by);
use Bio::MUST::Core::Types;
has 'tax_filter' => (
is => 'ro',
isa => 'Bio::MUST::Core::Taxonomy::Filter',
required => 1,
handles => [ qw(is_allowed) ],
);
has 'min_seq_count' => (
is => 'ro',
isa => 'Num',
default => 1,
);
has $_ => (
is => 'ro',
isa => 'Maybe[Num]',
default => undef,
) for qw( max_seq_count
min_org_count max_org_count
min_copy_mean max_copy_mean
min_seq_perc max_seq_perc
min_org_perc max_org_perc
);
sub matches { ## no critic (Subroutines::ProhibitExcessComplexity)
my $self = shift;
my $listable = shift;
# case 1: handle classification of single ids
# this should work for:
# - SeqId objects
# - stringified lineages
# - mere strings
unless ( ref $listable && $listable->can('all_seq_ids') ) {
# TODO: make this robust to ArrayRef[] (via coercion)
return $self->is_allowed($listable);
}
# case 2: handle "true" listable objects
# get seq_ids passing tax_filter
my @seq_ids = $listable->all_seq_ids;
my @targets = grep { $self->is_allowed($_) } @seq_ids;
# return success if positively avoided taxa are indeed absent
# Note: no need to compute percentages yet
my $seq_n = @targets;
unless ($seq_n) {
return 1
( run in 2.382 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )