lib/Bio/Roary/UniqueGenesPerSample.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 86.3% 57 / 66 CC 9 SCAR 13.3
CC
9
Cov
89%
_sample_to_gene_freq
6.1
write_unique_frequency
3.0
_build__output_fh
2.0
CRAP 3.8
« lib/Bio/Roary/Output/BlastIdentityFrequency.pm ↑ Summary lib/Bio/Roary/GroupStatistics.pm »
1 package Bio::Roary::UniqueGenesPerSample;
2 1 $Bio::Roary::UniqueGenesPerSample::VERSION = '3.13.0';
3 # ABSTRACT: Take in the clustered file and produce a sorted file with the frequency of each samples unique genes
4  
5  
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Bio::Roary::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 has 'clustered_proteins' => ( is => 'rw', isa => 'Str', default => 'clustered_proteins' );
10 1 has 'output_filename' => ( is => 'rw', isa => 'Str', default => 'unique_genes_per_sample.tsv' );
11  
12 1 has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' );
13  
14 1 ▶sub _build__output_fh {
Subroutine _build__output_fh: called CC=2 SCAR=7.1
15 1 my ($self) = @_;
16 1 ▶ 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) 1 0 1
17 or Bio::Roary::Exceptions::CouldntWriteToFile->throw( error => "Couldnt write output file:" . $self->output_filename );
18 1 return $fh;
19 }
20  
21 #group_17585: 14520_6#21_00645
22 2 ▶sub _sample_to_gene_freq {
Subroutine _sample_to_gene_freq: called CC=6 SCAR=18.2
23 2 my ($self) = @_;
24  
25 2 ▶ open( my $input_fh, $self->clustered_proteins )
Branch: 1 branch
BranchTrueFalseTotal
open my $input_fh, $self->clustered_proteins or "Bio::Roary::Exceptions::FileNotFound"->throw("error", 'Couldnt read input file:' . $self->clustered_proteins) 2 0 2
26 or Bio::Roary::Exceptions::FileNotFound->throw( error => "Couldnt read input file:" . $self->clustered_proteins );
27  
28 2 my %sample_to_gene_freq;
29 2 ▶ while (<$input_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $input_fh)) 12 2 14
30 12 chomp;
31 12 my $line = $_;
32 12 ▶ next if ( length( $line ) < 6 );
Branch: 1 branch
BranchTrueFalseTotal
if length $line < 6 0 12 12
33 12 ▶ if ( $line =~ /^.+: ([^\s]+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^.+: ([^\s]+)$/) { } 10 2 12
34 10 my $gene_id = $1;
35 10 ▶ if ( $gene_id =~ /^(.+)_[\d]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gene_id =~ /^(.+)_[\d]+$/) { } 10 0 10
36 10 my $sample_name = $1;
37 10 $sample_to_gene_freq{$sample_name}++;
38 }
39 else {
40 # gene id may not be valid so ignore
41 0 next;
42 }
43 }
44 else {
45 # its either an invalid line or theres more than 1 gene in the cluster
46 2 next;
47 }
48 }
49  
50 2 return \%sample_to_gene_freq;
51 }
52  
53 1 ▶sub write_unique_frequency {
Subroutine write_unique_frequency: called CC=3 SCAR=11.0
Pod undocumented
54 1 my ($self) = @_;
55  
56 1 my %sample_to_gene_freq = %{$self->_sample_to_gene_freq};
57
58 1 ▶ for my $sample ( sort { $sample_to_gene_freq{$b} <=> $sample_to_gene_freq{$a} || $a cmp $b } keys %sample_to_gene_freq ) {
Condition66%2/3
$sample_to_gene_freq{$b} <=> $sample_to_gene_freq{$a} || $a cmp $b
l!l&&r!l&&!r
220
MC/DC0%0/2
$sample_to_gene_freq{$b} <=> $sample_to_gene_freq{$a} || $a cmp $b
$sample_to_gene_freq{$b} <=> $sample_to_gene_freq{$a} $a cmp $b
Truth table66%2/3
A || B
A= $sample_to_gene_freq{$b} <=> $sample_to_gene_freq{$a}B= $a cmp $b
ABresult
1X1
011
000
59 4 print { $self->_output_fh } $sample . "\t" . $sample_to_gene_freq{$sample} . "\n";
60 }
61 1 close($self->_output_fh);
62 1 return 1;
63 }
64  
65 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 __PACKAGE__->meta->make_immutable;
67  
68 1 1;
69  
70 __END__
« lib/Bio/Roary/Output/BlastIdentityFrequency.pm ↑ Summary lib/Bio/Roary/GroupStatistics.pm »