EntrezGene/Indexer.pm

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