Sequence/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
« EntrezGene/Indexer.pm ↑ Summary
1 package Bio::ASN1::Sequence::Indexer;
2 BEGIN {
3 2 ▶ $Bio::ASN1::Sequence::Indexer::AUTHORITY = 'cpan:BIOPERLML';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 {
6 $Bio::ASN1::Sequence::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::Sequence;
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 '__Sequence_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 $/ = "Seq-entry ::= set {";
45 while(<IN>)
46 {
47 chomp;
48 while(/[,{}]\s+accession\s*"([^"]+)"\s+[,{}]/ig) # add both dna and protein
49 {
50 $self->add_record($1, $idx, $position);
51 }
52 $position = tell(IN) - 19; # $/'s length
53 }
54 close(IN);
55 return 1;
56 }
57  
58  
59 sub _file_format
60 {
61 return 'sequence';
62 }
63  
64  
65  
66 sub fetch_hash
67 {
68 my ($self, $seqid) = @_;
69 if (my $seq = $self->db->{$seqid})
70 {
71 my ($fileno, $position) = $self->unpack_record($seq);
72 my $parser = Bio::ASN1::Sequence->new('fh' => $self->_file_handle($fileno));
73 seek($parser->fh, $position, 0);
74 return $parser->next_seq;
75 }
76 }
77  
78  
79 sub _file_handle {
80 my( $self, $i ) = @_;
81  
82 unless ($self->{'_filehandle'}[$i]) {
83 my @rec = $self->unpack_record($self->db->{"__FILE_$i"})
84 or $self->throw("Can't get filename for index : $i");
85 my $file = $rec[0];
86 local *FH;
87 open *FH, $file or $self->throw("Can't read file '$file' : $!");
88 $self->{'_filehandle'}[$i] = *FH; # Cache filehandle
89 }
90 return $self->{'_filehandle'}[$i];
91 }
92  
93 1;
94  
95 __END__
« EntrezGene/Indexer.pm ↑ Summary