| 1 | package Bio::ASN1::EntrezGene::Indexer; | ||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:BIOPERLML'; | |||||||||
| 3 | 2 | $Bio::ASN1::EntrezGene::Indexer::VERSION = '1.72'; | |||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Carp qw(carp croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Bio::ASN1::EntrezGene; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Bio::Index::AbstractSeq; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use parent qw(Bio::Index::AbstractSeq); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | # ABSTRACT: Indexes NCBI Sequence files. | ||||||||||
| 13 | # AUTHOR: Dr. Mingyi Liu <mingyiliu@gmail.com> | ||||||||||
| 14 | # OWNER: 2005 Mingyi Liu | ||||||||||
| 15 | # OWNER: 2005 GPC Biotech AG | ||||||||||
| 16 | # OWNER: 2005 Altana Research Institute | ||||||||||
| 17 | # LICENSE: Perl_5 | ||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | # TODO: Should this be deprecated? | ||||||||||
| 22 | |||||||||||
| 23 | sub _version | ||||||||||
| 24 | { | ||||||||||
| 25 | 1 | ▶ | return $Bio::Index::AbstractSeq::VERSION; | ||||||||
|
Subroutine
_version: called CC=1 SCAR=0.0
| |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | sub _type_stamp | ||||||||||
| 30 | { | ||||||||||
| 31 | 0 | ▶ | return '__EntrezGene_ASN1__'; | ||||||||
|
Subroutine
_type_stamp: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | sub _index_file | ||||||||||
| 36 | { | ||||||||||
| 37 | 2 | ▶ | my($self, $file, $idx) = @_; | ||||||||
|
Subroutine
_index_file: called CC=4 SCAR=13.9
| |||||||||||
| 38 | 2 | my $position; | |||||||||
| 39 | 2 | ▶ | open(IN, $file) || $self->throw("Can't open $file - $!"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 2 | local $/ = "Entrezgene ::= {"; | |||||||||
| 41 | 2 | ▶ | while(<IN>) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | { | ||||||||||
| 43 | 6 | chomp; | |||||||||
| 44 | 6 | ▶ | $self->add_record($1, $idx, $position) if (/[,{}]\s+geneid\s*(\d+)\s+[,{}]/i); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 6 | $position = tell(IN) - 16; # $/'s length | |||||||||
| 46 | } | ||||||||||
| 47 | 2 | close(IN); | |||||||||
| 48 | 2 | return 1; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | sub _file_format | ||||||||||
| 53 | { | ||||||||||
| 54 | 0 | ▶ | return 'entrezgene'; | ||||||||
|
Subroutine
_file_format: not called CC=1 SCAR=6.9
| |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | sub fetch_hash | ||||||||||
| 60 | { | ||||||||||
| 61 | 1 | ▶ | my ($self, $geneid) = @_; | ||||||||
|
Subroutine
fetch_hash: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 62 | 1 | ▶ | if (my $gene = $self->db->{$geneid}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | { | ||||||||||
| 64 | 1 | my ($fileno, $position) = $self->unpack_record($gene); | |||||||||
| 65 | 1 | my $parser = Bio::ASN1::EntrezGene->new('fh' => $self->_file_handle($fileno)); | |||||||||
| 66 | 1 | seek($parser->fh, $position, 0); | |||||||||
| 67 | 1 | return $parser->next_seq; | |||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | sub _file_handle { | ||||||||||
| 73 | 1 | ▶ | my( $self, $i ) = @_; | ||||||||
|
Subroutine
_file_handle: called CC=4 SCAR=14.2
| |||||||||||
| 74 | |||||||||||
| 75 | 1 | ▶ | unless ($self->{'_filehandle'}[$i]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 1 | ▶ | my @rec = $self->unpack_record($self->db->{"__FILE_$i"}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | or $self->throw("Can't get filename for index : $i"); | ||||||||||
| 78 | 1 | my $file = $rec[0]; | |||||||||
| 79 | 1 | local *FH; | |||||||||
| 80 | 1 | ▶ | open *FH, $file or $self->throw("Can't read file '$file' : $!"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 1 | $self->{'_filehandle'}[$i] = *FH; # Cache filehandle | |||||||||
| 82 | } | ||||||||||
| 83 | 1 | return $self->{'_filehandle'}[$i]; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 2 | 1; | |||||||||
| 87 | |||||||||||
| 88 | __END__ | ||||||||||