| 1 | package Bio::Roary::External::Cdhit; | ||||||||||
| 2 | 4 | $Bio::Roary::External::Cdhit::VERSION = '3.13.0'; | |||||||||
| 3 | # ABSTRACT: Wrapper to run cd-hit | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | with 'Bio::Roary::JobRunner::Role'; | |||||||||
| 9 | |||||||||||
| 10 | 4 | has 'input_file' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 11 | 4 | has 'output_base' => ( is => 'ro', isa => 'Str', default => 'output' ); | |||||||||
| 12 | 4 | has 'exec' => ( is => 'ro', isa => 'Str', default => 'cd-hit' ); | |||||||||
| 13 | 4 | has 'alt_exec' => ( is => 'ro', isa => 'Str', default => 'cdhit' ); | |||||||||
| 14 | 4 | has '_max_available_memory_in_mb' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build__max_available_memory_in_mb' ); | |||||||||
| 15 | 4 | has '_use_most_similar_clustering' => ( is => 'ro', isa => 'Bool', default => 1 ); | |||||||||
| 16 | 4 | has '_length_difference_cutoff' => ( is => 'ro', isa => 'Num', default => 1 ); | |||||||||
| 17 | 4 | has '_sequence_identity_threshold' => ( is => 'ro', isa => 'Num', default => 1 ); | |||||||||
| 18 | 4 | has '_description_length' => ( is => 'ro', isa => 'Int', default => 256 ); | |||||||||
| 19 | 4 | has '_logging' => ( is => 'ro', isa => 'Str', default => '> /dev/null 2>&1' ); | |||||||||
| 20 | 4 | has '_max_cpus' => ( is => 'ro', isa => 'Int', default => 40 ); | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | # Overload Role | ||||||||||
| 24 | 4 | has 'memory_in_mb' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build_memory_in_mb' ); | |||||||||
| 25 | |||||||||||
| 26 | sub _build_memory_in_mb | ||||||||||
| 27 | 3 | ▶ | { | ||||||||
|
Subroutine
_build_memory_in_mb: called CC=3 SCAR=11.0
| |||||||||||
| 28 | 3 | my ($self) = @_; | |||||||||
| 29 | 3 | my $filename = $self->input_file; | |||||||||
| 30 | 3 | my $memory_required = 2000; | |||||||||
| 31 | 3 | ▶ | if(-e $filename) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | { | ||||||||||
| 33 | 1 | $memory_required = -s $filename; | |||||||||
| 34 | # Convert to mb | ||||||||||
| 35 | 1 | $memory_required = int($memory_required/1000000); | |||||||||
| 36 | # Give it bucket loads of memory for the worst case scenario | ||||||||||
| 37 | 1 | $memory_required *= 5; | |||||||||
| 38 | 1 | ▶ | $memory_required = 2000 if($memory_required < 2000); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 3 | return $memory_required; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub _build__max_available_memory_in_mb | ||||||||||
| 45 | 3 | ▶ | { | ||||||||
|
Subroutine
_build__max_available_memory_in_mb: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 3 | my ($self) = @_; | |||||||||
| 47 | 3 | my $memory_to_cdhit = int($self->memory_in_mb *0.9); | |||||||||
| 48 | 3 | return $memory_to_cdhit; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | sub clusters_filename | ||||||||||
| 52 | 0 | ▶ | { | ||||||||
|
Subroutine
clusters_filename: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 53 | 0 | my ($self) = @_; | |||||||||
| 54 | 0 | return join('.',($self->output_base,'clstr')); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 6 | ▶ | sub _command_to_run { | ||||||||
|
Subroutine
_command_to_run: called CC=2 SCAR=6.9
| |||||||||||
| 58 | 6 | my ($self) = @_; | |||||||||
| 59 | |||||||||||
| 60 | 6 | my $executable = $self->_find_exe([$self->exec, $self->alt_exec]); | |||||||||
| 61 | |||||||||||
| 62 | 6 | ▶ | my $cpus = ($self->cpus > $self->_max_cpus) ? $self->_max_cpus : $self->cpus; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 6 | return join( | |||||||||
| 64 | ' ', | ||||||||||
| 65 | ( | ||||||||||
| 66 | $executable, '-i', $self->input_file, '-o', | ||||||||||
| 67 | $self->output_base, '-T', $cpus, '-M', | ||||||||||
| 68 | $self->_max_available_memory_in_mb, '-g', $self->_use_most_similar_clustering, '-s', | ||||||||||
| 69 | $self->_length_difference_cutoff, '-d', $self->_description_length ,'-c', $self->_sequence_identity_threshold, | ||||||||||
| 70 | $self->_logging | ||||||||||
| 71 | ) | ||||||||||
| 72 | ); | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 2 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 76 | 2 | my ($self) = @_; | |||||||||
| 77 | 2 | my @commands_to_run; | |||||||||
| 78 | |||||||||||
| 79 | 2 | push(@commands_to_run, $self->_command_to_run() ); | |||||||||
| 80 | 2 | $self->logger->info( "Running command: " . $self->_command_to_run() ); | |||||||||
| 81 | 2 | my $job_runner_obj = $self->_job_runner_class->new( commands_to_run => \@commands_to_run, memory_in_mb => $self->memory_in_mb, queue => $self->_queue, cpus => $self->cpus ); | |||||||||
| 82 | 2 | $job_runner_obj->run(); | |||||||||
| 83 | |||||||||||
| 84 | 2 | 1; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 4 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 88 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 89 | |||||||||||
| 90 | 4 | 1; | |||||||||
| 91 | |||||||||||
| 92 | __END__ | ||||||||||