WGS2NCBI/TableReader.pm

filter: Statementstmt 19.4% 13 / 67 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 5 totaltotal 11.1% 17 / 152 CC 25 SCAR 52.3
CC
25
Cov
10%
next_feature
342.0
new
30.0
callback
6.0
CRAP 186.7
« WGS2NCBI.pm ↑ Summary WGS2NCBI/Feature.pm »
1 package Bio::WGS2NCBI::TableReader;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Bio::WGS2NCBI::Feature;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Bio::WGS2NCBI::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
8 0 my $class = shift;
9 0 my %args = @_;
10 my $self = {
11 'seq' => undef,
12 'fh' => undef,
13 0 ▶ 'cb' => sub { WARN "Starting @_ without a handler" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 0 };
15
16 # set callback
17 0 ▶ if ( $args{'-cb'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-cb"}) 0 0 0
18 0 $self->{'cb'} = $args{'-cb'};
19 }
20
21 # open file
22 0 ▶ if ( $args{'-file'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'-file'}) { } 0 0 0
elsif ($args{'-handle'}) { } 0 0 0
23 0 INFO "Opening ".$args{'-file'};
24 0 ▶ open $self->{'fh'}, '<', $args{'-file'} or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"fh"}, "<", $args{"-file"} or die $! 0 0 0
25 }
26
27 # store handle
28 elsif ( $args{'-handle'} ) {
29 0 INFO "Using provided handle ".$args{'-handle'};
30 0 $self->{'fh'} = $args{'-handle'};
31 }
32
33 # need either -file or -handle
34 else {
35 0 ERROR "Need -file or -handle argument";
36 }
37
38 0 return bless $self, $class;
39 }
40  
41 0 ▶sub next_feature {
Subroutine next_feature: not called CC=18 SCAR=58.3
Pod undocumented
42 0 my $self = shift;
43 0 my $feat;
44 0 ▶ FEAT: while( my $line = readline( $self->handle ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $self->handle)) 0 0 0
45 0 chomp($line);
46  
47 # start of feature table (chunk)
48 0 ▶ if ( $line =~ /^>Features (\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^>Features (\S+)/) 0 0 0
49 0 my $seq = $1;
50
51 # deal with >Features markers in two passes: first rewind, fall through
52 # the loop, and return the (defined) $feat; second time store focal $seq
53 0 ▶ if ( $feat ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feat) { } 0 0 0
54 0 seek $self->handle, ( length($line) * -1 ) - length($/), 1;
55 0 last FEAT;
56 }
57 else {
58 0 $self->seq($seq);
59 0 $self->callback->($seq);
60 0 DEBUG "Starting features for sequence ".$self->seq;
61 }
62 }
63
64 # should be five fields
65 0 my @f = split /\t/, $line;
66 0 DEBUG join "\t", @f;
67 0 my ( $start, $stop, $type, $key, $value ) = @f;
68
69 # start of new feature, don't have one yet
70 0 ▶ if ( $type and defined $start and defined $stop and not $feat ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type and defined $start and defined $stop and not $feat) { } 0 0 0
elsif ($type and defined $start and defined $stop and $feat) { } 0 0 0
elsif ($start and $stop and not $type) { } 0 0 0
elsif (defined $key and defined $value) { } 0 0 0
Condition0%0/9
$type and defined $start and defined $stop and not $feat
!ll&&!rl&&r
000
$type and defined $start and defined $stop
!ll&&!rl&&r
000
$type and defined $start
!ll&&!rl&&r
000
MC/DC0%0/4
$type and defined $start and defined $stop and not $feat
$type defined $start defined $stop not $feat
Truth table0%0/5
A and B and C and not(D)
A= $typeB= defined $startC= defined $stopD= not $feat
ABCDresult
0XXX0
10XX0
110X0
11100
11111
71
72 # load appropriate class for feature type
73 0 DEBUG "Instantiating new $type feature";
74 0 $feat = Bio::WGS2NCBI::Feature->new( type => $type );
75
76 0 DEBUG "Setting range $start => $stop";
77 0 $feat->range([ $start => $stop ]);
78 }
79
80 # start of new feature, already have one
81 ▶ elsif ( $type and defined $start and defined $stop and $feat ) {
Condition0%0/9
$type and defined $start and defined $stop and $feat
!ll&&!rl&&r
000
$type and defined $start and defined $stop
!ll&&!rl&&r
000
$type and defined $start
!ll&&!rl&&r
000
MC/DC0%0/4
$type and defined $start and defined $stop and $feat
$type defined $start defined $stop $feat
Truth table0%0/5
A and B and C and D
A= $typeB= defined $startC= defined $stopD= $feat
ABCDresult
0XXX0
10XX0
110X0
11100
11111
82 0 DEBUG "Finishing reading feature $feat";
83
84 # seek back from current pos (3rd arg) to the start of the line,
85 # taking into account the chomped line break
86 0 seek $self->handle, ( length($line) * -1 ) - length($/), 1;
87 0 last FEAT;
88 }
89
90 # line is a range extension
91 ▶ elsif ( $start and $stop and not $type ) {
Condition0%0/6
$start and $stop and not $type
!ll&&!rl&&r
000
$start and $stop
!ll&&!rl&&r
000
MC/DC0%0/3
$start and $stop and not $type
$start $stop not $type
Truth table0%0/4
A and B and not(C)
A= $startB= $stopC= not $type
ABCresult
0XX0
10X0
1100
1111
92 0 DEBUG "Adding range $start => $stop";
93 0 $feat->range([ $start => $stop ]);
94 }
95
96 # line is an annotation
97 ▶ elsif ( defined $key and defined $value ) {
Condition0%0/3
defined $key and defined $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and defined $value
defined $key defined $value
Truth table0%0/3
A and B
A= defined $keyB= defined $value
ABresult
0X0
100
111
98 0 DEBUG "Setting '$key' to '$value'";
99 0 $feat->$key($value);
100 }
101
102 0 ▶ last FEAT if eof $self->handle;
Branch: 1 branch
BranchTrueFalseTotal
if eof $self->handle 0 0 0
103 }
104 0 return $feat;
105 }
106  
107 0 ▶sub callback {
Subroutine callback: not called CC=2 SCAR=17.9
Pod undocumented
108 0 my ( $self, $cb ) = @_;
109 0 ▶ if ( $cb ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) 0 0 0
110 0 $self->{'cb'} = $cb;
111 }
112 0 return $self->{'cb'};
113 }
114  
115 0 ▶sub seq {
Subroutine seq: not called CC=2 SCAR=17.9
Pod undocumented
116 0 my ( $self, $seq ) = @_;
117 0 ▶ if ( $seq ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 0 0 0
118 0 $self->{'seq'} = $seq;
119 }
120 0 return $self->{'seq'};
121 }
122  
123 0 ▶sub handle {
Subroutine handle: not called CC=2 SCAR=17.9
Pod undocumented
124 0 my ( $self, $handle ) = @_;
125 0 ▶ if ( $handle ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle) 0 0 0
126 0 $self->{'fh'} = $handle;
127 }
128 0 return $self->{'fh'};
129 }
130  
131  
132 4 1;
« WGS2NCBI.pm ↑ Summary WGS2NCBI/Feature.pm »