File Coverage

lib/Bio/Roary/CommandLine/RoaryCoreAlignment.pm
Criterion Covered Total %
statement 57 62 91.9
branch 21 28 75.0
condition 4 6 66.6
subroutine 11 11 100.0
pod 0 3 0.0
total 93 110 84.5


line stmt bran cond sub pod time code
1             undef $VERSION;
2             package Bio::Roary::CommandLine::RoaryCoreAlignment;
3             $Bio::Roary::CommandLine::RoaryCoreAlignment::VERSION = '3.11.0';
4             # ABSTRACT: Take in the group statistics spreadsheet and the location of the gene multifasta files and create a core alignment.
5              
6              
7 1     1   460062 use Moose;
  1         8  
  1         7  
8 1     1   6230 use Getopt::Long qw(GetOptionsFromArray);
  1         7700  
  1         3  
9 1     1   128 use Cwd 'abs_path';
  1         1  
  1         38  
10 1     1   5 use File::Path qw(remove_tree);
  1         2  
  1         46  
11 1     1   276 use Bio::Roary::ExtractCoreGenesFromSpreadsheet;
  1         3  
  1         39  
12 1     1   396 use Bio::Roary::LookupGeneFiles;
  1         2  
  1         31  
13 1     1   278 use Bio::Roary::MergeMultifastaAlignments;
  1         3  
  1         500  
14             extends 'Bio::Roary::CommandLine::Common';
15              
16             has 'args' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
17             has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 );
18             has 'help' => ( is => 'rw', isa => 'Bool', default => 0 );
19              
20             has 'multifasta_base_directory' => ( is => 'rw', isa => 'Str', default => 'pan_genome_sequences' );
21             has 'spreadsheet_filename' => ( is => 'rw', isa => 'Str', default => 'gene_presence_absence.csv' );
22             has 'output_filename' => ( is => 'rw', isa => 'Str', default => 'core_gene_alignment.aln' );
23             has 'core_definition' => ( is => 'rw', isa => 'Num', default => 0.99 );
24             has 'dont_delete_files' => ( is => 'rw', isa => 'Bool', default => 0 );
25             has 'allow_paralogs' => ( is => 'rw', isa => 'Bool', default => 0 );
26             has '_error_message' => ( is => 'rw', isa => 'Str' );
27             has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 );
28              
29             sub BUILD {
30 3     3 0 9 my ($self) = @_;
31              
32 3         9 my ( $multifasta_base_directory, $spreadsheet_filename, $output_filename, $core_definition,$verbose, $help, $mafft, $allow_paralogs, $dont_delete_files );
33              
34 3         93 GetOptionsFromArray(
35             $self->args,
36             'm|multifasta_base_directory=s' => \$multifasta_base_directory,
37             's|spreadsheet_filename=s' => \$spreadsheet_filename,
38             'o|output_filename=s' => \$output_filename,
39             'cd|core_definition=f' => \$core_definition,
40             'z|dont_delete_files' => \$dont_delete_files,
41             'p|allow_paralogs' => \$allow_paralogs,
42             'v|verbose' => \$verbose,
43             'h|help' => \$help,
44             );
45            
46 3 50       2488 if ( defined($verbose) ) {
47 0         0 $self->verbose($verbose);
48 0         0 $self->logger->level(10000);
49             }
50 3 100       46 $self->help($help) if(defined($help));
51 3 50       6 $self->allow_paralogs($allow_paralogs) if(defined($allow_paralogs));
52              
53 3 100 66     36 if ( defined($multifasta_base_directory) && ( -d $multifasta_base_directory ) ) {
54 2         96 $self->multifasta_base_directory( abs_path($multifasta_base_directory));
55             }
56 3 100       111 if(! -d $self->multifasta_base_directory )
57             {
58 1         32 $self->_error_message("Error: Cant access the multifasta base directory: ".$self->multifasta_base_directory);
59             }
60            
61 3 100 66     32 if ( defined($spreadsheet_filename) && ( -e $spreadsheet_filename ) ) {
62 2         84 $self->spreadsheet_filename( abs_path($spreadsheet_filename));
63             }
64 3 100       73 if(! -e $self->spreadsheet_filename )
65             {
66 1         25 $self->_error_message("Error: Cant access the spreadsheet: ".$self->spreadsheet_filename);
67             }
68 3 50       11 $self->output_filename( $output_filename ) if ( defined($output_filename) );
69 3 100       9 if ( defined($core_definition) )
70             {
71 1 50       6 if($core_definition > 1)
72             {
73 0         0 $self->core_definition( $core_definition/100 );
74             }
75             else
76             {
77 1         35 $self->core_definition( $core_definition );
78             }
79             }
80 3 50       97 $self->dont_delete_files($dont_delete_files) if ( defined($dont_delete_files) );
81            
82             }
83              
84             sub run {
85 3     3 0 7 my ($self) = @_;
86              
87 3 100       73 ( !$self->help ) or die $self->usage_text;
88 2 50       48 if ( defined( $self->_error_message ) ) {
89 0         0 print $self->_error_message . "\n";
90 0         0 die $self->usage_text;
91             }
92              
93 2         50 $self->logger->info("Extract core genes from spreadsheet");
94 2         85 my $core_genes_obj = Bio::Roary::ExtractCoreGenesFromSpreadsheet->new(
95             spreadsheet => $self->spreadsheet_filename,
96             core_definition => $self->core_definition,
97             allow_paralogs => $self->allow_paralogs
98             );
99            
100 2         42 $self->logger->info("Looking up genes in files");
101 2         61 my $gene_files = Bio::Roary::LookupGeneFiles->new(
102             multifasta_directory => $self->multifasta_base_directory,
103             ordered_genes => $core_genes_obj->ordered_core_genes,
104             );
105            
106 2         46 $self->logger->info("Merge multifasta alignments");
107 2         58 my $merge_alignments_obj = Bio::Roary::MergeMultifastaAlignments->new(
108             sample_names => $core_genes_obj->sample_names,
109             multifasta_files => $gene_files->ordered_gene_files(),
110             output_filename => $self->output_filename,
111             sample_names_to_genes => $core_genes_obj->sample_names_to_genes
112             );
113 2         9 $merge_alignments_obj->merge_files;
114            
115 2 50       56 if($self->dont_delete_files == 0)
116             {
117 2         248 remove_tree('pan_genome_sequences');
118             }
119             }
120              
121             sub usage_text {
122 1     1 0 2 my ($self) = @_;
123              
124 1         15 return <<USAGE;
125             Usage: pan_genome_core_alignment [options]
126             Create an alignment of core genes from the spreadsheet and the directory of gene multi-FASTAs.
127              
128             Options: -o STR output filename [core_gene_alignment.aln]
129             -cd FLOAT percentage of isolates a gene must be in to be core [99]
130             -m STR directory containing gene multi-FASTAs [pan_genome_sequences]
131             -s STR gene presence and absence spreadsheet [gene_presence_absence.csv]
132             -p allow paralogs
133             -z dont delete intermediate files
134             -v verbose output to STDOUT
135             -h this help message
136              
137             For further info see: http://sanger-pathogens.github.io/Roary/
138             USAGE
139             }
140              
141             __PACKAGE__->meta->make_immutable;
142 1     1   9 no Moose;
  1         2  
  1         6  
143             1;
144              
145             __END__
146              
147             =pod
148              
149             =encoding UTF-8
150              
151             =head1 NAME
152              
153             Bio::Roary::CommandLine::RoaryCoreAlignment - Take in the group statistics spreadsheet and the location of the gene multifasta files and create a core alignment.
154              
155             =head1 VERSION
156              
157             version 3.11.0
158              
159             =head1 SYNOPSIS
160              
161             Take in the group statistics spreadsheet and the location of the gene multifasta files and create a core alignment.
162              
163             =head1 AUTHOR
164              
165             Andrew J. Page <ap13@sanger.ac.uk>
166              
167             =head1 COPYRIGHT AND LICENSE
168              
169             This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
170              
171             This is free software, licensed under:
172              
173             The GNU General Public License, Version 3, June 2007
174              
175             =cut