lib/Bio/Roary/CommandLine/QueryRoary.pm

filter: Statementstmt 94.0% 110 / 117 Branchbran 85.0% 34 / 40 Conditioncond 61.1% 11 / 18 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 4 totaltotal 85.3% 175 / 205 CC 29 SCAR 24.9
CC
29
Cov
89%
BUILD
19.0
run
13.5
BEGIN
1.0
CRAP 12.0
« lib/Bio/Roary/Output/GroupsMultifastaNucleotide.pm ↑ Summary lib/Bio/Roary/PostAnalysis.pm »
1 1 undef $VERSION;
2 package Bio::Roary::CommandLine::QueryRoary;
3 1 $Bio::Roary::CommandLine::QueryRoary::VERSION = '3.13.0';
4 # ABSTRACT: Take in a groups file and the protein fasta files and output selected data
5  
6  
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Getopt::Long qw(GetOptionsFromArray);
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::Output::GroupsMultifastas;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Bio::Roary::Output::QueryGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Bio::Roary::PrepareInputFiles;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Bio::Roary::Output::DifferenceBetweenSets;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Bio::Roary::AnnotateGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Bio::Roary::GroupStatistics;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Bio::Roary::OrderGenes;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 extends 'Bio::Roary::CommandLine::Common';
18  
19 1 has 'args' => ( is => 'rw', isa => 'ArrayRef', required => 1 );
20 1 has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 );
21 1 has 'help' => ( is => 'rw', isa => 'Bool', default => 0 );
22  
23 1 has 'input_files' => ( is => 'rw', isa => 'ArrayRef' );
24 1 has 'groups_filename' => ( is => 'rw', isa => 'Str', default => 'clustered_proteins');
25 1 has 'group_names' => ( is => 'rw', isa => 'ArrayRef' );
26 1 has 'input_set_one' => ( is => 'rw', isa => 'ArrayRef' );
27 1 has 'input_set_two' => ( is => 'rw', isa => 'ArrayRef' );
28 1 has 'output_filename' => ( is => 'rw', isa => 'Str', default => 'pan_genome_results' );
29 1 has 'action' => ( is => 'rw', isa => 'Str', default => 'union' );
30 1 has 'core_definition' => ( is => 'rw', isa => 'Num', default => 0.99 );
31 1 has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 );
32  
33 1 has '_error_message' => ( is => 'rw', isa => 'Str' );
34  
35 18 ▶sub BUILD {
Subroutine BUILD: called CC=18 SCAR=29.4
Pod undocumented
36 18 my ($self) = @_;
37  
38 18 my ( $input_files, $output_filename, $groups_filename, @group_names, @input_set_one, @input_set_two, $action, $core_definition,$verbose, $help );
39  
40 18 GetOptionsFromArray(
41 $self->args,
42 'o|output=s' => \$output_filename,
43 'g|groups_filename=s' => \$groups_filename,
44 'n|group_names=s' => \@group_names,
45 'a|action=s' => \$action,
46 'i|input_set_one=s' => \@input_set_one,
47 't|input_set_two=s' => \@input_set_two,
48 'c|core_definition=f' => \$core_definition,
49 'v|verbose' => \$verbose,
50 'h|help' => \$help,
51 );
52  
53 18 ▶ if ( defined($verbose) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $verbose) 0 18 18
54 0 $self->verbose($verbose);
55 0 $self->logger->level(10000);
56 }
57 18 ▶ $self->help($help) if(defined($help));
Branch: 1 branch
BranchTrueFalseTotal
if defined $help 1 17 18
58
59 18 ▶ $self->output_filename($output_filename) if ( defined($output_filename) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $output_filename 0 18 18
60 18 ▶ $self->action($action) if ( defined($action) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $action 16 2 18
61 18 ▶ $self->core_definition( $core_definition / 100 ) if ( defined($core_definition) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $core_definition 0 18 18
62 18 ▶ if ( defined($groups_filename) && ( -e $groups_filename ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $groups_filename and -e $groups_filename) 17 1 18
Condition66%2/3
defined $groups_filename and -e $groups_filename
!ll&&!rl&&r
1017
MC/DC50%1/2
defined $groups_filename and -e $groups_filename
defined $groups_filename -e $groups_filename
Truth table66%2/3
A and B
A= defined $groups_filenameB= -e $groups_filename
ABresult
0X0
100
111
63 17 $self->groups_filename($groups_filename);
64 }
65
66 18 ▶ if(! (-e $self->groups_filename)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $self->groups_filename) 1 17 18
67 1 $self->_error_message("Error: Cant access the groups file: ".$self->groups_filename);
68 }
69  
70 18 @group_names = split( /,/, join( ',', @group_names ) );
71 18 ▶ $self->group_names( \@group_names ) if (@group_names);
Branch: 1 branch
BranchTrueFalseTotal
if @group_names 7 11 18
72
73 18 @input_set_one = split( /,/, join( ',', @input_set_one ) );
74 18 ▶ $self->input_set_one( \@input_set_one ) if (@input_set_one);
Branch: 1 branch
BranchTrueFalseTotal
if @input_set_one 7 11 18
75
76 18 @input_set_two = split( /,/, join( ',', @input_set_two ) );
77 18 ▶ $self->input_set_two( \@input_set_two ) if (@input_set_two);
Branch: 1 branch
BranchTrueFalseTotal
if @input_set_two 7 11 18
78
79 18 ▶ if(defined($self->input_set_one) && defined($self->input_set_two) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->input_set_one and defined $self->input_set_two) 7 11 18
Condition66%2/3
defined $self->input_set_one and defined $self->input_set_two
!ll&&!rl&&r
1107
MC/DC50%1/2
defined $self->input_set_one and defined $self->input_set_two
defined $self->input_set_one defined $self->input_set_two
Truth table66%2/3
A and B
A= defined $self->input_set_oneB= defined $self->input_set_two
ABresult
0X0
100
111
80 {
81 7 my @all_input_files = (@{ $self->input_set_one },@{ $self->input_set_two });
82 7 $self->args(\@all_input_files);
83 }
84  
85  
86 18 ▶ if ( !defined($self->input_set_two) && @{ $self->args } == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->input_set_two and @{$self->args;} == 0) 1 17 18
Condition100%3/3
not defined $self->input_set_two and @{$self->args;} == 0
!ll&&!rl&&r
7101
MC/DC100%2/2
not defined $self->input_set_two and @{$self->args;} == 0
not defined $self->input_set_two @{$self->args;} == 0
Truth table100%3/3
not(A) and B
A= not defined $self->input_set_twoB= @{$self->args;} == 0
ABresult
0X0
100
111
87 1 $self->_error_message("Error: You need to provide a FASTA file");
88 }
89
90 18 for my $filename ( @{ $self->args } ) {
91 44 ▶ if ( !-e $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $filename) 0 44 44
92 0 $self->_error_message("Error: Cant access file $filename");
93 0 last;
94 }
95 }
96 18 $self->input_files( $self->args );
97  
98 }
99  
100 18 ▶sub run {
Subroutine run: called CC=12 SCAR=26.0
Pod undocumented
101 18 my ($self) = @_;
102  
103 18 ▶ ( !$self->help ) or die $self->usage_text;
Branch: 1 branch
BranchTrueFalseTotal
$self->help and die $self->usage_text 1 17 18
104 17 ▶ if ( defined( $self->_error_message ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_error_message) 0 17 17
105 0 print $self->_error_message . "\n";
106 0 die $self->usage_text;
107 }
108
109 17 my $prepare_input_files = Bio::Roary::PrepareInputFiles->new(
110 input_files => $self->input_files,
111 );
112  
113 17 my $analyse_groups_obj = Bio::Roary::AnalyseGroups->new(
114 fasta_files => $prepare_input_files->fasta_files,
115 groups_filename => $self->groups_filename,
116 );
117  
118 17 ▶ if ( $self->action eq 'union' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($self->action eq 'union') { } 2 15 17
elsif ($self->action eq 'intersection') { } 1 14 15
elsif ($self->action eq 'complement') { } 1 13 14
elsif ($self->action eq 'gene_multifasta' and defined $self->group_names) { } 6 7 13
elsif ($self->action eq 'difference' and defined $self->input_set_one and defined $self->input_set_two) { } 7 0 7
119 2 my $query_groups = Bio::Roary::Output::QueryGroups->new(
120 analyse_groups => $analyse_groups_obj,
121 output_union_filename => $self->output_filename,
122 input_filenames => $prepare_input_files->fasta_files
123 );
124 2 $query_groups->groups_union();
125 }
126 elsif ( $self->action eq 'intersection' ) {
127 1 my $query_groups = Bio::Roary::Output::QueryGroups->new(
128 analyse_groups => $analyse_groups_obj,
129 output_intersection_filename => $self->output_filename,
130 input_filenames => $prepare_input_files->fasta_files,
131 core_definition => $self->core_definition
132 );
133 1 $query_groups->groups_intersection();
134 }
135 elsif ( $self->action eq 'complement' ) {
136 1 my $query_groups = Bio::Roary::Output::QueryGroups->new(
137 analyse_groups => $analyse_groups_obj,
138 output_complement_filename => $self->output_filename,
139 input_filenames => $prepare_input_files->fasta_files,
140 core_definition => $self->core_definition
141 );
142 1 $query_groups->groups_complement();
143 }
144 ▶ elsif ( $self->action eq 'gene_multifasta' && defined( $self->group_names ) ) {
Condition66%2/3
$self->action eq "gene_multifasta" and defined $self->group_names
!ll&&!rl&&r
706
MC/DC50%1/2
$self->action eq "gene_multifasta" and defined $self->group_names
$self->action eq "gene_multifasta" defined $self->group_names
Truth table66%2/3
A and B
A= $self->action eq "gene_multifasta"B= defined $self->group_names
ABresult
0X0
100
111
145 6 my $group_multi_fastas = Bio::Roary::Output::GroupsMultifastas->new(
146 group_names => $self->group_names,
147 analyse_groups => $analyse_groups_obj,
148 output_filename_base => $self->output_filename
149 );
150 6 $group_multi_fastas->create_files();
151 }
152 ▶ elsif($self->action eq 'difference' && defined($self->input_set_one) && defined($self->input_set_two))
Condition33%2/6
$self->action eq "difference" and defined $self->input_set_one and defined $self->input_set_two
!ll&&!rl&&r
007
$self->action eq "difference" and defined $self->input_set_one
!ll&&!rl&&r
007
MC/DC0%0/3
$self->action eq "difference" and defined $self->input_set_one and defined $self->input_set_two
$self->action eq "difference" defined $self->input_set_one defined $self->input_set_two
Truth table25%1/4
A and B and C
A= $self->action eq "difference"B= defined $self->input_set_oneC= defined $self->input_set_two
ABCresult
0XX0
10X0
1100
1111
153 {
154 7 my $difference_between_sets = Bio::Roary::Output::DifferenceBetweenSets->new(
155 analyse_groups => $analyse_groups_obj,
156 input_filenames_sets => [
157 $prepare_input_files->lookup_fasta_files_from_unknown_input_files($self->input_set_one),
158 $prepare_input_files->lookup_fasta_files_from_unknown_input_files($self->input_set_two)
159 ],
160 );
161 7 $difference_between_sets->groups_set_one_unique();
162 7 $difference_between_sets->groups_set_two_unique();
163 7 $difference_between_sets->groups_in_common();
164
165 7 for my $differences_group_filename(($difference_between_sets->groups_set_one_unique_filename,$difference_between_sets->groups_set_two_unique_filename,$difference_between_sets->groups_in_common_filename))
166 {
167 21 $self->create_spreadsheets($differences_group_filename, $prepare_input_files->fasta_files, $self->input_files);
168 }
169  
170 }
171 else {
172 0 print "Nothing done\n";
173 }
174 }
175  
176 sub create_spreadsheets
177 21 ▶{
Subroutine create_spreadsheets: called CC=1 SCAR=0.0
Pod undocumented
178 21 my ($self, $groups_file, $fasta_files, $gff_files) = @_;
179  
180 21 my $analyse_groups_obj = Bio::Roary::AnalyseGroups->new(
181 fasta_files => $fasta_files,
182 groups_filename => $groups_file,
183 );
184
185 21 my $annotate_groups = Bio::Roary::AnnotateGroups->new(
186 gff_files => $gff_files,
187 output_filename => $groups_file.'_reannotated',
188 groups_filename => $groups_file,
189 );
190 21 $annotate_groups->reannotate;
191
192 21 my $order_genes_obj = Bio::Roary::OrderGenes->new(
193 analyse_groups_obj => $analyse_groups_obj,
194 gff_files => $gff_files,
195 core_definition => $self->core_definition,
196 pan_graph_filename => 'set_difference_core_accessory_graph.dot',
197 accessory_graph_filename => 'set_difference_accessory_graph.dot',
198 );
199
200 21 my $group_statistics = Bio::Roary::GroupStatistics->new(
201 output_filename => $groups_file.'_statistics.csv',
202 annotate_groups_obj => $annotate_groups,
203 analyse_groups_obj => $analyse_groups_obj,
204 groups_to_contigs => $order_genes_obj->groups_to_contigs
205 );
206 21 $group_statistics->create_spreadsheet;
207 }
208  
209 1 ▶sub usage_text {
Subroutine usage_text: called CC=1 SCAR=0.0
Pod undocumented
210 1 my ($self) = @_;
211  
212 1 return <<USAGE;
213 Usage: query_pan_genome [options] *.gff
214 Perform set operations on the pan genome to see the gene differences between groups of isolates.
215  
216 Options: -g STR groups filename [clustered_proteins]
217 -a STR action (union/intersection/complement/gene_multifasta/difference) [union]
218 -c FLOAT percentage of isolates a gene must be in to be core [99]
219 -o STR output filename [pan_genome_results]
220 -n STR comma separated list of gene names for use with gene_multifasta action
221 -i STR comma separated list of filenames, comparison set one
222 -t STR comma separated list of filenames, comparison set two
223 -v verbose output to STDOUT
224 -h this help message
225
226 Examples:
227 Union of genes found in isolates
228 query_pan_genome -a union *.gff
229
230 Intersection of genes found in isolates (core genes)
231 query_pan_genome -a intersection *.gff
232
233 Complement of genes found in isolates (accessory genes)
234 query_pan_genome -a complement *.gff
235  
236 Extract the sequence of each gene listed and create multi-FASTA files
237 query_pan_genome -a gene_multifasta -n gryA,mecA,abc *.gff
238  
239 Gene differences between sets of isolates
240 query_pan_genome -a difference --input_set_one 1.gff,2.gff --input_set_two 3.gff,4.gff,5.gff
241  
242 For further info see: http://sanger-pathogens.github.io/Roary/
243 USAGE
244 }
245  
246 1 __PACKAGE__->meta->make_immutable;
247 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
248 1 1;
249  
250 __END__
« lib/Bio/Roary/Output/GroupsMultifastaNucleotide.pm ↑ Summary lib/Bio/Roary/PostAnalysis.pm »