| 1 | package Bio::FastParsers::Roles::Clusterable; | ||||||||||||||||||||
| 2 | # ABSTRACT: Attributes and methods common to CD-HIT and UCLUST drivers | ||||||||||||||||||||
| 3 | # CONTRIBUTOR: Amandine BERTRAND <amandine.bertrand@doct.uliege.be> | ||||||||||||||||||||
| 4 | 7 | $Bio::FastParsers::Roles::Clusterable::VERSION = '0.221230'; | |||||||||||||||||||
| 5 | 7 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 7 | ▶ | use autodie; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 7 | ▶ | use feature qw(say); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 7 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 7 | ▶ | use Sort::Naturally; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 7 | ▶ | use Try::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | # private attributes | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 7 | has '_members_for' => ( | |||||||||||||||||||
| 18 | traits => ['Hash'], | ||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||
| 20 | isa => 'HashRef[ArrayRef[Str]]', | ||||||||||||||||||||
| 21 | init_arg => undef, | ||||||||||||||||||||
| 22 | writer => '_set_members_for', | ||||||||||||||||||||
| 23 | handles => { | ||||||||||||||||||||
| 24 | all_representatives => 'keys', | ||||||||||||||||||||
| 25 | members_for => 'get', | ||||||||||||||||||||
| 26 | }, | ||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 2 | ▶ | sub all_representatives_by_cluster_size { | ||||||||||||||||||
|
Subroutine
all_representatives_by_cluster_size: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 30 | 2 | my $self = shift; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | # sort first on descending cluster size then on representative id | ||||||||||||||||||||
| 33 | # using natural sort and the Schwartzian transform | ||||||||||||||||||||
| 34 | 134 | my @list = map { $_->[1] } | |||||||||||||||||||
| 35 | 664 | ▶ | sort { $b->[0] <=> $a->[0] || ncmp($a->[1], $b->[1]) } | ||||||||||||||||||
|
Condition66%2/3
$Bio::FastParsers::Roles::Clusterable::b->[0] <=> $Bio::FastParsers::Roles::Clusterable::a->[0] || ncmp($Bio::FastParsers::Roles::Clusterable::a->[1], $Bio::FastParsers::Roles::Clusterable::b->[1])
MC/DC0%0/2
$Bio::FastParsers::Roles::Clusterable::b->[0] <=> $Bio::FastParsers::Roles::Clusterable::a->[0] || ncmp($Bio::FastParsers::Roles::Clusterable::a->[1], $Bio::FastParsers::Roles::Clusterable::b->[1])
$Bio::FastParsers::Roles::Clusterable::b->[0] <=> $Bio::FastParsers::Roles::Clusterable::a->[0]
ncmp($Bio::FastParsers::Roles::Clusterable::a->[1], $Bio::FastParsers::Roles::Clusterable::b->[1])
Truth table66%2/3
A || B
A= $Bio::FastParsers::Roles::Clusterable::b->[0] <=> $Bio::FastParsers::Roles::Clusterable::a->[0]B= ncmp($Bio::FastParsers::Roles::Clusterable::a->[1], $Bio::FastParsers::Roles::Clusterable::b->[1])
| |||||||||||||||||||||
| 36 | 2 | map { [ scalar @{ $self->members_for($_) }, $_ ] } | |||||||||||||||||||
| 37 | $self->all_representatives | ||||||||||||||||||||
| 38 | ; | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 2 | return @list; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub clust_mapper { | ||||||||||||||||||
|
Subroutine
clust_mapper: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||
| 46 | 0 | ▶ | my $sep = shift // q{/}; | ||||||||||||||||||
|
Condition0%0/2
shift() // "/"
MC/DC0%0/1
shift() // "/"
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | # do not force Bio::FastParsers to depend on Bio::MUST::Core | ||||||||||||||||||||
| 49 | 0 | ▶ | my $bmc = try { require Bio::MUST::Core } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 50 | 0 | ▶ | catch { return } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 51 | 0 | ; | |||||||||||||||||||
| 52 | 0 | ▶ | unless ($bmc) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 0 | carp 'Warning: Bio::MUST::Core not installed; returning nothing!'; | |||||||||||||||||||
| 54 | 0 | return; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | my @abbr_ids; | |||||||||||||||||||
| 58 | my @long_ids; | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | for my $repr ( $self->all_representatives_by_cluster_size ) { | |||||||||||||||||||
| 61 | 0 | push @abbr_ids, $repr; | |||||||||||||||||||
| 62 | push @long_ids, join $sep, | ||||||||||||||||||||
| 63 | 0 | nsort ( @{ $self->members_for($repr) }, $repr ) | |||||||||||||||||||
| 64 | ; | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | return Bio::MUST::Core::IdMapper->new( | |||||||||||||||||||
| 68 | abbr_ids => \@abbr_ids, | ||||||||||||||||||||
| 69 | long_ids => \@long_ids, | ||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 7 | ▶ | no Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 74 | 7 | 1; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||