WGS2NCBI/Feature.pm

filter: Statementstmt 3.9% 2 / 51 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 7 Podpod 100% 7 / 7 totaltotal 9.1% 9 / 98 CC 16 SCAR 36.2
CC
16
Cov
3%
lies_within
56.0
to_string
56.0
new
6.0
CRAP 37.4
« WGS2NCBI/TableReader.pm ↑ Summary WGS2NCBI/Config.pm »
1 package Bio::WGS2NCBI::Feature;
2  
3 4 my $IDCOUNTER = 1;
4  
5 =head1 NAME
6  
7 Bio::WGS2NCBI::Feature - base class for sequence features
8  
9 =head1 DESCRIPTION
10  
11 This is the base class for all sequence feature classes for which
12 L<Bio::WGS2NCBI> instantiates objects when reading a genome annotation.
13 In particular, this class manages the coordinates (1-based inclusive
14 start/stop) for the region(s) that the feature spans, the internal unique
15 identifiers for all features, and the serialization logic.
16  
17 The API for features is deliberately sparse as it is only intended to be
18 used by L<Bio::WGS2NCBI> and may change in future versions (e.g. in order
19 to become compatible with BioPerl features so that other annotation file
20 formats can be used as well).
21  
22 =head1 METHODS
23  
24 =over
25  
26 =item new()
27  
28 Returns a new feature. This constructor is called with the 'type'
29 argument to create any of the subclasses. For example:
30  
31 my $gene = Bio::WGS2NCBI::Feature->new( type => 'gene' );
32  
33 In addition, the values for all methods except 'qualifiers', 'id'
34 and 'to_string' can be set here by using the method name as the
35 key name of a named argument. For example:
36  
37 my $gene = Bio::WGS2NCBI::Feature->new( type => 'gene', gene => 'CO1' );
38  
39 =cut
40  
41 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
42 0 my $class = shift;
43 0 my %args = @_;
44 0 ▶ if ( $class eq __PACKAGE__ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 0 0
45 0 my $type = ucfirst lc $args{'type'};
46 0 $class =~ s/::Feature$/::${type}Feature/;
47 0 eval "require $class";
48 0 return $class->new( 'range' => [], %args );
49 }
50 0 my $self = \%args;
51 0 $self->{'id'} = $IDCOUNTER++;
52 0 return bless $self, $class;
53 }
54  
55  
56 =item seq
57  
58 Getter/setter of sequence id
59  
60 =cut
61  
62 0 ▶sub seq {
Subroutine seq: not called CC=2 SCAR=17.9
Pod documented
63 0 my $self = shift;
64 0 ▶ $self->{'seq'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
65 0 return $self->{'seq'};
66 }
67  
68 =item range()
69  
70 Returns a list of ranges, specified as start/stop coordinates,
71 that the feature spans. Optional argument ([ $start, $stop ])
72 grows the set of ranges by one additional range.
73  
74 =cut
75  
76 0 ▶sub range {
Subroutine range: not called CC=2 SCAR=17.9
Pod documented
77 0 my $self = shift;
78 0 ▶ push @{ $self->{'range'} }, shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
79 0 return @{ $self->{'range'} };
80 }
81  
82 =item lies_within
83  
84 Tests whether the invocant lies within the provided coordinates
85  
86 =cut
87  
88 0 ▶sub lies_within {
Subroutine lies_within: not called CC=7 SCAR=40.3
Pod documented
89 0 my ( $self, $start, $stop ) = @_;
90 0 $start =~ s/^[c<>]//;
91 0 $stop =~ s/^[c<>]//;
92 0 my @r = $self->range;
93 0 my $r1 = $r[0]->[0];
94 0 my $r2 = $r[-1]->[-1];
95 0 $r1 =~ s/^[c<>]//;
96 0 $r2 =~ s/^[c<>]//;
97 0 ▶ if ( $start <= $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start <= $stop) 0 0 0
98 0 ▶ if ( $r1 >= $start and $r2 <= $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r1 >= $start and $r2 <= $stop) 0 0 0
Condition0%0/3
$r1 >= $start and $r2 <= $stop
!ll&&!rl&&r
000
MC/DC0%0/2
$r1 >= $start and $r2 <= $stop
$r1 >= $start $r2 <= $stop
Truth table0%0/3
A and B
A= $r1 >= $startB= $r2 <= $stop
ABresult
0X0
100
111
99 0 return 1;
100 }
101 0 return 0;
102 }
103
104 # opposite strand
105 0 ▶ if ( $start >= $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start >= $stop) 0 0 0
106 0 ▶ if ( $r1 <= $start and $r2 >= $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r1 <= $start and $r2 >= $stop) 0 0 0
Condition0%0/3
$r1 <= $start and $r2 >= $stop
!ll&&!rl&&r
000
MC/DC0%0/2
$r1 <= $start and $r2 >= $stop
$r1 <= $start $r2 >= $stop
Truth table0%0/3
A and B
A= $r1 <= $startB= $r2 >= $stop
ABresult
0X0
100
111
107 0 return 1;
108 }
109 0 return 0;
110 }
111 }
112  
113 =item id()
114  
115 Returns a unique integer ID for the feature.
116  
117 =cut
118  
119 0 ▶sub id { shift->{'id'} }
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
120  
121 =item qualifiers()
122  
123 Returns a list of qualifier names. This is an empty ("abstract") method
124 that the subclasses need to override.
125  
126 =cut
127  
128 0 ▶sub qualifiers { }
Subroutine qualifiers: not called CC=1 SCAR=0.0
Pod documented
129  
130 =item to_string()
131  
132 Returns a string representation of the feature in NCBI's tbl format.
133  
134 =cut
135  
136 0 ▶sub to_string {
Subroutine to_string: not called CC=7 SCAR=40.3
Pod documented
137 0 my $self = shift;
138 0 my @range = $self->range;
139 0 my $result = $range[0]->[0] . "\t" . $range[0]->[1] . "\t" . $self->{'type'} . "\n";
140 0 for my $i ( 1 .. $#range ) {
141 0 $result .= $range[$i]->[0] . "\t" . $range[$i]->[1] . "\n";
142 }
143 0 for my $q ( $self->qualifiers ) {
144 0 my @values;
145 0 ▶ if ( ref $self->{$q} and ref $self->{$q} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$q} and ref $self->{$q} eq 'ARRAY') { } 0 0 0
Condition0%0/3
ref $self->{$q} and ref $self->{$q} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{$q} and ref $self->{$q} eq "ARRAY"
ref $self->{$q} ref $self->{$q} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $self->{$q}B= ref $self->{$q} eq "ARRAY"
ABresult
0X0
100
111
146 0 @values = @{ $self->{$q} };
147 }
148 else {
149 0 @values = ( $self->{$q} );
150 }
151 0 for my $v ( @values ) {
152 0 ▶ $result .= ( "\t" x 3 ) . $q . "\t" . $v . "\n" if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
153 }
154 }
155 0 return $result;
156 }
157  
158 =back
159  
160 =cut
161  
162 4 1;
« WGS2NCBI/TableReader.pm ↑ Summary WGS2NCBI/Config.pm »