| 1 | package Bio::Roary::FilterFullClusters; | ||||||||||||||||||||||||||||
| 2 | 2 | $Bio::Roary::FilterFullClusters::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::SeqIO; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | with 'Bio::Roary::ClustersRole'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | has 'number_of_input_files' => ( is => 'ro', isa => 'Int', required => 1 ); | |||||||||||||||||||||||||||
| 11 | 2 | has 'fasta_file' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 12 | 2 | has 'output_file' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 13 | 2 | has '_greater_than_or_equal' => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 14 | 2 | has 'cdhit_input_fasta_file' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 15 | 2 | has 'cdhit_output_fasta_file' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | has 'output_groups_file' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | has '_full_cluster_gene_names' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build__full_cluster_gene_names' ); | |||||||||||||||||||||||||||
| 20 | 2 | has '_input_seqio' => ( is => 'ro', isa => 'Bio::SeqIO', lazy => 1, builder => '_build__input_seqio' ); | |||||||||||||||||||||||||||
| 21 | 2 | has '_output_seqio' => ( is => 'ro', isa => 'Bio::SeqIO', lazy => 1, builder => '_build__output_seqio' ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | has '_all_full_cluster_genes' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build__all_full_cluster_genes' ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub _build__full_cluster_gene_names | ||||||||||||||||||||||||||||
| 26 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_build__full_cluster_gene_names: called CC=7 SCAR=22.6
| |||||||||||||||||||||||||||||
| 27 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | my %full_cluster_gene_names ; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | for my $gene_name (keys %{$self->_clustered_genes}) | |||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 10 | ▶ | if($self->_greater_than_or_equal == 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if(defined($self->_clustered_genes->{$gene_name}) && @{$self->_clustered_genes->{$gene_name}} >= ($self->number_of_input_files -1)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->_clustered_genes->{$gene_name} and @{$self->_clustered_genes->{$gene_name};} >= $self->number_of_input_files - 1
MC/DC0%0/2
defined $self->_clustered_genes->{$gene_name} and @{$self->_clustered_genes->{$gene_name};} >= $self->number_of_input_files - 1
defined $self->_clustered_genes->{$gene_name}
@{$self->_clustered_genes->{$gene_name};} >= $self->number_of_input_files - 1
Truth table0%0/3
A and B
A= defined $self->_clustered_genes->{$gene_name}B= @{$self->_clustered_genes->{$gene_name};} >= $self->number_of_input_files - 1
| |||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | 0 | $full_cluster_gene_names{$gene_name}++; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | else | ||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 10 | ▶ | if(defined($self->_clustered_genes->{$gene_name}) && @{$self->_clustered_genes->{$gene_name}} == ($self->number_of_input_files -1)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->_clustered_genes->{$gene_name} and @{$self->_clustered_genes->{$gene_name};} == $self->number_of_input_files - 1
MC/DC100%2/2
defined $self->_clustered_genes->{$gene_name} and @{$self->_clustered_genes->{$gene_name};} == $self->number_of_input_files - 1
defined $self->_clustered_genes->{$gene_name}
@{$self->_clustered_genes->{$gene_name};} == $self->number_of_input_files - 1
Truth table100%3/3
A and B
A= defined $self->_clustered_genes->{$gene_name}B= @{$self->_clustered_genes->{$gene_name};} == $self->number_of_input_files - 1
| |||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 1 | $full_cluster_gene_names{$gene_name}++; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | return \%full_cluster_gene_names; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | ▶ | sub _build__input_seqio { | ||||||||||||||||||||||||||
|
Subroutine
_build__input_seqio: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 55 | 1 | return Bio::SeqIO->new( -file => $self->fasta_file, -format => 'Fasta' ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub _build__output_seqio { | ||||||||||||||||||||||||||
|
Subroutine
_build__output_seqio: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 1 | my ( $self, $chunk_number ) = @_; | |||||||||||||||||||||||||||
| 60 | 1 | return Bio::SeqIO->new( -file => ">".$self->output_file, -format => 'Fasta' ); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub _build__all_full_cluster_genes | ||||||||||||||||||||||||||||
| 64 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_build__all_full_cluster_genes: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 65 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 66 | 1 | my %full_cluster_genes; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | for my $gene_name (keys %{$self->_full_cluster_gene_names}) | |||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||
| 70 | 1 | $full_cluster_genes{$gene_name}++; | |||||||||||||||||||||||||||
| 71 | 1 | for my $cluster_gene_name (@{$self->_clustered_genes->{$gene_name}}) | |||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 5 | $full_cluster_genes{$cluster_gene_name}++; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 1 | return \%full_cluster_genes; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub _create_groups_file | ||||||||||||||||||||||||||||
| 81 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_create_groups_file: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 82 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 83 | 1 | open(my $out_fh, '>>', $self->output_groups_file); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | for my $gene_name (keys %{$self->_full_cluster_gene_names}) | |||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||
| 87 | 1 | print {$out_fh} $gene_name."\t". join("\t", @{$self->_clustered_genes->{$gene_name}}). "\n"; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 1 | close($out_fh); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub filter_complete_cluster_from_original_fasta | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
filter_complete_cluster_from_original_fasta: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | my $input_seq_io = Bio::SeqIO->new( -file => $self->cdhit_input_fasta_file, -format => 'Fasta' ); | |||||||||||||||||||||||||||
| 99 | 1 | my $output_seq_io = Bio::SeqIO->new( -file => ">".$self->cdhit_output_fasta_file, -format => 'Fasta' ); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | ▶ | while ( my $input_seq = $input_seq_io->next_seq() ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | 30 | ▶ | unless(defined($self->_all_full_cluster_genes->{$input_seq->display_id})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 24 | $output_seq_io->write_seq($input_seq); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | $self->_create_groups_file; | |||||||||||||||||||||||||||
| 110 | 1 | return $self; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | sub filter_full_clusters_from_fasta | ||||||||||||||||||||||||||||
| 114 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
filter_full_clusters_from_fasta: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | while ( my $input_seq = $self->_input_seqio->next_seq() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 10 | ▶ | unless(defined($self->_full_cluster_gene_names->{$input_seq->display_id})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||
| 120 | 9 | $self->_output_seqio->write_seq($input_seq); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 1 | return $self; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 127 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 2 | 1; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||