lib/Bio/Roary/Output/EmblGroups.pm

filter: Statementstmt 31.4% 50 / 159 Branchbran 11.1% 4 / 36 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 47.3% 9 / 19 Podpod 0.0% 0 / 1 totaltotal 24.4% 63 / 258 CC 34 SCAR 44.5
CC
34
Cov
24%
_fragment_blocks
240.0
_block
72.0
_header_block
30.0
CRAP 85.2
« blib/lib/Bio/Roary/CommandLine/AssemblyStatistics.pm ↑ Summary blib/lib/Bio/Roary/CommandLine/IterativeCdhit.pm »
1 package Bio::Roary::Output::EmblGroups;
2 2 $Bio::Roary::Output::EmblGroups::VERSION = '3.13.0';
3 # ABSTRACT: Create a tab/embl file with the features for drawing pretty pictures
4  
5  
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Bio::Roary::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Bio::Roary::AnalyseGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Bio::Roary::AnnotateGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 with 'Bio::Roary::Output::EMBLHeaderCommon';
13  
14 2 has 'annotate_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnnotateGroups', required => 1 );
15 2 has 'analyse_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnalyseGroups', required => 1 );
16 2 has 'output_filename' => ( is => 'ro', isa => 'Str', default => 'core_accessory.tab' );
17 2 has 'output_header_filename' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_output_header_filename' );
18 2 has 'groups_to_contigs' => ( is => 'ro', isa => 'Maybe[HashRef]' );
19 2 has 'ordering_key' => ( is => 'ro', isa => 'Str', default => 'core_accessory_overall_order' );
20  
21 2 has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' );
22 2 has '_output_header_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_header_fh' );
23 2 has '_sorted_file_names' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build__sorted_file_names' );
24 2 has '_groups_to_files' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build__groups_to_files' );
25 2 has 'heatmap_lookup_table' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_heatmap_lookup_table' );
26  
27 0 ▶sub _build__output_fh {
Subroutine _build__output_fh: not called CC=2 SCAR=17.9
28 0 my ($self) = @_;
29 0 ▶ open( my $fh, '>', $self->output_filename )
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->output_filename or "Bio::Roary::Exceptions::CouldntWriteToFile"->throw("error", 'Couldnt write output file:' . $self->output_filename) 0 0 0
30 or Bio::Roary::Exceptions::CouldntWriteToFile->throw( error => "Couldnt write output file:" . $self->output_filename );
31 0 return $fh;
32 }
33  
34 0 ▶sub _build__output_header_fh {
Subroutine _build__output_header_fh: not called CC=2 SCAR=17.9
35 0 my ($self) = @_;
36 0 ▶ open( my $fh, '>', $self->output_header_filename )
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->output_header_filename or "Bio::Roary::Exceptions::CouldntWriteToFile"->throw("error", 'Couldnt write output file:' . $self->output_filename) 0 0 0
37 or Bio::Roary::Exceptions::CouldntWriteToFile->throw( error => "Couldnt write output file:" . $self->output_filename );
38 0 return $fh;
39 }
40  
41 0 ▶sub _build_output_header_filename {
Subroutine _build_output_header_filename: not called CC=1 SCAR=6.9
42 0 my ($self) = @_;
43 0 my $base_name = $self->output_filename;
44 0 $base_name =~ s/\.tab/.header.embl/i;
45 0 return $base_name;
46 }
47  
48 0 ▶sub _build__sorted_file_names {
Subroutine _build__sorted_file_names: not called CC=1 SCAR=6.9
49 0 my ($self) = @_;
50 0 my @sorted_file_names = sort( @{ $self->analyse_groups_obj->fasta_files } );
51 0 return \@sorted_file_names;
52 }
53  
54 0 ▶sub _build__groups_to_files {
Subroutine _build__groups_to_files: not called CC=3 SCAR=24.8
55 0 my ($self) = @_;
56 0 my %groups_to_files;
57 0 for my $group ( @{ $self->annotate_groups_obj->_groups } ) {
58 0 my $genes = $self->annotate_groups_obj->_groups_to_id_names->{$group};
59 0 my %filenames;
60 0 for my $gene_name ( @{$genes} ) {
61 0 my $filename = $self->analyse_groups_obj->_genes_to_file->{$gene_name};
62 0 push( @{ $filenames{$filename} }, $gene_name );
63 }
64 0 $groups_to_files{$group} = \%filenames;
65 }
66 0 return \%groups_to_files;
67 }
68  
69 0 ▶sub _block {
Subroutine _block: not called CC=8 SCAR=42.8
70 0 my ( $self, $group ) = @_;
71 0 my @taxon_names_array;
72 0 my $annotated_group_name = $self->annotate_groups_obj->_groups_to_consensus_gene_names->{$group};
73  
74 return ''
75 if (
76 !(
77 defined( $self->groups_to_contigs->{$annotated_group_name} )
78 0 ▶ && defined( $self->groups_to_contigs->{$annotated_group_name}->{ $self->ordering_key } )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->groups_to_contigs->{$annotated_group_name} and defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key} 0 0 0
Condition0%0/3
defined $self->groups_to_contigs->{$annotated_group_name} and defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->groups_to_contigs->{$annotated_group_name} and defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key}
defined $self->groups_to_contigs->{$annotated_group_name} defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key}
Truth table0%0/3
A and B
A= defined $self->groups_to_contigs->{$annotated_group_name}B= defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key}
ABresult
0X0
100
111
79 )
80 );
81  
82 return ''
83 if ( defined( $self->groups_to_contigs->{$annotated_group_name}->{comment} )
84 0 ▶ && $self->groups_to_contigs->{$annotated_group_name}->{comment} ne '' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->groups_to_contigs->{$annotated_group_name}{"comment"} and $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne "" 0 0 0
Condition0%0/3
defined $self->groups_to_contigs->{$annotated_group_name}{"comment"} and $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->groups_to_contigs->{$annotated_group_name}{"comment"} and $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne ""
defined $self->groups_to_contigs->{$annotated_group_name}{"comment"} $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne ""
Truth table0%0/3
A and B
A= defined $self->groups_to_contigs->{$annotated_group_name}{"comment"}B= $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne ""
ABresult
0X0
100
111
85  
86 0 my $coordindates = $self->groups_to_contigs->{$annotated_group_name}->{ $self->ordering_key };
87  
88 0 for my $filename ( @{ $self->_sorted_file_names } ) {
89 0 my $group_to_file_genes = $self->_groups_to_files->{$group}->{$filename};
90  
91 0 ▶ if ( defined($group_to_file_genes) && @{$group_to_file_genes} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $group_to_file_genes and @{$group_to_file_genes;} > 0) 0 0 0
Condition0%0/3
defined $group_to_file_genes and @{$group_to_file_genes;} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $group_to_file_genes and @{$group_to_file_genes;} > 0
defined $group_to_file_genes @{$group_to_file_genes;} > 0
Truth table0%0/3
A and B
A= defined $group_to_file_genesB= @{$group_to_file_genes;} > 0
ABresult
0X0
100
111
92 0 my $filename_cpy = basename($filename);
93 0 $filename_cpy =~ s!\.gff\.proteome\.faa!!;
94 0 push( @taxon_names_array, $filename_cpy );
95 0 next;
96 }
97 }
98  
99 0 my $colour = $self->_get_heat_map_colour( \@taxon_names_array, $self->annotate_groups_obj->_number_of_files );
100  
101 0 my $taxon_names = join( " ", @taxon_names_array );
102  
103 0 my $tab_file_entry = "FT variation $coordindates\n";
104 0 $tab_file_entry .= "FT /colour=$colour\n";
105 0 $tab_file_entry .= "FT /gene=$annotated_group_name\n";
106 0 $tab_file_entry .= "FT /taxa=\"$taxon_names\"\n";
107  
108 0 return $tab_file_entry;
109 }
110  
111 14 ▶sub _get_heat_map_colour {
Subroutine _get_heat_map_colour: called CC=3 SCAR=11.0
112 14 my ( $self, $taxon_names, $number_of_files ) = @_;
113 14 ▶ return $self->heatmap_lookup_table->[0] if ( @{$taxon_names} == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @{$taxon_names;} == 1 2 12 14
114 12 my $number_of_colours = @{ $self->heatmap_lookup_table };
115 12 ▶ return $self->heatmap_lookup_table->[ $number_of_colours - 1 ] if ( @{$taxon_names} == $number_of_files );
Branch: 1 branch
BranchTrueFalseTotal
if @{$taxon_names;} == $number_of_files 2 10 12
116  
117 10 my $block_size = $number_of_files / @{ $self->heatmap_lookup_table };
118 10 my $colour_index = ceil( @{$taxon_names} / $block_size ) - 1;
119 10 return $self->heatmap_lookup_table->[$colour_index];
120 }
121  
122 1 ▶sub _build_heatmap_lookup_table {
Subroutine _build_heatmap_lookup_table: called CC=1 SCAR=0.0
123 1 my ($self) = @_;
124 return [
125 1 4, # blue (RGB values: 0 0 255)
126 5, # cyan (RGB values: 0 255 255)
127 9, # light sky blue (RGB values: 135 206 250)
128 8, # pale green (RGB values: 152 251 152)
129 3, # green (RGB values: 0 255 0)
130 7, # yellow (RGB values: 255 255 0)
131 10, # orange (RGB values: 255 165 0)
132 16, # light red (RGB values: 255 127 127)
133 15, # mid red: (RGB values: 255 63 63)
134 2, # red (RGB values: 255 0 0)
135 ];
136 }
137  
138 0 ▶sub _block_colour {
Subroutine _block_colour: not called CC=2 SCAR=17.9
139 0 my ( $self, $accessory_label ) = @_;
140 0 my $colour = 2;
141 0 ▶ return $colour unless ( defined($accessory_label) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $accessory_label 0 0 0
142  
143 0 $colour += $accessory_label % 6;
144 0 return $colour;
145 }
146  
147 0 ▶sub _header_block {
Subroutine _header_block: not called CC=5 SCAR=34.0
148 0 my ( $self, $group ) = @_;
149 0 my $annotated_group_name = $self->annotate_groups_obj->_groups_to_consensus_gene_names->{$group};
150 0 my $colour = 1;
151  
152 return ''
153 if (
154 !(
155 defined( $self->groups_to_contigs->{$annotated_group_name} )
156 0 ▶ && defined( $self->groups_to_contigs->{$annotated_group_name}->{ $self->ordering_key } )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->groups_to_contigs->{$annotated_group_name} and defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key} 0 0 0
Condition0%0/3
defined $self->groups_to_contigs->{$annotated_group_name} and defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->groups_to_contigs->{$annotated_group_name} and defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key}
defined $self->groups_to_contigs->{$annotated_group_name} defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key}
Truth table0%0/3
A and B
A= defined $self->groups_to_contigs->{$annotated_group_name}B= defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key}
ABresult
0X0
100
111
157 )
158 );
159 return ''
160 if ( defined( $self->groups_to_contigs->{$annotated_group_name}->{comment} )
161 0 ▶ && $self->groups_to_contigs->{$annotated_group_name}->{comment} ne '' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->groups_to_contigs->{$annotated_group_name}{"comment"} and $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne "" 0 0 0
Condition0%0/3
defined $self->groups_to_contigs->{$annotated_group_name}{"comment"} and $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->groups_to_contigs->{$annotated_group_name}{"comment"} and $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne ""
defined $self->groups_to_contigs->{$annotated_group_name}{"comment"} $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne ""
Truth table0%0/3
A and B
A= defined $self->groups_to_contigs->{$annotated_group_name}{"comment"}B= $self->groups_to_contigs->{$annotated_group_name}{"comment"} ne ""
ABresult
0X0
100
111
162 0 my $coordindates = $self->groups_to_contigs->{$annotated_group_name}->{ $self->ordering_key };
163 0 my $annotation_type = $self->_annotation_type($annotated_group_name);
164  
165 0 $colour = $self->_block_colour( $self->groups_to_contigs->{$annotated_group_name}->{accessory_label} );
166  
167 0 my $tab_file_entry = "FT$annotation_type$coordindates\n";
168 0 $tab_file_entry .= "FT /label=$annotated_group_name\n";
169 0 $tab_file_entry .= "FT /locus_tag=$annotated_group_name\n";
170 0 $tab_file_entry .= "FT /colour=$colour\n";
171  
172 0 return $tab_file_entry;
173 }
174  
175 0 ▶sub _fragment_blocks {
Subroutine _fragment_blocks: not called CC=15 SCAR=54.8
176 0 my ( $self, $fh ) = @_;
177 0 my %fragment_numbers;
178 0 for my $group ( @{ $self->annotate_groups_obj->_groups } ) {
179 0 my $annotated_group_name = $self->annotate_groups_obj->_groups_to_consensus_gene_names->{$group};
180  
181 0 ▶ next unless ( defined( $self->groups_to_contigs->{$annotated_group_name}->{accessory_label} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->groups_to_contigs->{$annotated_group_name}{"accessory_label"} 0 0 0
182 0 ▶ next unless ( defined( $self->groups_to_contigs->{$annotated_group_name}->{ $self->ordering_key } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key} 0 0 0
183 0 ▶ next if ( $self->groups_to_contigs->{$annotated_group_name}->{ $self->ordering_key } eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->groups_to_contigs->{$annotated_group_name}{$self->ordering_key} eq "" 0 0 0
184 push(
185 0 @{ $fragment_numbers{ $self->groups_to_contigs->{$annotated_group_name}->{accessory_label} } },
186 0 $self->groups_to_contigs->{$annotated_group_name}->{ $self->ordering_key }
187 );
188 }
189  
190 0 for my $accessory_label ( keys %fragment_numbers ) {
191 0 ▶ next unless ( defined( $fragment_numbers{$accessory_label} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fragment_numbers{$accessory_label} 0 0 0
192 0 my @sorted_fragment = sort { $a <=> $b } @{ $fragment_numbers{$accessory_label} };
193 0 my $tab_file_entry = '';
194 0 ▶ if ( @sorted_fragment > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@sorted_fragment > 1) { } 0 0 0
elsif (@sorted_fragment == 1) { } 0 0 0
195 0 my $min = $sorted_fragment[0];
196 0 my $max = $sorted_fragment[-1];
197  
198 0 ▶ next if ( !defined($min) || !defined($max) || $min eq '' || $max eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $min && defined $max or $min eq "" or $max eq "" 0 0 0
Condition0%0/9
not defined $min && defined $max or $min eq "" or $max eq ""
l!l&&r!l&&!r
000
not defined $min && defined $max or $min eq ""
l!l&&r!l&&!r
000
defined $min && defined $max
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $min && defined $max or $min eq "" or $max eq ""
defined $min defined $max $min eq "" $max eq ""
Truth table0%0/5
not(A && B) or C or D
A= defined $minB= defined $maxC= $min eq ""D= $max eq ""
ABCDresult
0XXX1
10XX1
111X1
11011
11000
199 0 $tab_file_entry = "FT feature $min" . '..' . "$max\n";
200 }
201 elsif ( @sorted_fragment == 1 ) {
202 0 my $min = $sorted_fragment[0];
203 0 ▶ next if ( !defined($min) || $min eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $min or $min eq "" 0 0 0
Condition0%0/3
not defined $min or $min eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $min or $min eq ""
not defined $min $min eq ""
Truth table0%0/3
not(A) or B
A= not defined $minB= $min eq ""
ABresult
1X1
011
000
204 0 $tab_file_entry = "FT feature $min\n";
205 }
206 else {
207 0 next;
208 }
209 0 $tab_file_entry .= "FT /colour=" . $self->_block_colour($accessory_label) . "\n";
210  
211 0 print {$fh} $tab_file_entry;
212 }
213  
214 }
215  
216 0 ▶sub create_files {
Subroutine create_files: not called CC=2 SCAR=17.9
Pod undocumented
217 0 my ($self) = @_;
218  
219 0 print { $self->_output_header_fh } $self->_header_top();
220 0 for my $group ( @{ $self->annotate_groups_obj->_groups } ) {
221 0 print { $self->_output_fh } $self->_block($group);
222 0 print { $self->_output_header_fh } $self->_header_block($group);
223 }
224 0 $self->_fragment_blocks( $self->_output_header_fh );
225 0 print { $self->_output_header_fh } $self->_header_bottom();
226 0 close( $self->_output_header_fh );
227 0 close( $self->_output_fh );
228 }
229  
230 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
231 2 __PACKAGE__->meta->make_immutable;
232  
233 2 1;
234  
235 __END__
« blib/lib/Bio/Roary/CommandLine/AssemblyStatistics.pm ↑ Summary blib/lib/Bio/Roary/CommandLine/IterativeCdhit.pm »