blib/lib/Bio/SeqHash.pm

filter: Statementstmt 29.2% 12 / 41 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.0% 3 / 10 Podpod 66.6% 4 / 6 totaltotal 24.6% 19 / 77 SCAR 44.6
CC
12
Cov
20%
fa2hs
30.0
get_seqs_batch
20.0
new
12.0
CRAP 86.6
↑ Summary Build »
1 package Bio::SeqHash;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our @EXPORT_OK = qw(fa2hs);
6  
7 1 our $VERSION = '0.1.3'; # VERSION:
8 # ABSTRACT: get one or more sequences from a FASTA file quickly.
9  
10  
11 sub new {
12 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
13 0 ▶ my $self = ref $_[0] ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
14 0 ▶ $self->{file} || die `file parameter is not exist`;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"file"} or die `file parameter is not exist` 0 0 0
15 0 bless $self, $class;
16 }
17  
18  
19 sub fa2hs {
20 0 ▶ my $fa = ref $_[0] ? $_[0]->{file} : $_[0];
Subroutine fa2hs: not called CC=5 SCAR=34.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
21 0 ▶ open my $file, "<", "$fa" or die "Can not open $fa $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $file, "<", "$fa" or die "Can not open $fa $!" 0 0 0
22 0 my (%hs, $name);
23 0 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 0 0 0
24 0 chomp($line);
25 0 ▶ if ($line =~/^>(.+?)\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^>(.+?)\s/) { } 0 0 0
26 0 $name = $1;
27 } else {
28 0 $hs{$name} .= $line;
29 }
30 }
31 0 close($file);
32 0 return \%hs;
33 }
34  
35 sub _initialize {
36 0 ▶ my $self = shift;
Subroutine _initialize: not called CC=1 SCAR=6.9
37 0 $self->{id2seq} = $self->fa2hs();
38 }
39  
40  
41 sub get_id_seq {
42 0 ▶ my ($self, $id) = @_;
Subroutine get_id_seq: not called CC=2 SCAR=17.9
Pod documented
43 0 ▶ $self->_initialize() unless (exists $self->{id2seq});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"id2seq"} 0 0 0
44 0 return ">$id\n" . $self->{id2seq}->{$id} . "\n";
45 }
46  
47  
48 sub get_seq {
49 0 ▶ my ($self, $id) = @_;
Subroutine get_seq: not called CC=2 SCAR=17.9
Pod documented
50 0 ▶ $self->_initialize() unless (exists $self->{id2seq});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"id2seq"} 0 0 0
51 0 return $self->{id2seq}{$id};
52 }
53  
54  
55 sub get_seqs_batch {
56 0 ▶ my ($self, $id_file, $outfile) = @_;
Subroutine get_seqs_batch: not called CC=4 SCAR=30.0
Pod documented
57 0 ▶ open my $IN, "<", $id_file or die "Can not open $id_file $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $IN, "<", $id_file or die "Can not open $id_file $!" 0 0 0
58 0 my @ids = <$IN>;
59 0 chomp @ids;
60 0 ▶ open my $OUT, ">", $outfile or die "Can not open $outfile $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $OUT, ">", $outfile or die "Can not open $outfile $!" 0 0 0
61 0 for my $id (@ids) {
62 0 print $OUT $self->get_id_seq($id);
63 }
64 }
65  
66 # may be use later
67 ▶sub rename_seqs {
Subroutine rename_seqs: not called CC=1 SCAR=0.0
Pod undocumented
68
69 }
70  
71 1 1;
72  
73 __END__
↑ Summary Build »