| 1 | package Bio::Roary::AccessoryClustering; | ||||||||||
| 2 | 2 | $Bio::Roary::AccessoryClustering::VERSION = '3.13.0'; | |||||||||
| 3 | # ABSTRACT: Take an a clusters file from CD-hit and the fasta file and output a fasta file without full clusters | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Bio::Roary::External::Cdhit; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | with 'Bio::Roary::ClustersRole'; | |||||||||
| 9 | |||||||||||
| 10 | 2 | has 'input_file' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 11 | 2 | has 'identity' => ( is => 'ro', isa => 'Num', default => 0.9 ); | |||||||||
| 12 | 2 | has 'cpus' => ( is => 'ro', isa => 'Int', default => 1 ); | |||||||||
| 13 | 2 | has '_output_cd_hit_filename' => ( is => 'ro', isa => 'Str', default => '_accessory_clusters' ); | |||||||||
| 14 | 2 | has 'clusters_to_samples' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_clusters_to_samples' ); | |||||||||
| 15 | 2 | has 'samples_to_clusters' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_samples_to_clusters' ); | |||||||||
| 16 | 2 | has 'sample_weights' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_sample_weights' ); | |||||||||
| 17 | 2 | has 'clusters_filename' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_clusters_filename' ); | |||||||||
| 18 | 2 | has 'clusters' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build__clusters' ); | |||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub _build_sample_weights { | ||||||||
|
Subroutine
_build_sample_weights: not called CC=3 SCAR=24.8
| |||||||||||
| 21 | 0 | my ($self) = @_; | |||||||||
| 22 | 0 | my %sample_weights; | |||||||||
| 23 | 0 | for my $cluster_name ( keys %{ $self->clusters_to_samples } ) { | |||||||||
| 24 | 0 | my $cluster_size = @{ $self->clusters_to_samples->{$cluster_name} }; | |||||||||
| 25 | 0 | for my $sample_name ( @{ $self->clusters_to_samples->{$cluster_name} } ) { | |||||||||
| 26 | 0 | $sample_weights{$sample_name} = 1 / $cluster_size; | |||||||||
| 27 | } | ||||||||||
| 28 | } | ||||||||||
| 29 | 0 | return \%sample_weights; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub _build_samples_to_clusters { | ||||||||
|
Subroutine
_build_samples_to_clusters: not called CC=3 SCAR=24.8
| |||||||||||
| 33 | 0 | my ($self) = @_; | |||||||||
| 34 | 0 | my %samples_to_clusters; | |||||||||
| 35 | 0 | for my $cluster_name ( keys %{ $self->clusters_to_samples } ) { | |||||||||
| 36 | 0 | for my $sample_name ( @{ $self->clusters_to_samples->{$cluster_name} } ) { | |||||||||
| 37 | 0 | $samples_to_clusters{$sample_name} = $cluster_name; | |||||||||
| 38 | } | ||||||||||
| 39 | } | ||||||||||
| 40 | 0 | return \%samples_to_clusters; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 1 | ▶ | sub _build_clusters_filename { | ||||||||
|
Subroutine
_build_clusters_filename: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 1 | my ($self) = @_; | |||||||||
| 45 | 1 | return $self->_output_cd_hit_filename . '.clstr'; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 1 | ▶ | sub _build_clusters_to_samples { | ||||||||
|
Subroutine
_build_clusters_to_samples: called CC=5 SCAR=28.8
| |||||||||||
| 49 | 1 | my ($self) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 1 | my $cdhit_obj = Bio::Roary::External::Cdhit->new( | |||||||||
| 52 | input_file => $self->input_file, | ||||||||||
| 53 | output_base => $self->_output_cd_hit_filename, | ||||||||||
| 54 | _length_difference_cutoff => 1, | ||||||||||
| 55 | _sequence_identity_threshold => $self->identity, | ||||||||||
| 56 | cpus => $self->cpus | ||||||||||
| 57 | ); | ||||||||||
| 58 | 1 | $cdhit_obj->run(); | |||||||||
| 59 | 1 | my $clusterd_genes = $self->_clustered_genes; | |||||||||
| 60 | |||||||||||
| 61 | 0 | for my $cluster_name ( keys %{$clusterd_genes} ) { | |||||||||
| 62 | 0 | my $found = 0; | |||||||||
| 63 | 0 | for my $gene_name ( @{ $clusterd_genes->{$cluster_name} } ) { | |||||||||
| 64 | 0 | ▶ | if ( $gene_name eq $cluster_name ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | $found = 1; | |||||||||
| 66 | 0 | last; | |||||||||
| 67 | } | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | if ( $found == 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | push( @{ $clusterd_genes->{$cluster_name} }, $cluster_name ); | |||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 0 | return $clusterd_genes; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 79 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 80 | |||||||||||
| 81 | 2 | 1; | |||||||||
| 82 | |||||||||||
| 83 | __END__ | ||||||||||