lib/Bio/Roary/PostAnalysis.pm

filter: Statementstmt 49.7% 97 / 195 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 51.4% 18 / 35 Podpod 0.0% 0 / 1 totaltotal 44.4% 115 / 259 CC 13 SCAR 24.8
CC
13
Cov
44%
run
56.0
_delete_intermediate_files
20.0
_build__accessory_clustering
12.0
CRAP 12.0
« lib/Bio/Roary/CommandLine/QueryRoary.pm ↑ Summary lib/Bio/Roary/AccessoryClustering.pm »
1 package Bio::Roary::PostAnalysis;
2 1 $Bio::Roary::PostAnalysis::VERSION = '3.13.0';
3 # ABSTRACT: Post analysis of pan genomes
4  
5  
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Bio::Roary::InflateClusters;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Bio::Roary::AnalyseGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Bio::Roary::GroupLabels;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Bio::Roary::AnnotateGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Bio::Roary::GroupStatistics;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Bio::Roary::Output::GroupsMultifastasNucleotide;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Bio::Roary::Output::NumberOfGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Bio::Roary::OrderGenes;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Bio::Roary::Output::EmblGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Bio::Roary::SplitGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Bio::Roary::AccessoryBinaryFasta;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Bio::Roary::External::Fasttree;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Bio::Roary::AccessoryClustering;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Bio::Roary::AssemblyStatistics;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Log::Log4perl qw(:easy);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 has 'fasta_files' => ( is => 'rw', isa => 'ArrayRef', required => 1 );
25 1 has 'input_files' => ( is => 'rw', isa => 'ArrayRef', required => 1 );
26 1 has 'output_filename' => ( is => 'rw', isa => 'Str', default => 'clustered_proteins' );
27 1 has 'output_pan_geneome_filename' => ( is => 'rw', isa => 'Str', default => 'pan_genome.fa' );
28 1 has 'output_statistics_filename' => ( is => 'rw', isa => 'Str', default => 'gene_presence_absence.csv' );
29 1 has 'output_multifasta_files' => ( is => 'ro', isa => 'Bool', default => 0 );
30 1 has 'verbose_stats' => ( is => 'rw', isa => 'Bool', default => 0 );
31 1 has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 );
32 1 has 'cpus' => ( is => 'ro', isa => 'Int', default => 1 );
33  
34 1 has 'clusters_filename' => ( is => 'rw', isa => 'Str', required => 1 );
35 1 has 'dont_delete_files' => ( is => 'ro', isa => 'Bool', default => 0 );
36 1 has 'dont_split_groups' => ( is => 'ro', isa => 'Bool', default => 0 );
37 1 has 'dont_create_rplots' => ( is => 'rw', isa => 'Bool', default => 1 );
38 1 has 'group_limit' => ( is => 'rw', isa => 'Num', default => 50000 );
39  
40 1 has '_output_mcl_filename' => ( is => 'ro', isa => 'Str', default => '_uninflated_mcl_groups' );
41 1 has '_output_inflate_unsplit_clusters_filename' => ( is => 'ro', isa => 'Str', default => '_inflated_unsplit_mcl_groups' );
42 1 has '_output_inflate_clusters_filename' => ( is => 'ro', isa => 'Str', default => '_inflated_mcl_groups' );
43 1 has '_output_group_labels_filename' => ( is => 'ro', isa => 'Str', default => '_labeled_mcl_groups' );
44 1 has '_output_combined_filename' => ( is => 'ro', isa => 'Str', default => '_combined_files' );
45 1 has '_input_cd_hit_groups_file' => ( is => 'ro', isa => 'Str', default => '_combined_files.groups' );
46 1 has 'core_accessory_tab_output_filename' => ( is => 'ro', isa => 'Str', default => 'core_accessory.tab' );
47 1 has 'accessory_tab_output_filename' => ( is => 'ro', isa => 'Str', default => 'accessory.tab' );
48 1 has 'core_accessory_ordering_key' => ( is => 'ro', isa => 'Str', default => 'core_accessory_overall_order_filtered' );
49 1 has 'accessory_ordering_key' => ( is => 'ro', isa => 'Str', default => 'accessory_overall_order_filtered' );
50 1 has 'core_definition' => ( is => 'ro', isa => 'Num', default => 1.0 );
51 1 has 'pan_genome_reference_filename' => ( is => 'ro', isa => 'Str', default => 'pan_genome_reference.fa' );
52  
53 1 has '_inflate_clusters_obj' => ( is => 'ro', isa => 'Bio::Roary::InflateClusters', lazy => 1, builder => '_build__inflate_clusters_obj' );
54 1 has '_group_labels_obj' => ( is => 'ro', isa => 'Bio::Roary::GroupLabels', lazy => 1, builder => '_build__group_labels_obj' );
55 1 has '_annotate_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnnotateGroups', lazy => 1, builder => '_build__annotate_groups_obj' );
56 1 has '_analyse_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnalyseGroups', lazy => 1, builder => '_build__analyse_groups_obj' );
57 1 has '_order_genes_obj' => ( is => 'ro', isa => 'Bio::Roary::OrderGenes', lazy => 1, builder => '_build__order_genes_obj' );
58 1 has '_group_statistics_obj' => ( is => 'ro', isa => 'Bio::Roary::GroupStatistics', lazy => 1, builder => '_build__group_statistics_obj' );
59 1 has '_number_of_groups_obj' =>
60 ( is => 'ro', isa => 'Bio::Roary::Output::NumberOfGroups', lazy => 1, builder => '_build__number_of_groups_obj' );
61 1 has '_accessory_binary_fasta' =>
62 ( is => 'ro', isa => 'Bio::Roary::AccessoryBinaryFasta', lazy => 1, builder => '_build__accessory_binary_fasta' );
63 1 has '_groups_multifastas_nuc_obj' =>
64 ( is => 'ro', isa => 'Bio::Roary::Output::GroupsMultifastasNucleotide', lazy => 1, builder => '_build__groups_multifastas_nuc_obj' );
65 1 has '_split_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::SplitGroups', lazy => 1, builder => '_build__split_groups_obj' );
66 1 has '_accessory_binary_tree' =>
67 ( is => 'ro', isa => 'Bio::Roary::External::Fasttree', lazy => 1, builder => '_build__accessory_binary_tree' );
68 1 has '_accessory_clustering' =>
69 ( is => 'ro', isa => 'Maybe[Bio::Roary::AccessoryClustering]', lazy => 1, builder => '_build__accessory_clustering' );
70 1 has '_assembly_statistics' => ( is => 'ro', isa => 'Bio::Roary::AssemblyStatistics', lazy => 1, builder => '_build__assembly_statistics' );
71  
72 1 has 'logger' => ( is => 'ro', lazy => 1, builder => '_build_logger' );
73  
74 0 ▶sub _build_logger {
Subroutine _build_logger: not called CC=1 SCAR=6.9
75 0 my ($self) = @_;
76 0 Log::Log4perl->easy_init( level => $ERROR );
77 0 my $logger = get_logger();
78 0 return $logger;
79 }
80  
81 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod undocumented
82 0 my ($self) = @_;
83  
84 0 $self->logger->info("Reinflate clusters");
85 0 $self->_inflate_clusters_obj->inflate();
86  
87 0 $self->logger->info("Split groups with paralogs");
88 ## SPLIT GROUPS WITH PARALOGS ##
89 0 ▶ if ( $self->dont_split_groups ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dont_split_groups) { } 0 0 0
90 0 move( $self->_output_inflate_unsplit_clusters_filename, $self->_output_inflate_clusters_filename );
91 }
92 else {
93 0 $self->_split_groups_obj->split_groups;
94 }
95  
96 0 $self->logger->info("Labelling the groups");
97 0 $self->_group_labels_obj->add_labels();
98  
99 0 $self->logger->info("Transfering the annotation to the groups");
100 0 $self->_annotate_groups_obj->reannotate;
101  
102 0 $self->logger->info("Creating accessory binary gene presence and absence fasta");
103 0 $self->_accessory_binary_fasta->create_accessory_binary_fasta;
104  
105 0 $self->logger->info("Creating accessory binary gene presence and absence tree");
106 0 $self->_accessory_binary_tree->run;
107  
108 0 $self->logger->info("Creating accessory gene presence and absence clusters");
109 0 ▶ if ( $self->_accessory_clustering ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_accessory_clustering) 0 0 0
110 0 $self->_accessory_clustering->sample_weights;
111 }
112  
113 0 $self->logger->info("Creating the spreadsheet with gene presence and absence");
114 0 $self->_group_statistics_obj->create_spreadsheet;
115 0 $self->_group_statistics_obj->create_rtab;
116  
117 0 $self->logger->info("Creating summary statistics of the spreadsheet");
118 0 $self->_assembly_statistics->create_summary_output;
119  
120 0 $self->logger->info("Creating tab files for R");
121 0 $self->_number_of_groups_obj->create_output_files;
122  
123 0 ▶ system("create_pan_genome_plots.R") unless ( $self->dont_create_rplots == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dont_create_rplots == 1 0 0 0
124  
125 0 $self->logger->info("Create EMBL files");
126 0 $self->_create_embl_files;
127  
128 0 my $clusters_not_exceeded = 1;
129 0 ▶ if ( $self->output_multifasta_files ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->output_multifasta_files) 0 0 0
130 0 $self->logger->info("Creating files with the nucleotide sequences for every cluster");
131 0 $clusters_not_exceeded = $self->_groups_multifastas_nuc_obj->create_files();
132 }
133  
134 0 $self->_delete_intermediate_files;
135 0 ▶ if ( $clusters_not_exceeded == 0 && $self->output_multifasta_files ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($clusters_not_exceeded == 0 and $self->output_multifasta_files) 0 0 0
Condition0%0/3
$clusters_not_exceeded == 0 and $self->output_multifasta_files
!ll&&!rl&&r
000
MC/DC0%0/2
$clusters_not_exceeded == 0 and $self->output_multifasta_files
$clusters_not_exceeded == 0 $self->output_multifasta_files
Truth table0%0/3
A and B
A= $clusters_not_exceeded == 0B= $self->output_multifasta_files
ABresult
0X0
100
111
136 0 $self->logger->error("Exiting early because number of clusters is too high");
137 0 exit();
138 }
139 }
140  
141 0 ▶sub _build__assembly_statistics {
Subroutine _build__assembly_statistics: not called CC=1 SCAR=6.9
142 0 my ($self) = @_;
143 0 return Bio::Roary::AssemblyStatistics->new(
144 spreadsheet => $self->_group_statistics_obj->output_filename,
145 core_definition => $self->core_definition,
146 logger => $self->logger
147 );
148 }
149  
150 0 ▶sub _build__accessory_clustering {
Subroutine _build__accessory_clustering: not called CC=3 SCAR=24.8
151 0 my ($self) = @_;
152 0 ▶ if ( ( -e $self->_accessory_binary_fasta->output_filename ) && ( -s $self->_accessory_binary_fasta->output_filename > 5 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->_accessory_binary_fasta->output_filename and -s $self->_accessory_binary_fasta->output_filename > 5) { } 0 0 0
Condition0%0/3
-e $self->_accessory_binary_fasta->output_filename and -s $self->_accessory_binary_fasta->output_filename > 5
!ll&&!rl&&r
000
MC/DC0%0/2
-e $self->_accessory_binary_fasta->output_filename and -s $self->_accessory_binary_fasta->output_filename > 5
-e $self->_accessory_binary_fasta->output_filename -s $self->_accessory_binary_fasta->output_filename > 5
Truth table0%0/3
A and B
A= -e $self->_accessory_binary_fasta->output_filenameB= -s $self->_accessory_binary_fasta->output_filename > 5
ABresult
0X0
100
111
153 0 $self->logger->info( $self->_accessory_binary_fasta->output_filename );
154 0 return Bio::Roary::AccessoryClustering->new(
155 input_file => $self->_accessory_binary_fasta->output_filename,
156 cpus => $self->cpus,
157 logger => $self->logger
158 );
159 }
160 else {
161 0 $self->logger->info("Theres no accessory binary file so skipping accessory binary clustering");
162 0 return undef;
163 }
164  
165 }
166  
167 0 ▶sub _build__accessory_binary_tree {
Subroutine _build__accessory_binary_tree: not called CC=1 SCAR=6.9
168 0 my ($self) = @_;
169 0 return Bio::Roary::External::Fasttree->new(
170 input_file => $self->_accessory_binary_fasta->output_filename,
171 verbose => $self->verbose,
172 logger => $self->logger
173 );
174 }
175  
176 0 ▶sub _build__accessory_binary_fasta {
Subroutine _build__accessory_binary_fasta: not called CC=1 SCAR=6.9
177 0 my ($self) = @_;
178 0 return Bio::Roary::AccessoryBinaryFasta->new(
179 input_files => $self->fasta_files,
180 annotate_groups_obj => $self->_annotate_groups_obj,
181 analyse_groups_obj => $self->_analyse_groups_obj,
182 logger => $self->logger
183 );
184 }
185  
186 0 ▶sub _build__split_groups_obj {
Subroutine _build__split_groups_obj: not called CC=1 SCAR=6.9
187 0 my ($self) = @_;
188 0 return Bio::Roary::SplitGroups->new(
189 groupfile => $self->_output_inflate_unsplit_clusters_filename,
190 gff_files => $self->input_files,
191 fasta_files => $self->fasta_files,
192 outfile => $self->_output_inflate_clusters_filename,
193 dont_delete => $self->dont_delete_files,
194 logger => $self->logger
195 );
196 }
197  
198 0 ▶sub _build__number_of_groups_obj {
Subroutine _build__number_of_groups_obj: not called CC=1 SCAR=6.9
199 0 my ($self) = @_;
200 0 return Bio::Roary::Output::NumberOfGroups->new(
201 group_statistics_obj => $self->_group_statistics_obj,
202 groups_to_contigs => $self->_order_genes_obj->groups_to_contigs,
203 annotate_groups_obj => $self->_annotate_groups_obj,
204 core_definition => $self->core_definition,
205 logger => $self->logger
206 );
207 }
208  
209 0 ▶sub _build__group_statistics_obj {
Subroutine _build__group_statistics_obj: not called CC=1 SCAR=6.9
210 0 my ($self) = @_;
211 0 return Bio::Roary::GroupStatistics->new(
212 output_filename => $self->output_statistics_filename,
213 annotate_groups_obj => $self->_annotate_groups_obj,
214 analyse_groups_obj => $self->_analyse_groups_obj,
215 groups_to_contigs => $self->_order_genes_obj->groups_to_contigs,
216 _verbose => $self->verbose_stats,
217 logger => $self->logger
218 );
219 }
220  
221 0 ▶sub _build__order_genes_obj {
Subroutine _build__order_genes_obj: not called CC=2 SCAR=17.9
222 0 my ($self) = @_;
223 0 ▶ if ( defined( $self->_accessory_clustering ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_accessory_clustering) { } 0 0 0
224 0 return Bio::Roary::OrderGenes->new(
225 analyse_groups_obj => $self->_analyse_groups_obj,
226 gff_files => $self->input_files,
227 core_definition => $self->core_definition,
228 sample_weights => $self->_accessory_clustering->sample_weights,
229 samples_to_clusters => $self->_accessory_clustering->samples_to_clusters,
230 logger => $self->logger
231 );
232 }
233 else {
234 0 return Bio::Roary::OrderGenes->new(
235 analyse_groups_obj => $self->_analyse_groups_obj,
236 gff_files => $self->input_files,
237 core_definition => $self->core_definition,
238 logger => $self->logger
239 );
240 }
241 }
242  
243 0 ▶sub _build__group_labels_obj {
Subroutine _build__group_labels_obj: not called CC=1 SCAR=6.9
244 0 my ($self) = @_;
245 0 return Bio::Roary::GroupLabels->new(
246 groups_filename => $self->_output_inflate_clusters_filename,
247 output_filename => $self->_output_group_labels_filename,
248 logger => $self->logger
249 );
250 }
251  
252 0 ▶sub _build__annotate_groups_obj {
Subroutine _build__annotate_groups_obj: not called CC=1 SCAR=6.9
253 0 my ($self) = @_;
254 0 return Bio::Roary::AnnotateGroups->new(
255 gff_files => $self->input_files,
256 output_filename => $self->output_filename,
257 groups_filename => $self->_output_group_labels_filename,
258 logger => $self->logger
259 );
260 }
261  
262 0 ▶sub _build__analyse_groups_obj {
Subroutine _build__analyse_groups_obj: not called CC=1 SCAR=6.9
263 0 my ($self) = @_;
264 0 return Bio::Roary::AnalyseGroups->new(
265 fasta_files => $self->fasta_files,
266 groups_filename => $self->output_filename,
267 logger => $self->logger
268 );
269 }
270  
271 0 ▶sub _build__inflate_clusters_obj {
Subroutine _build__inflate_clusters_obj: not called CC=1 SCAR=6.9
272 0 my ($self) = @_;
273 0 return Bio::Roary::InflateClusters->new(
274 clusters_filename => $self->clusters_filename,
275 cdhit_groups_filename => $self->_input_cd_hit_groups_file,
276 mcl_filename => $self->_output_mcl_filename,
277 output_file => $self->_output_inflate_unsplit_clusters_filename,
278 logger => $self->logger
279 );
280 }
281  
282 0 ▶sub _build__groups_multifastas_nuc_obj {
Subroutine _build__groups_multifastas_nuc_obj: not called CC=1 SCAR=6.9
283 0 my ($self) = @_;
284 0 return Bio::Roary::Output::GroupsMultifastasNucleotide->new(
285 output_multifasta_files => $self->output_multifasta_files,
286 gff_files => $self->input_files,
287 annotate_groups => $self->_annotate_groups_obj,
288 group_names => $self->_analyse_groups_obj->_groups,
289 group_limit => $self->group_limit,
290 core_definition => $self->core_definition,
291 dont_delete_files => $self->dont_delete_files,
292 logger => $self->logger
293 );
294 }
295  
296 0 ▶sub _create_embl_files {
Subroutine _create_embl_files: not called CC=1 SCAR=6.9
297 0 my ($self) = @_;
298 0 my $core_accessory_tab_obj = Bio::Roary::Output::EmblGroups->new(
299 output_filename => $self->core_accessory_tab_output_filename,
300 annotate_groups_obj => $self->_annotate_groups_obj,
301 analyse_groups_obj => $self->_analyse_groups_obj,
302 ordering_key => $self->core_accessory_ordering_key,
303 groups_to_contigs => $self->_order_genes_obj->groups_to_contigs,
304 logger => $self->logger
305 );
306 0 $core_accessory_tab_obj->create_files;
307  
308 0 my $accessory_tab_obj = Bio::Roary::Output::EmblGroups->new(
309 output_filename => $self->accessory_tab_output_filename,
310 annotate_groups_obj => $self->_annotate_groups_obj,
311 analyse_groups_obj => $self->_analyse_groups_obj,
312 ordering_key => $self->accessory_ordering_key,
313 groups_to_contigs => $self->_order_genes_obj->groups_to_contigs,
314 logger => $self->logger
315 );
316 0 $accessory_tab_obj->create_files;
317 }
318  
319 0 ▶sub _delete_intermediate_files {
Subroutine _delete_intermediate_files: not called CC=4 SCAR=30.0
320 0 my ($self) = @_;
321 0 ▶ return if ( $self->dont_delete_files == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->dont_delete_files == 1 0 0 0
322 0 $self->logger->info("Cleaning up files");
323  
324 0 for my $fasta_file ( @{ $self->fasta_files } ) {
325 0 ▶ unlink($fasta_file) if ( -e $fasta_file );
Branch: 1 branch
BranchTrueFalseTotal
if -e $fasta_file 0 0 0
326 }
327  
328 0 unlink( $self->_output_mcl_filename );
329 0 unlink( $self->_output_inflate_clusters_filename );
330 0 unlink( $self->_output_group_labels_filename );
331 0 unlink( $self->_output_combined_filename );
332 0 unlink( $self->clusters_filename );
333 0 unlink( $self->clusters_filename . '.clstr' );
334 0 unlink( $self->clusters_filename . '.bak.clstr' );
335 0 unlink('_gff_files');
336 0 unlink('_fasta_files');
337 0 unlink('_clustered_filtered.fa');
338 0 unlink( $self->_input_cd_hit_groups_file );
339 0 unlink('database_masking.asnb');
340 0 unlink('_clustered');
341 0 unlink('_accessory_clusters');
342 0 unlink('_accessory_clusters.clstr');
343 }
344  
345 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
346 1 __PACKAGE__->meta->make_immutable;
347  
348 1 1;
349  
350 __END__
« lib/Bio/Roary/CommandLine/QueryRoary.pm ↑ Summary lib/Bio/Roary/AccessoryClustering.pm »