lib/Bio/Roary/PresenceAbsenceMatrix.pm

filter: Statementstmt 100% 55 / 55 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 91.1% 72 / 79 CC 7 SCAR 11.4
CC
7
Cov
95%
create_matrix_file
6.0
_build__output_fh
2.0
BEGIN
1.0
CRAP 3.1
« lib/Bio/Roary/Output/NumberOfGroups.pm ↑ Summary lib/Bio/Roary/JobRunner/Role.pm »
1 package Bio::Roary::PresenceAbsenceMatrix;
2 11 $Bio::Roary::PresenceAbsenceMatrix::VERSION = '3.13.0';
3 # ABSTRACT: Create a matrix with presence and absence
4  
5  
6 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Text::CSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Bio::Roary::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Bio::Roary::AnnotateGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 has 'annotate_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnnotateGroups', required => 1 );
13 11 has 'sorted_file_names' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
14 11 has 'groups_to_files' => ( is => 'ro', isa => 'HashRef', required => 1 );
15 11 has 'num_files_in_groups' => ( is => 'ro', isa => 'HashRef', required => 1 );
16 11 has 'sample_headers' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
17 11 has 'output_filename' => ( is => 'ro', isa => 'Str', default => 'gene_presence_absence.Rtab' );
18  
19 11 has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' );
20 11 has '_text_csv_obj' => ( is => 'ro', isa => 'Text::CSV', lazy => 1, builder => '_build__text_csv_obj' );
21  
22 3 ▶sub _build__output_fh {
Subroutine _build__output_fh: called CC=2 SCAR=7.1
23 3 my ($self) = @_;
24 3 ▶ 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) 3 0 3
25 or Bio::Roary::Exceptions::CouldntWriteToFile->throw( error => "Couldnt write output file:" . $self->output_filename );
26 3 return $fh;
27 }
28  
29 3 ▶sub _build__text_csv_obj {
Subroutine _build__text_csv_obj: called CC=1 SCAR=0.0
30 3 my ($self) = @_;
31 3 return Text::CSV->new( { binary => 1, always_quote => 0, sep_char => "\t", eol => "\r\n" } );
32 }
33  
34 3 ▶sub create_matrix_file {
Subroutine create_matrix_file: called CC=6 SCAR=17.9
Pod undocumented
35 3 my ($self) = @_;
36  
37 # Header row
38 3 unshift @{ $self->sample_headers }, 'Gene';
39 3 $self->_text_csv_obj->print( $self->_output_fh, $self->sample_headers );
40  
41 3 ▶ for my $group ( sort { $self->num_files_in_groups->{$b} <=> $self->num_files_in_groups->{$a} || $a cmp $b }
Condition66%2/3
$self->num_files_in_groups->{$b} <=> $self->num_files_in_groups->{$a} || $a cmp $b
l!l&&r!l&&!r
1580
MC/DC0%0/2
$self->num_files_in_groups->{$b} <=> $self->num_files_in_groups->{$a} || $a cmp $b
$self->num_files_in_groups->{$b} <=> $self->num_files_in_groups->{$a} $a cmp $b
Truth table66%2/3
A || B
A= $self->num_files_in_groups->{$b} <=> $self->num_files_in_groups->{$a}B= $a cmp $b
ABresult
1X1
011
000
42 3 keys %{ $self->num_files_in_groups } )
43 {
44 15 my @row;
45 15 my $annotated_group_name = $self->annotate_groups_obj->_groups_to_consensus_gene_names->{$group};
46 15 push( @row, $annotated_group_name );
47 15 for my $filename ( @{ $self->sorted_file_names } ) {
48 45 my $group_to_file_genes = $self->groups_to_files->{$group}->{$filename};
49  
50 45 ▶ 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) { } 25 20 45
Condition66%2/3
defined $group_to_file_genes and @{$group_to_file_genes;} > 0
!ll&&!rl&&r
20025
MC/DC50%1/2
defined $group_to_file_genes and @{$group_to_file_genes;} > 0
defined $group_to_file_genes @{$group_to_file_genes;} > 0
Truth table66%2/3
A and B
A= defined $group_to_file_genesB= @{$group_to_file_genes;} > 0
ABresult
0X0
100
111
51 25 push( @row, 1 );
52 25 next;
53 }
54 else {
55 20 push( @row, 0 );
56 }
57 }
58 15 $self->_text_csv_obj->print( $self->_output_fh, \@row );
59 }
60 3 close( $self->_output_fh );
61 3 return $self;
62 }
63  
64 11 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 11 __PACKAGE__->meta->make_immutable;
66  
67 11 1;
68  
69 __END__
« lib/Bio/Roary/Output/NumberOfGroups.pm ↑ Summary lib/Bio/Roary/JobRunner/Role.pm »