lib/Bio/Roary/Output/NumberOfGroups.pm

filter: Statementstmt 100% 96 / 96 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 1 totaltotal 99.1% 117 / 118 CC 9 SCAR 11.6
CC
9
Cov
100%
_single_iteration_gene_expansion
7.0
create_output_files
2.0
_create_raw_output_file
2.0
CRAP 3.2
« lib/Bio/Roary/AnalyseGroups.pm ↑ Summary lib/Bio/Roary/PresenceAbsenceMatrix.pm »
1 package Bio::Roary::Output::NumberOfGroups;
2 2 $Bio::Roary::Output::NumberOfGroups::VERSION = '3.13.0';
3 # ABSTRACT: Create raw output files of group counts for turning into plots
4  
5  
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use List::Util qw(shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Bio::Roary::AnnotateGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Bio::Roary::GroupStatistics;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 has 'group_statistics_obj' => ( is => 'ro', isa => 'Bio::Roary::GroupStatistics', required => 1 );
12 2 has 'number_of_iterations' => ( is => 'ro', isa => 'Int', default => 10);
13 2 has 'groups_to_contigs' => ( is => 'ro', isa => 'Maybe[HashRef]' );
14 2 has 'annotate_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnnotateGroups', required => 1 );
15 2 has 'core_definition' => ( is => 'ro', isa => 'Num', default => 1.0 );
16  
17 2 has 'output_raw_filename_conserved_genes' => ( is => 'ro', isa => 'Str', default => 'number_of_conserved_genes.Rtab' );
18 2 has 'output_raw_filename_unique_genes' => ( is => 'ro', isa => 'Str', default => 'number_of_unique_genes.Rtab' );
19 2 has 'output_raw_filename_total_genes' => ( is => 'ro', isa => 'Str', default => 'number_of_genes_in_pan_genome.Rtab' );
20 2 has 'output_raw_filename_new_genes' => ( is => 'ro', isa => 'Str', default => 'number_of_new_genes.Rtab' );
21 2 ▶has '_conserved_genes' => ( is => 'ro', isa => 'ArrayRef', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
22 2 ▶has '_unique_genes' => ( is => 'ro', isa => 'ArrayRef', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
23 2 ▶has '_total_genes' => ( is => 'ro', isa => 'ArrayRef', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
24 2 ▶has '_new_genes' => ( is => 'ro', isa => 'ArrayRef', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 2 ▶sub create_output_files {
Subroutine create_output_files: called CC=2 SCAR=6.9
Pod undocumented
27 2 my ($self) = @_;
28  
29 2 ▶ for ( my $i = 0 ; $i < $self->number_of_iterations ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->number_of_iterations) 20 2 22
30 20 $self->_single_iteration_gene_expansion;
31 }
32  
33 2 $self->_create_raw_output_file( $self->output_raw_filename_conserved_genes, $self->_conserved_genes );
34 2 $self->_create_raw_output_file( $self->output_raw_filename_unique_genes, $self->_unique_genes );
35 2 $self->_create_raw_output_file( $self->output_raw_filename_total_genes, $self->_total_genes );
36 2 $self->_create_raw_output_file( $self->output_raw_filename_new_genes, $self->_new_genes );
37 2 return 1;
38 }
39  
40 8 ▶sub _create_raw_output_file {
Subroutine _create_raw_output_file: called CC=2 SCAR=6.9
41 8 my ( $self, $filename, $output_data ) = @_;
42 8 open( my $fh, '>', $filename );
43 8 for my $iterations ( @{$output_data} ) {
44 80 print {$fh} join( "\t", @{$iterations} );
45 80 print {$fh} "\n";
46 }
47 8 close($fh);
48 }
49  
50 20 ▶sub _shuffle_input_files {
Subroutine _shuffle_input_files: called CC=1 SCAR=0.0
51 20 my ($self) = @_;
52 20 my @shuffled_input_files = shuffle( @{ $self->group_statistics_obj->_sorted_file_names } );
53 20 return \@shuffled_input_files;
54 }
55  
56 20 ▶sub _single_iteration_gene_expansion {
Subroutine _single_iteration_gene_expansion: called CC=7 SCAR=19.5
57 20 my ($self) = @_;
58 20 my %existing_groups;
59 my @conserved_genes_added_per_file;
60 20 my @unique_genes_added_per_file;
61 20 my @total_genes_added_per_file;
62 20 my @new_genes_added_per_file;
63  
64 20 my $shuffled_input_files = $self->_shuffle_input_files();
65  
66 20 my $files_counter = 1;
67 20 for my $input_file ( @{$shuffled_input_files} ) {
68 60 my $unique_groups_counter = 0;
69 60 my $total_groups_counter = 0;
70 60 my $new_group_counter = 0;
71 60 my $conserved_groups_counter = 0;
72 60 my $new_groups = $self->group_statistics_obj->_files_to_groups->{$input_file};
73  
74 60 for my $group ( @{$new_groups} ) {
75 240 ▶ if ( !defined( $existing_groups{$group} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $existing_groups{$group}) 140 100 240
76 140 $new_group_counter++;
77 }
78 240 $existing_groups{$group}++;
79 }
80  
81 60 for my $group ( keys %existing_groups ) {
82 340 ▶ if ( $existing_groups{$group} >= ($files_counter*$self->core_definition) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($existing_groups{$group} >= $files_counter * $self->core_definition) 170 170 340
83 170 $conserved_groups_counter++;
84 }
85  
86 340 ▶ if ( $existing_groups{$group} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($existing_groups{$group} == 1) 220 120 340
87 220 $unique_groups_counter++;
88 }
89 340 $total_groups_counter++;
90 }
91  
92 60 push( @conserved_genes_added_per_file, $conserved_groups_counter );
93 60 push( @unique_genes_added_per_file, $unique_groups_counter );
94 60 push( @total_genes_added_per_file, $total_groups_counter );
95 60 push( @new_genes_added_per_file, $new_group_counter );
96 60 $files_counter++;
97 }
98 20 push( @{ $self->_conserved_genes }, \@conserved_genes_added_per_file );
99 20 push( @{ $self->_unique_genes }, \@unique_genes_added_per_file );
100 20 push( @{ $self->_total_genes }, \@total_genes_added_per_file );
101 20 push( @{ $self->_new_genes }, \@new_genes_added_per_file );
102  
103 20 return;
104 }
105  
106 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 2 __PACKAGE__->meta->make_immutable;
108  
109 2 1;
110  
111 __END__
« lib/Bio/Roary/AnalyseGroups.pm ↑ Summary lib/Bio/Roary/PresenceAbsenceMatrix.pm »