File Coverage

lib/Bio/Roary/External/PostAnalysis.pm
Criterion Covered Total %
statement 9 69 13.0
branch 0 22 0.0
condition 0 24 0.0
subroutine 3 11 27.2
pod 0 1 0.0
total 12 127 9.4


line stmt bran cond sub pod time code
1             package Bio::Roary::External::PostAnalysis;
2             $Bio::Roary::External::PostAnalysis::VERSION = '3.10.2';
3             # ABSTRACT: Perform the post analysis
4              
5              
6 1     1   7 use Moose;
  1         2  
  1         7  
7 1     1   5601 use Cwd qw(getcwd);
  1         2  
  1         812  
8             with 'Bio::Roary::JobRunner::Role';
9              
10             has 'input_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
11             has 'exec' => ( is => 'ro', isa => 'Str', default => 'pan_genome_post_analysis' );
12             has 'fasta_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
13             has 'output_filename' => ( is => 'ro', isa => 'Str', required => 1 );
14             has 'output_pan_geneome_filename' => ( is => 'ro', isa => 'Str', required => 1 );
15             has 'output_statistics_filename' => ( is => 'ro', isa => 'Str', required => 1 );
16             has 'clusters_filename' => ( is => 'ro', isa => 'Str', required => 1 );
17             has 'output_multifasta_files' => ( is => 'ro', isa => 'Bool', required => 1 );
18             has 'dont_delete_files' => ( is => 'ro', isa => 'Bool', default => 0 );
19             has 'dont_create_rplots' => ( is => 'rw', isa => 'Bool', default => 0 );
20             has 'dont_split_groups' => ( is => 'rw', isa => 'Bool', default => 0 );
21             has 'verbose_stats' => ( is => 'rw', isa => 'Bool', default => 0 );
22             has 'translation_table' => ( is => 'rw', isa => 'Int', default => 11 );
23             has 'group_limit' => ( is => 'rw', isa => 'Num', default => 50000 );
24             has 'core_definition' => ( is => 'ro', isa => 'Num', default => 1.0 );
25             has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 );
26             has 'mafft' => ( is => 'ro', isa => 'Bool', default => 0 );
27             has 'allow_paralogs' => ( is => 'ro', isa => 'Bool', default => 0 );
28             has '_working_directory' => ( is => 'ro', isa => 'File::Temp::Dir', default => sub { File::Temp->newdir( DIR => getcwd, CLEANUP => 1 ); } );
29             has '_gff_fofn' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build__gff_fofn' );
30             has '_fasta_fofn' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build__fasta_fofn' );
31              
32             # Overload Role
33             has 'memory_in_mb' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build_memory_in_mb' );
34             has '_minimum_memory_mb' => ( is => 'ro', isa => 'Int', default => 4000 );
35             has '_memory_per_sample_mb' => ( is => 'ro', isa => 'Int', default => 30 );
36             has '_queue' => ( is => 'rw', isa => 'Str', lazy => 1, builder => '_build__queue');
37              
38              
39             sub _build__queue {
40 0     0     my ($self) = @_;
41 0           my $queue = 'normal';
42 0           my $num_samples = @{ $self->input_files };
  0            
43 0 0         if($num_samples > 200)
    0          
44             {
45 0           $queue = 'long';
46             }
47             elsif($num_samples > 600)
48             {
49 0           $queue = 'basement';
50             }
51 0           return $queue;
52             }
53              
54              
55             sub _build_memory_in_mb {
56 0     0     my ($self) = @_;
57 0           my $num_samples = @{ $self->input_files };
  0            
58              
59 0           my $memory_required = $num_samples * $self->_memory_per_sample_mb;
60 0 0         if ( $memory_required < $self->_minimum_memory_mb ) {
61 0           $memory_required = $self->_minimum_memory_mb;
62             }
63              
64 0           return $memory_required;
65             }
66              
67             sub _build__gff_fofn
68             {
69 0     0     my ($self) = @_;
70 0           return join('/', ($self->_working_directory, '/_gff_files'));
71             }
72              
73             sub _build__fasta_fofn
74             {
75 0     0     my ($self) = @_;
76 0           return join('/', ($self->_working_directory, '/_fasta_files'));
77             }
78              
79              
80             sub _output_gff_files
81             {
82 0     0     my ($self) = @_;
83 0           open(my $out_fh, '>', $self->_gff_fofn);
84 0           for my $filename (@{$self->input_files})
  0            
85             {
86 0           print {$out_fh} $filename."\n";
  0            
87             }
88 0           close($out_fh);
89             }
90              
91             sub _output_fasta_files
92             {
93 0     0     my ($self) = @_;
94 0           open(my $out_fh, '>', $self->_fasta_fofn);
95 0           for my $filename (@{$self->fasta_files})
  0            
96             {
97 0           print {$out_fh} $filename."\n";
  0            
98             }
99 0           close($out_fh);
100             }
101              
102             sub _command_to_run {
103 0     0     my ($self) = @_;
104            
105 0           $self->_output_fasta_files;
106 0           $self->_output_gff_files;
107            
108 0           my $output_multifasta_files_flag = '';
109 0 0 0       $output_multifasta_files_flag = '--output_multifasta_files' if(defined($self->output_multifasta_files) && $self->output_multifasta_files == 1);
110              
111 0           my $dont_delete_files_flag = '';
112 0 0 0       $dont_delete_files_flag = '--dont_delete_files' if(defined($self->dont_delete_files) && $self->dont_delete_files == 1);
113            
114 0           my $dont_create_rplots_flag = '';
115 0 0 0       $dont_create_rplots_flag = '--dont_create_rplots' if(defined($self->dont_create_rplots) && $self->dont_create_rplots == 1);
116            
117 0           my $dont_split_groups_flag = '';
118 0 0 0       $dont_split_groups_flag = '--dont_split_groups' if ( defined $self->dont_split_groups && $self->dont_split_groups == 1 );
119              
120 0           my $verbose_stats_flag = '';
121 0 0 0       $verbose_stats_flag = '--verbose_stats' if ( defined($self->verbose_stats) && $self->verbose_stats == 1 );
122            
123 0           my $mafft_flag = '';
124 0 0 0       $mafft_flag = '--mafft' if ( defined($self->mafft) && $self->mafft == 1 );
125            
126 0           my $verbose_flag = '';
127 0 0 0       $verbose_flag = '-v' if ( defined($self->verbose) && $self->verbose == 1 );
128            
129 0           my $allow_paralogs_flag = '';
130 0 0 0       $allow_paralogs_flag = '--allow_paralogs' if ( defined($self->allow_paralogs) && $self->allow_paralogs == 1 );
131            
132 0           return join(
133             " ",
134             (
135             $self->exec,
136             '-o', $self->output_filename,
137             '-p', $self->output_pan_geneome_filename,
138             '-s', $self->output_statistics_filename,
139             '-c', $self->clusters_filename,
140             $output_multifasta_files_flag,
141             '-i', $self->_gff_fofn,
142             '-f', $self->_fasta_fofn,
143             '-t', $self->translation_table,
144             $dont_delete_files_flag,
145             $dont_create_rplots_flag,
146             $dont_split_groups_flag,
147             $verbose_stats_flag,
148             $verbose_flag,
149             $mafft_flag,
150             $allow_paralogs_flag,
151             '-j', $self->job_runner,
152             '--processors', $self->cpus,
153             '--group_limit', $self->group_limit,
154             '-cd', ($self->core_definition*100)
155             )
156             );
157             }
158              
159             sub run {
160 0     0 0   my ($self) = @_;
161              
162 0           my @commands_to_run;
163 0           push( @commands_to_run, $self->_command_to_run );
164 0           $self->logger->info( "Running command: " . $self->_command_to_run() );
165 0           my $job_runner_obj = $self->_job_runner_class->new(
166             commands_to_run => \@commands_to_run,
167             memory_in_mb => $self->memory_in_mb,
168             queue => $self->_queue,
169             dont_wait => $self->dont_wait,
170             cpus => $self->cpus
171             );
172 0           $job_runner_obj->run();
173              
174 0           1;
175             }
176              
177 1     1   7 no Moose;
  1         2  
  1         7  
178             __PACKAGE__->meta->make_immutable;
179             1;
180              
181             __END__
182              
183             =pod
184              
185             =encoding UTF-8
186              
187             =head1 NAME
188              
189             Bio::Roary::External::PostAnalysis - Perform the post analysis
190              
191             =head1 VERSION
192              
193             version 3.10.2
194              
195             =head1 SYNOPSIS
196              
197             Perform the post analysis
198              
199             use Bio::Roary::External::PostAnalysis;
200            
201             my $seg= Bio::Roary::External::PostAnalysis->new(
202             fasta_file => 'contigs.fa',
203             );
204            
205             $seg->run();
206              
207             =head1 AUTHOR
208              
209             Andrew J. Page <ap13@sanger.ac.uk>
210              
211             =head1 COPYRIGHT AND LICENSE
212              
213             This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
214              
215             This is free software, licensed under:
216              
217             The GNU General Public License, Version 3, June 2007
218              
219             =cut