| 1 | package Bio::Roary::External::GeneAlignmentFromNucleotides; | ||||||||||||||||||||||||||||
| 2 | 1 | $Bio::Roary::External::GeneAlignmentFromNucleotides::VERSION = '3.13.0'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Take in multi-FASTA files of nucleotides and align each file with PRANK or MAFFT | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | with 'Bio::Roary::JobRunner::Role'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | has 'fasta_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | |||||||||||||||||||||||||||
| 10 | 1 | has 'exec' => ( is => 'ro', isa => 'Str', default => 'protein_alignment_from_nucleotides' ); | |||||||||||||||||||||||||||
| 11 | 1 | has 'translation_table' => ( is => 'rw', isa => 'Int', default => 11 ); | |||||||||||||||||||||||||||
| 12 | 1 | has 'core_definition' => ( is => 'ro', isa => 'Num', default => 1 ); | |||||||||||||||||||||||||||
| 13 | 1 | has 'mafft' => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 14 | 1 | has 'dont_delete_files' => ( is => 'rw', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 15 | 1 | has 'allow_paralogs' => ( is => 'rw', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 16 | 1 | has 'num_input_files' => ( is => 'ro', isa => 'Int', required => 1); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Overload Role` | ||||||||||||||||||||||||||||
| 19 | 1 | has 'memory_in_mb' => ( is => 'rw', isa => 'Int', lazy => 1, builder => '_build_memory_in_mb' ); | |||||||||||||||||||||||||||
| 20 | 1 | has '_min_memory_in_mb' => ( is => 'ro', isa => 'Int', default => 1500 ); | |||||||||||||||||||||||||||
| 21 | 1 | has '_max_memory_in_mb' => ( is => 'ro', isa => 'Int', default => 60000 ); | |||||||||||||||||||||||||||
| 22 | 1 | has '_queue' => ( is => 'rw', isa => 'Str', default => 'normal' ); | |||||||||||||||||||||||||||
| 23 | 1 | has '_files_per_chunk' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build__files_per_chunk' ); | |||||||||||||||||||||||||||
| 24 | 1 | has '_core_alignment_cmd' => ( is => 'rw', isa => 'Str', lazy_build => 1 ); | |||||||||||||||||||||||||||
| 25 | 1 | has '_dependancy_memory_in_mb' => ( is => 'ro', isa => 'Int', default => 15000 ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub _build__files_per_chunk | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_build__files_per_chunk: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 30 | 0 | return 1; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub _build_memory_in_mb { | ||||||||||||||||||||||||||
|
Subroutine
_build_memory_in_mb: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 34 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $largest_file_size = 1; | |||||||||||||||||||||||||||
| 37 | 0 | for my $file (@{$self->fasta_files}) | |||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||
| 39 | 0 | my $file_size = -s $file; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | if($file_size > $largest_file_size) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 0 | $largest_file_size = $file_size; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | my $approx_sequence_length_of_largest_file = $largest_file_size/ $self->num_input_files; | |||||||||||||||||||||||||||
| 47 | 0 | my $memory_required = int((($approx_sequence_length_of_largest_file*$approx_sequence_length_of_largest_file)/1000000)*2 + $self->_min_memory_in_mb); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $memory_required = $self->_max_memory_in_mb if($memory_required > $self->_max_memory_in_mb); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | return $memory_required; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub _command_to_run { | ||||||||||||||||||||||||||
|
Subroutine
_command_to_run: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 55 | 0 | my ( $self, $fasta_files) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | my $verbose = ""; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if($self->verbose) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 0 | $verbose = ' -v '; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 0 | my $mafft_str = ""; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | $mafft_str = ' --mafft ' if($self->mafft); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | return $self->exec." ".$verbose.$mafft_str.join( " ", @{$fasta_files} ); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub _build__core_alignment_cmd { | ||||||||||||||||||||||||||
|
Subroutine
_build__core_alignment_cmd: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 67 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $core_cmd = "pan_genome_core_alignment"; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | $core_cmd .= " -cd " . ($self->core_definition*100) if ( defined $self->core_definition ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $core_cmd .= " --dont_delete_files " if ( defined $self->dont_delete_files && $self->dont_delete_files == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->dont_delete_files and $self->dont_delete_files == 1
MC/DC0%0/2
defined $self->dont_delete_files and $self->dont_delete_files == 1
defined $self->dont_delete_files
$self->dont_delete_files == 1
Truth table0%0/3
A and B
A= defined $self->dont_delete_filesB= $self->dont_delete_files == 1
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $core_cmd .= " --allow_paralogs " if ( defined $self->allow_paralogs && $self->allow_paralogs == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->allow_paralogs and $self->allow_paralogs == 1
MC/DC0%0/2
defined $self->allow_paralogs and $self->allow_paralogs == 1
defined $self->allow_paralogs
$self->allow_paralogs == 1
Truth table0%0/3
A and B
A= defined $self->allow_paralogsB= $self->allow_paralogs == 1
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | return $core_cmd; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 79 | 0 | my @commands_to_run; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | my @files_chunk; | ||||||||||||||||||||||||||||
| 82 | 0 | for my $fasta_file ( @{ $self->fasta_files } ) { | |||||||||||||||||||||||||||
| 83 | 0 | push(@files_chunk,$fasta_file); | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | if(@files_chunk == $self->_files_per_chunk ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 0 | push(@commands_to_run, $self->_command_to_run(\@files_chunk)); | |||||||||||||||||||||||||||
| 87 | 0 | $self->logger->info( "Running command: " . $self->_command_to_run(\@files_chunk) ); | |||||||||||||||||||||||||||
| 88 | 0 | @files_chunk = (); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if(@files_chunk > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||
| 94 | 0 | push(@commands_to_run, $self->_command_to_run(\@files_chunk)); | |||||||||||||||||||||||||||
| 95 | 0 | $self->logger->info( "Running command: " . $self->_command_to_run(\@files_chunk) ); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | my $job_runner_obj = $self->_job_runner_class->new( | |||||||||||||||||||||||||||
| 99 | commands_to_run => \@commands_to_run, | ||||||||||||||||||||||||||||
| 100 | memory_in_mb => $self->memory_in_mb, | ||||||||||||||||||||||||||||
| 101 | queue => $self->_queue, | ||||||||||||||||||||||||||||
| 102 | dont_wait => 1, | ||||||||||||||||||||||||||||
| 103 | cpus => $self->cpus | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | 0 | $job_runner_obj->run(); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | $job_runner_obj->memory_in_mb($self->_dependancy_memory_in_mb); | |||||||||||||||||||||||||||
| 108 | 0 | $self->logger->info( "Running command: " . $self->_core_alignment_cmd() ); | |||||||||||||||||||||||||||
| 109 | 0 | $job_runner_obj->submit_dependancy_job($self->_core_alignment_cmd); | |||||||||||||||||||||||||||
| 110 | 0 | 1; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 115 | 1 | 1; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||