« lib/Bio/AutomatedAnnotation/GeneNamesFromGFF.pm
↑ Summary
blib/lib/Bio/AutomatedAnnotation/SpreadsheetOfGeneOccurances.pm »
| 1 | package Bio::AutomatedAnnotation::GeneNameOccurances; | ||
| 2 | |||
| 3 | # ABSTRACT: Parse the gene names from multiple GFF files and provide a matrix of matches. | ||
| 4 | |||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use Bio::Tools::GFF; | ||
| 8 | use Bio::AutomatedAnnotation::Exceptions; | ||
| 9 | use Bio::AutomatedAnnotation::GeneNamesFromGFF; | ||
| 10 | |||
| 11 | has 'gff_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | ||
| 12 | has 'all_gene_names' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_all_gene_names' ); | ||
| 13 | has 'sorted_all_gene_names' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_sorted_all_gene_names' ); | ||
| 14 | |||
| 15 | has 'gene_name_hashes' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_gene_name_hashes' ); | ||
| 16 | has 'number_of_files' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build_number_of_files' ); | ||
| 17 | |||
| 18 | sub _build_sorted_all_gene_names | ||
| 19 | { | ||
| 20 | my ($self) = @_; | ||
| 21 | my %all_gene_names = %{$self->all_gene_names}; | ||
| 22 | |||
| 23 | my @sorted_gene_names = sort { $b cmp $a } keys %all_gene_names; | ||
| 24 | return \@sorted_gene_names; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub _build_number_of_files | ||
| 28 | { | ||
| 29 | my ($self) = @_; | ||
| 30 | return @{$self->gff_files}; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub _build_all_gene_names { | ||
| 34 | my ($self) = @_; | ||
| 35 | my %all_gene_names; | ||
| 36 | |||
| 37 | for my $filename (keys %{$self->gene_name_hashes}) | ||
| 38 | { | ||
| 39 | for my $gene_name (keys %{$self->gene_name_hashes->{$filename}}) | ||
| 40 | { | ||
| 41 | $all_gene_names{$gene_name}++; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | return \%all_gene_names; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub _build_gene_name_hashes { | ||
| 48 | my ($self) = @_; | ||
| 49 | my %gene_name_hashes; | ||
| 50 | |||
| 51 | for my $gff_file ( @{ $self->gff_files } ) { | ||
| 52 | Bio::AutomatedAnnotation::Exceptions::FileNotFound->throw( error => 'Cant open file: ' . $gff_file ) | ||
| 53 | unless ( -e $gff_file ); | ||
| 54 | my $gene_names_object = Bio::AutomatedAnnotation::GeneNamesFromGFF->new( gff_file => $gff_file ); | ||
| 55 | $gene_name_hashes{$gff_file} = $gene_names_object->gene_names ; | ||
| 56 | } | ||
| 57 | return \%gene_name_hashes; | ||
| 58 | } | ||
| 59 | |||
| 60 | no Moose; | ||
| 61 | __PACKAGE__->meta->make_immutable; | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | __END__ | ||
| 66 | |||
| 67 | =pod | ||
| 68 | |||
| 69 | =encoding UTF-8 | ||
| 70 | |||
| 71 | =head1 NAME | ||
| 72 | |||
| 73 | Bio::AutomatedAnnotation::GeneNameOccurances - Parse the gene names from multiple GFF files and provide a matrix of matches. | ||
| 74 | |||
| 75 | =head1 VERSION | ||
| 76 | |||
| 77 | version 1.182680 | ||
| 78 | |||
| 79 | =head1 SYNOPSIS | ||
| 80 | |||
| 81 | Parse the gene names from multiple GFF files and provide a matrix of matches. | ||
| 82 | use Bio::AutomatedAnnotation::GeneNameOccurances; | ||
| 83 | |||
| 84 | my $obj = Bio::AutomatedAnnotation::GeneNameOccurances->new( | ||
| 85 | gff_files => ['abc.gff','efg.gff','hij.gff'] | ||
| 86 | ); | ||
| 87 | my %all_gene_names = %{$obj->all_gene_names}; | ||
| 88 | |||
| 89 | =head1 METHODS | ||
| 90 | |||
| 91 | =head2 all_gene_names | ||
| 92 | |||
| 93 | Returns a HashRef where the keys are all observed gene names and the values are the frequency of occurance. | ||
| 94 | |||
| 95 | =head1 AUTHOR | ||
| 96 | |||
| 97 | Andrew J. Page <ap13@sanger.ac.uk> | ||
| 98 | |||
| 99 | =head1 COPYRIGHT AND LICENSE | ||
| 100 | |||
| 101 | This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. | ||
| 102 | |||
| 103 | This is free software, licensed under: | ||
| 104 | |||
| 105 | The GNU General Public License, Version 3, June 2007 | ||
| 106 | |||
| 107 | =cut |