| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 30 | 12 | chomp; | |||||||||||||||||||
| 31 | 12 | my $line = $_; | |||||||||||||||||||
| 32 | 12 | ▶ | next if ( length( $line ) < 6 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 12 | ▶ | if ( $line =~ /^.+: ([^\s]+)$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 10 | my $gene_id = $1; | |||||||||||||||||||
| 35 | 10 | ▶ | if ( $gene_id =~ /^(.+)_[\d]+$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||