blib/lib/HTML/ListScraper/Foam.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 87.5% 14 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 90.9% 70 / 77 CC 10 SCAR 13.8
CC
10
Cov
95%
store
7.1
_prune_map
3.0
_cond_store
2.0
CRAP 4.0
« blib/lib/HTML/ListScraper/Book.pm ↑ Summary blib/lib/HTML/ListScraper/Vat.pm »
1 package HTML::ListScraper::Foam;
2  
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 my $epsilon = 0.0001;
7  
8 12 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 12 my ($class, $book) = @_;
10 12 my $self = { book => $book, map => { } };
11 12 bless $self, $class;
12  
13 12 return $self;
14 }
15  
16 12 ▶sub get_sequences {
Subroutine get_sequences: called CC=1 SCAR=0.0
Pod undocumented
17 12 my $self = shift;
18  
19 12 my $os = $self->{max_log_score};
20 return grep {
21 12 $self->{map}->{$_}->log_score + $epsilon >= $os;
22 12 } keys %{$self->{map}};
23 }
24  
25 12 ▶sub get_occurence {
Subroutine get_occurence: called CC=1 SCAR=0.0
Pod undocumented
26 12 my ($self, $seq) = @_;
27  
28 12 return $self->{map}->{$seq};
29 }
30  
31 3638 ▶sub store {
Subroutine store: called CC=7 SCAR=19.5
Pod undocumented
32 3638 my ($self, $seq, $occ) = @_;
33  
34 3638 ▶ if (exists($self->{map}->{$seq})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"map"}{$seq}) 0 3638 3638
35 0 die "duplicated sequence";
36 }
37  
38 3638 ▶ if (!exists($self->{max_log_score})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"max_log_score"}) 13 3625 3638
39 13 $self->_cond_store($seq, $occ);
40 13 return 1;
41 }
42  
43 3625 my $s = $occ->log_score;
44 3625 my $os = $self->{max_log_score};
45 3625 ▶ if ($s + $epsilon < $os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s + $epsilon < $os) 784 2841 3625
46 784 return 0;
47 }
48  
49 2841 ▶ if ($s > $os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s > $os) { } 2466 375 2841
50 2466 ▶ if ($self->_cond_store($seq, $occ)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_cond_store($seq, $occ)) 80 2386 2466
51 80 ▶ if ($s > $os + $epsilon) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s > $os + $epsilon) 80 0 80
52 80 $self->_prune_map;
53 }
54 }
55 } else {
56 375 $self->_cond_store($seq, $occ);
57 }
58  
59 2841 return 1;
60 }
61  
62 2854 ▶sub _cond_store {
Subroutine _cond_store: called CC=2 SCAR=6.9
63 2854 my ($self, $seq, $occ) = @_;
64  
65 2854 ▶ if (!$self->{book}->is_presentable($occ->first_pos, $occ->len)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"book"}->is_presentable($occ->first_pos, $occ->len)) 2749 105 2854
66 2749 return 0;
67 }
68  
69 105 $self->{max_log_score} = $occ->log_score;
70 105 $self->{map}->{$seq} = $occ;
71 105 return 1;
72 }
73  
74 80 ▶sub _prune_map {
Subroutine _prune_map: called CC=3 SCAR=11.0
75 80 my $self = shift;
76  
77 80 my $os = $self->{max_log_score};
78 80 my @seq = keys %{$self->{map}};
79 80 foreach my $seq (@seq) {
80 173 my $s = $self->{map}->{$seq}->log_score;
81 173 ▶ if ($s + $epsilon < $os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s + $epsilon < $os) 93 80 173
82 93 delete $self->{map}->{$seq};
83 }
84 }
85 }
86  
87 10 1;
« blib/lib/HTML/ListScraper/Book.pm ↑ Summary blib/lib/HTML/ListScraper/Vat.pm »