« blib/lib/Bio/AutomatedAnnotation/SpreadsheetOfGeneOccurances.pm
↑ Summary
blib/lib/Bio/AutomatedAnnotation/Exceptions.pm »
| 1 | package Bio::AutomatedAnnotation::SpreadsheetOfGeneOccurances; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Output a spreadsheet with the gene occurances per file | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Text::CSV; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Bio::AutomatedAnnotation::Exceptions; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Bio::AutomatedAnnotation::GeneNameOccurances; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | has 'gene_occurances' => ( is => 'ro', isa => 'Bio::AutomatedAnnotation::GeneNameOccurances', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | has 'output_filename' => ( is => 'ro', isa => 'Str', default => 'gene_occurances_output.csv' ); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' ); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | has '_text_csv_obj' => ( is => 'ro', isa => 'Text::CSV', lazy => 1, builder => '_build__text_csv_obj' ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | sub _build__text_csv_obj { | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__text_csv_obj: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | return Text::CSV->new( { binary => 1, always_quote => 1, eol => "\r\n" } ); | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub _build__output_fh { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__output_fh: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | open( my $out_fh, ">", $self->output_filename ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | or Bio::AutomatedAnnotation::Exceptions::CouldntWriteToFile->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 26 | error => "Couldnt write to file: " . $self->output_filename ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | return $out_fh; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | sub _header { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | my @header = @{$self->gene_occurances->sorted_all_gene_names}; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | unshift( @header, 'File' ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | return \@header; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | sub _row { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 12 | ▶ | my ( $self, $filename ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_row: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 12 | my @row_data; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 12 | push( @row_data, $filename ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 12 | for my $gene_name ( @{ $self->gene_occurances->sorted_all_gene_names } ) { | |||||||||||||||||||||||||||||||||||||||||
| 44 | 100 | ▶ | if ( defined( $self->gene_occurances->gene_name_hashes->{$filename} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $self->gene_occurances->gene_name_hashes->{$filename} and defined $self->gene_occurances->gene_name_hashes->{$filename}{$gene_name} and $self->gene_occurances->gene_name_hashes->{$filename}{$gene_name} > 0
defined $self->gene_occurances->gene_name_hashes->{$filename} and defined $self->gene_occurances->gene_name_hashes->{$filename}{$gene_name}
MC/DC33%1/3
defined $self->gene_occurances->gene_name_hashes->{$filename} and defined $self->gene_occurances->gene_name_hashes->{$filename}{$gene_name} and $self->gene_occurances->gene_name_hashes->{$filename}{$gene_name} > 0
defined $self->gene_occurances->gene_name_hashes->{$filename}
defined $self->gene_occurances->gene_name_hashes->{$filename}{$gene_name}
$self->gene_occurances->gene_name_hashes->{$filename}{$gene_name} > 0
Truth table50%2/4
A and B and C
A= defined $self->gene_occurances->gene_name_hashes->{$filename}B= defined $self->gene_occurances->gene_name_hashes->{$filename}{$gene_name}C= $self->gene_occurances->gene_name_hashes->{$filename}{$gene_name} > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | && defined( $self->gene_occurances->gene_name_hashes->{$filename}->{$gene_name} ) | ||||||||||||||||||||||||||||||||||||||||||
| 46 | && $self->gene_occurances->gene_name_hashes->{$filename}->{$gene_name} > 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 45 | push( @row_data, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 55 | push( @row_data, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | return \@row_data; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | sub _totals { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_totals: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | my $footer = ['% Total']; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | for my $gene_name ( @{ $self->gene_occurances->sorted_all_gene_names } ) { | |||||||||||||||||||||||||||||||||||||||||
| 63 | 35 | my $percentage_total_for_gene = ( $self->gene_occurances->all_gene_names->{$gene_name} ) / $self->gene_occurances->number_of_files; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 35 | push( @{$footer}, $percentage_total_for_gene ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | return $footer; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | sub create_spreadsheet { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_spreadsheet: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | $self->_text_csv_obj->print( $self->_output_fh, $self->_header ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | for my $filename (sort keys %{ $self->gene_occurances->gene_name_hashes } ) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | $self->_text_csv_obj->print( $self->_output_fh, $self->_row($filename) ); | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | $self->_text_csv_obj->print( $self->_output_fh, $self->_totals ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | close( $self->_output_fh ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | Bio::AutomatedAnnotation::SpreadsheetOfGeneOccurances - Output a spreadsheet with the gene occurances per file | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | version 1.182680 | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | Output a spreadsheet with the gene occurances per file | ||||||||||||||||||||||||||||||||||||||||||
| 102 | use Bio::AutomatedAnnotation::SpreadsheetOfGeneOccurances; | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | my $obj = Bio::AutomatedAnnotation::SpreadsheetOfGeneOccurances->new( | ||||||||||||||||||||||||||||||||||||||||||
| 105 | gene_occurances => $gene_occurances_obj, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | output_filename => 'example.csv', | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 108 | $obj->create_spreadsheet | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =head2 create_spreadsheet | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | Save a CSV file to disk | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | Andrew J. Page <ap13@sanger.ac.uk> | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||||||||||||||