| 1 | package Bio::Roary::GeneNamesFromGFF; | ||||||||||||||
| 2 | 18 | $Bio::Roary::GeneNamesFromGFF::VERSION = '3.13.0'; | |||||||||||||
| 3 | # ABSTRACT: Parse a GFF and efficiently extract ID -> Gene Name | ||||||||||||||
| 4 | |||||||||||||||
| 5 | |||||||||||||||
| 6 | 18 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 18 | ▶ | use Bio::Tools::GFF; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 18 | with 'Bio::Roary::ParseGFFAnnotationRole'; | |||||||||||||
| 10 | |||||||||||||||
| 11 | 18 | has 'ids_to_gene_name' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_ids_to_gene_name' ); | |||||||||||||
| 12 | 42 | ▶ | has 'ids_to_product' => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 42 | ▶ | has 'ids_to_gene_size' => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | # Parsing with the perl GFF module is exceptionally slow. | ||||||||||||||
| 16 | 42 | ▶ | sub _build_ids_to_gene_name { | ||||||||||||
|
Subroutine
_build_ids_to_gene_name: called CC=8 SCAR=20.9
| |||||||||||||||
| 17 | 42 | my ($self) = @_; | |||||||||||||
| 18 | 42 | my %id_to_gene_name; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 42 | my $gffio = Bio::Tools::GFF->new( -file => $self->gff_file, -gff_version => 3 ); | |||||||||||||
| 21 | 42 | ▶ | while ( my $feature = $gffio->next_feature() ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | 641 | my $gene_id = $self->_get_feature_id($feature); | |||||||||||||
| 23 | 641 | ▶ | next unless ($gene_id); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 641 | ▶ | if ( $feature->has_tag('gene') ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 26 | 196 | my ( $gene_name, @junk ) = $feature->get_tag_values('gene'); | |||||||||||||
| 27 | 196 | $gene_name =~ s!"!!g; | |||||||||||||
| 28 | 196 | ▶ | if ( $gene_name ne "" ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | 196 | $id_to_gene_name{$gene_id} = $gene_name; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | } | ||||||||||||||
| 32 | elsif ( $feature->has_tag('Name') ) { | ||||||||||||||
| 33 | 8 | my ( $gene_name, @junk ) = $feature->get_tag_values('Name'); | |||||||||||||
| 34 | 8 | $gene_name =~ s!"!!g; | |||||||||||||
| 35 | 8 | ▶ | if ( $gene_name ne "" ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 8 | $id_to_gene_name{$gene_id} = $gene_name; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 641 | ▶ | if ( $feature->has_tag('product') ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | 641 | my ( $product, @junk ) = $feature->get_tag_values('product'); | |||||||||||||
| 42 | 641 | $self->ids_to_product->{$gene_id} = $product; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | 641 | $self->ids_to_gene_size->{$gene_id} = $feature->end - $feature->start; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 42 | return \%id_to_gene_name; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 641 | ▶ | sub _get_feature_id { | ||||||||||||
|
Subroutine
_get_feature_id: called CC=4 SCAR=14.2
| |||||||||||||||
| 51 | 641 | my ( $self, $feature ) = @_; | |||||||||||||
| 52 | 641 | my ( $gene_id, @junk ); | |||||||||||||
| 53 | 641 | ▶ | if ( $feature->has_tag('ID') ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 54 | 625 | ( $gene_id, @junk ) = $feature->get_tag_values('ID'); | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | elsif ( $feature->has_tag('locus_tag') ) { | ||||||||||||||
| 57 | 16 | ( $gene_id, @junk ) = $feature->get_tag_values('locus_tag'); | |||||||||||||
| 58 | } | ||||||||||||||
| 59 | else { | ||||||||||||||
| 60 | 0 | return undef; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | 641 | $gene_id =~ s!["']!!g; | |||||||||||||
| 63 | 641 | ▶ | return undef if ( $gene_id eq "" ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 641 | return $gene_id; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 18 | ▶ | no Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 68 | 18 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 69 | |||||||||||||||
| 70 | 18 | 1; | |||||||||||||
| 71 | |||||||||||||||
| 72 | __END__ | ||||||||||||||