line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::MUST::Core::Taxonomy::Criterion; |
2
|
|
|
|
|
|
|
# ABSTRACT: Helper class for multiple-criterion classifier based on taxonomy |
3
|
|
|
|
|
|
|
$Bio::MUST::Core::Taxonomy::Criterion::VERSION = '0.212650'; |
4
|
17
|
|
|
17
|
|
11930
|
use Moose; |
|
17
|
|
|
|
|
53
|
|
|
17
|
|
|
|
|
133
|
|
5
|
17
|
|
|
17
|
|
123882
|
use namespace::autoclean; |
|
17
|
|
|
|
|
51
|
|
|
17
|
|
|
|
|
225
|
|
6
|
|
|
|
|
|
|
|
7
|
17
|
|
|
17
|
|
1895
|
use List::AllUtils qw(sum count_by); |
|
17
|
|
|
|
|
49
|
|
|
17
|
|
|
|
|
1249
|
|
8
|
|
|
|
|
|
|
|
9
|
17
|
|
|
17
|
|
142
|
use Bio::MUST::Core::Types; |
|
17
|
|
|
|
|
44
|
|
|
17
|
|
|
|
|
7884
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'tax_filter' => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'Bio::MUST::Core::Taxonomy::Filter', |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
handles => [ qw(is_allowed) ], |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'min_seq_count' => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => 'Num', |
23
|
|
|
|
|
|
|
default => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has $_ => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => 'Maybe[Num]', |
30
|
|
|
|
|
|
|
default => undef, |
31
|
|
|
|
|
|
|
) for qw( max_seq_count |
32
|
|
|
|
|
|
|
min_org_count max_org_count |
33
|
|
|
|
|
|
|
min_copy_mean max_copy_mean |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub matches { |
39
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
40
|
0
|
|
|
|
|
|
my $listable = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# case 1: handle classification of single ids |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# this should work for: |
45
|
|
|
|
|
|
|
# - SeqId objects |
46
|
|
|
|
|
|
|
# - stringified lineages |
47
|
|
|
|
|
|
|
# - mere strings |
48
|
0
|
0
|
0
|
|
|
|
unless ( ref $listable && $listable->can('all_seq_ids') ) { |
49
|
|
|
|
|
|
|
# TODO: make this robust to ArrayRef[] (via coercion) |
50
|
0
|
|
|
|
|
|
return $self->is_allowed($listable); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# case 2: handle "true" listable objects |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# get seq_ids passing tax_filter |
56
|
0
|
|
|
|
|
|
my @seq_ids = grep { $self->is_allowed($_) } $listable->all_seq_ids; |
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $seq_n = @seq_ids; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# return success if positively avoided taxa are indeed absent |
60
|
0
|
0
|
|
|
|
|
unless ($seq_n) { |
61
|
0
|
0
|
0
|
|
|
|
return 1 |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
62
|
|
|
|
|
|
|
if ( defined $self->max_seq_count && !$self->max_seq_count ) |
63
|
|
|
|
|
|
|
|| ( defined $self->max_org_count && !$self->max_org_count ) |
64
|
|
|
|
|
|
|
; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# return failure unless #seqs within allowed bounds |
68
|
|
|
|
|
|
|
# by default there is no upper bound on #seqs |
69
|
0
|
0
|
|
|
|
|
return 0 if $seq_n < $self->min_seq_count; |
70
|
0
|
0
|
0
|
|
|
|
return 0 if defined $self->max_seq_count && $seq_n > $self->max_seq_count; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# return success if no more condition for criterion |
73
|
|
|
|
|
|
|
# this is optimized for speed |
74
|
0
|
0
|
0
|
|
|
|
return 1 |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
75
|
|
|
|
|
|
|
unless defined $self->min_org_count || defined $self->max_org_count |
76
|
|
|
|
|
|
|
|| defined $self->min_copy_mean || defined $self->max_copy_mean |
77
|
|
|
|
|
|
|
; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# compute #orgs, #seqs/org and mean(copy/org) |
80
|
|
|
|
|
|
|
# these statistics only pertain to seq_ids having passed tax_filter |
81
|
0
|
|
0
|
0
|
|
|
my %count_for = count_by { $_->full_org // $_->taxon_id } @seq_ids; |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Note: use taxon_id if full_org is not defined (for tax-aware abbr ids) |
83
|
|
|
|
|
|
|
# this implies that each taxon_id must correspond to a single org |
84
|
0
|
|
|
|
|
|
my $org_n = keys %count_for; |
85
|
0
|
|
|
|
|
|
my $cpy_n = (sum values %count_for) / $org_n; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# return failure unless #orgs within allowed bounds |
88
|
|
|
|
|
|
|
# by default there is no lower nor upper bound on #seqs |
89
|
0
|
0
|
0
|
|
|
|
return 0 if defined $self->min_org_count && $org_n < $self->min_org_count; |
90
|
0
|
0
|
0
|
|
|
|
return 0 if defined $self->max_org_count && $org_n > $self->max_org_count; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# return failure unless mean(copy/org) within allowed bounds |
93
|
|
|
|
|
|
|
# by default there is no lower nor upper bound on mean(copy/org) |
94
|
0
|
0
|
0
|
|
|
|
return 0 if defined $self->min_copy_mean && $cpy_n < $self->min_copy_mean; |
95
|
0
|
0
|
0
|
|
|
|
return 0 if defined $self->max_copy_mean && $cpy_n > $self->max_copy_mean; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# return success |
98
|
0
|
|
|
|
|
|
return 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Bio::MUST::Core::Taxonomy::Criterion - Helper class for multiple-criterion classifier based on taxonomy |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 VERSION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
version 0.212650 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SYNOPSIS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# TODO |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DESCRIPTION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# TODO |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 METHODS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 matches |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 AUTHOR |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Denis BAURAIN <denis.baurain@uliege.be> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
137
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |