| 1 | package Bio::Roary::AccessoryBinaryFasta; | ||||||||||||||||||||||||||||
| 2 | 2 | $Bio::Roary::AccessoryBinaryFasta::VERSION = '3.13.0'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Output a FASTA file which represents the binary presence and absence of genes in the accessory genome | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use POSIX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Bio::Roary::AnnotateGroups; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Bio::Roary::AnalyseGroups; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Bio::Roary::Exceptions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Bio::SeqIO; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | has 'input_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | |||||||||||||||||||||||||||
| 15 | 2 | has 'annotate_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnnotateGroups', required => 1 ); | |||||||||||||||||||||||||||
| 16 | 2 | has 'analyse_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnalyseGroups', required => 1 ); | |||||||||||||||||||||||||||
| 17 | 2 | has 'output_filename' => ( is => 'ro', isa => 'Str', default => 'accessory_binary_genes.fa' ); | |||||||||||||||||||||||||||
| 18 | 2 | has 'lower_bound_percentage' => ( is => 'ro', isa => 'Int', default => 5 ); | |||||||||||||||||||||||||||
| 19 | 2 | has 'upper_bound_percentage' => ( is => 'ro', isa => 'Int', default => 5 ); | |||||||||||||||||||||||||||
| 20 | 2 | has 'max_accessory_to_include' => ( is => 'ro', isa => 'Int', default => 4000 ); | |||||||||||||||||||||||||||
| 21 | 2 | has 'groups_to_files' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build__groups_to_files' ); | |||||||||||||||||||||||||||
| 22 | 2 | has '_lower_bound_value' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build__lower_bound_value' ); | |||||||||||||||||||||||||||
| 23 | 2 | has '_upper_bound_value' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build__upper_bound_value' ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub _build__groups_to_files { | ||||||||||||||||||||||||||
|
Subroutine
_build__groups_to_files: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 26 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 27 | 0 | my %groups_to_files; | |||||||||||||||||||||||||||
| 28 | 0 | for my $group ( @{ $self->annotate_groups_obj->_groups } ) { | |||||||||||||||||||||||||||
| 29 | 0 | my $genes = $self->annotate_groups_obj->_groups_to_id_names->{$group}; | |||||||||||||||||||||||||||
| 30 | 0 | my %filenames; | |||||||||||||||||||||||||||
| 31 | 0 | for my $gene_name ( @{$genes} ) { | |||||||||||||||||||||||||||
| 32 | 0 | my $filename = $self->analyse_groups_obj->_genes_to_file->{$gene_name}; | |||||||||||||||||||||||||||
| 33 | 0 | push( @{ $filenames{$filename} }, $gene_name ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 0 | $groups_to_files{$group} = \%filenames; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | return \%groups_to_files; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub _build__lower_bound_value { | ||||||||||||||||||||||||||
|
Subroutine
_build__lower_bound_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 43 | 1 | my $num_files = @{ $self->input_files }; | |||||||||||||||||||||||||||
| 44 | 1 | return ceil( $num_files * ( $self->lower_bound_percentage / 100 ) ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | sub _build__upper_bound_value { | ||||||||||||||||||||||||||
|
Subroutine
_build__upper_bound_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 49 | 1 | my $num_files = @{ $self->input_files }; | |||||||||||||||||||||||||||
| 50 | 1 | return $num_files - ceil( $num_files * ( $self->upper_bound_percentage / 100 ) ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | sub create_accessory_binary_fasta { | ||||||||||||||||||||||||||
|
Subroutine
create_accessory_binary_fasta: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 55 | 2 | my $out_seq_io = Bio::SeqIO->new( -file => ">" . $self->output_filename, -format => 'Fasta' ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | for my $full_filename ( @{ $self->input_files } ) { | |||||||||||||||||||||||||||
| 58 | 8 | my($filename, $dirs, $suffix) = fileparse($full_filename); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 8 | my $output_sequence = ''; | |||||||||||||||||||||||||||
| 61 | 8 | my $sample_name = $filename; | |||||||||||||||||||||||||||
| 62 | 8 | $sample_name =~ s!\.gff\.proteome\.faa!!; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 8 | my $gene_count = 0; | |||||||||||||||||||||||||||
| 65 | 8 | for my $group ( sort keys %{ $self->groups_to_files } ) { | |||||||||||||||||||||||||||
| 66 | 32 | ▶ | last if($gene_count > $self->max_accessory_to_include); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 32 | my @files = keys %{ $self->groups_to_files->{$group} }; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 32 | ▶ | next if ( @files <= $self->_lower_bound_value || @files > $self->_upper_bound_value ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@files <= $self->_lower_bound_value or @files > $self->_upper_bound_value
MC/DC100%2/2
@files <= $self->_lower_bound_value or @files > $self->_upper_bound_value
@files <= $self->_lower_bound_value
@files > $self->_upper_bound_value
Truth table100%3/3
A or B
A= @files <= $self->_lower_bound_valueB= @files > $self->_upper_bound_value
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 24 | my $group_to_file_genes = $self->groups_to_files->{$group}->{$full_filename}; | |||||||||||||||||||||||||||
| 73 | 24 | ▶ | if ( defined($group_to_file_genes) && @{$group_to_file_genes} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $group_to_file_genes and @{$group_to_file_genes;} > 0
MC/DC50%1/2
defined $group_to_file_genes and @{$group_to_file_genes;} > 0
defined $group_to_file_genes
@{$group_to_file_genes;} > 0
Truth table66%2/3
A and B
A= defined $group_to_file_genesB= @{$group_to_file_genes;} > 0
| |||||||||||||||||||||||||||||
| 74 | 15 | $output_sequence .= 'A'; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||
| 77 | 9 | $output_sequence .= 'C'; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 24 | $gene_count++; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 8 | ▶ | next if($output_sequence eq ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 8 | $out_seq_io->write_seq( Bio::Seq->new( -display_id => $sample_name, -seq => $output_sequence ) ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 2 | return 1; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 2 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||