| 1 | package Bio::MUST::Core::Taxonomy::Filter; | ||||||||||
| 2 | # ABSTRACT: Helper class for filtering seqs according to taxonomy | ||||||||||
| 3 | 18 | $Bio::MUST::Core::Taxonomy::Filter::VERSION = '0.252040'; | |||||||||
| 4 | 18 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 18 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 18 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 18 | ▶ | use feature qw(say); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 18 | ▶ | use Smart::Comments '###'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 18 | ▶ | use List::AllUtils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 18 | ▶ | use Bio::MUST::Core::Types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 18 | ▶ | use aliased 'Bio::MUST::Core::IdList'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 18 | with 'Bio::MUST::Core::Roles::Filterable', | |||||||||
| 17 | 'Bio::MUST::Core::Roles::Taxable'; | ||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub is_allowed { | ||||||||
|
Subroutine
is_allowed: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 22 | 0 | my $self = shift; | |||||||||
| 23 | 0 | my $seq_id = shift; | |||||||||
| 24 | |||||||||||
| 25 | # test whether lineage of seq_id has at least one wanted taxon | ||||||||||
| 26 | # ... or has at least one unwanted taxon | ||||||||||
| 27 | # non-matching taxa are allowed by default | ||||||||||
| 28 | |||||||||||
| 29 | 0 | my @lineage = $self->tax->fetch_lineage($seq_id); | |||||||||
| 30 | 0 | ▶ | return undef unless @lineage; ## no critic (ProhibitExplicitReturnUndef) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | return 0 unless List::AllUtils::any { $self->is_wanted( $_) } @lineage; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 33 | 0 | ▶ | return 0 if List::AllUtils::any { $self->is_unwanted($_) } @lineage; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 34 | 0 | return 1; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | sub tax_list { | ||||||||
|
Subroutine
tax_list: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 39 | 0 | my $self = shift; | |||||||||
| 40 | 0 | my $listable = shift; | |||||||||
| 41 | |||||||||||
| 42 | 0 | my @ids; | |||||||||
| 43 | 0 | for my $seq_id ($listable->all_seq_ids) { | |||||||||
| 44 | 0 | ▶ | push @ids, $seq_id->full_id if $self->is_allowed($seq_id); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | return IdList->new( ids => \@ids ); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 18 | __PACKAGE__->meta->make_immutable; | |||||||||
| 51 | 18 | 1; | |||||||||
| 52 | |||||||||||
| 53 | __END__ | ||||||||||