Bio/SeqIO/FTHelper.pm

filter: Statementstmt 88.5% 77 / 87 Branchbran 68.1% 15 / 22 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 92.3% 12 / 13 Podpod 100% 6 / 6 totaltotal 86.4% 115 / 133 CC 18 SCAR 17.0
CC
18
Cov
85%
from_SeqFeature
9.7
_generic_seqfeature
7.0
add_field
6.0
CRAP 5.5
« Bio/SeqI.pm ↑ Summary Bio/Annotation/DBLink.pm »
1 #
2 # BioPerl module for Bio::SeqIO::FTHelper
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
7 #
8 # Copyright Ewan Birney
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::SeqIO::FTHelper - Helper class for EMBL/Genbank feature tables
17  
18 =head1 SYNOPSIS
19  
20 Used by Bio::SeqIO::EMBL,Bio::SeqIO::genbank, and Bio::SeqIO::swiss to
21 help process the Feature Table
22  
23 =head1 DESCRIPTION
24  
25 Represents one particular Feature with the following fields
26  
27 key - the key of the feature
28 loc - the location string of the feature
29 <other fields> - other fields
30  
31 =head1 FEEDBACK
32  
33 =head2 Mailing Lists
34  
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to one
37 of the Bioperl mailing lists. Your participation is much appreciated.
38  
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41  
42 =head2 Support
43  
44 Please direct usage questions or support issues to the mailing list:
45  
46 I<bioperl-l@bioperl.org>
47  
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
52  
53 =head2 Reporting Bugs
54  
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 the bugs and their resolution. Bug reports can be submitted via the web:
57  
58 https://github.com/bioperl/bioperl-live/issues
59  
60 =head1 AUTHOR - Ewan Birney
61  
62 Email birney@ebi.ac.uk
63  
64 =head1 CONTRIBUTORS
65  
66 Jason Stajich jason@bioperl.org
67  
68 =head1 APPENDIX
69  
70 The rest of the documentation details each of the object
71 methods. Internal methods are usually preceded with a _
72  
73 =cut
74  
75  
76 # Let the code begin...
77  
78  
79 package Bio::SeqIO::FTHelper;
80 25 $Bio::SeqIO::FTHelper::VERSION = '1.7.8';
81 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 25 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 25 ▶use Bio::Location::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 25 ▶use Bio::Location::Fuzzy;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 25 ▶use Bio::Location::Split;
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 25 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 9248 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
91 9248 my ($class, @args) = @_;
92  
93 # no chained new because we make lots and lots of these.
94 9248 my $self = {};
95 9248 bless $self,$class;
96 9248 $self->{'_field'} = {};
97 9248 return $self;
98 }
99  
100 =head2 _generic_seqfeature
101  
102 Title : _generic_seqfeature
103 Usage : $fthelper->_generic_seqfeature($annseq, "GenBank")
104 Function: processes fthelper into a generic seqfeature
105 Returns : TRUE on success and otherwise FALSE
106 Args : The Bio::Factory::LocationFactoryI object to use for parsing
107 location strings. The ID (e.g., display_id) of the sequence on which
108 this feature is located, optionally a string indicating the source
109 (GenBank/EMBL/SwissProt)
110  
111 =cut
112  
113 8778 ▶sub _generic_seqfeature {
Subroutine _generic_seqfeature: called CC=7 SCAR=19.5
114 8778 my ($fth, $locfac, $seqid, $source) = @_;
115 8778 my ($sf);
116  
117 # set a default if not specified
118 8778 ▶ if(! defined($source)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $source) 8387 391 8778
119 8387 $source = "EMBL/GenBank/SwissProt";
120 }
121  
122 # initialize feature object
123 8778 $sf = Bio::SeqFeature::Generic->direct_new();
124  
125 # parse location; this may cause an exception, in which case we gently
126 # recover and ignore this feature
127  
128  
129 8778 my $loc;
130 8778 eval {
131 8778 $loc = $locfac->from_string($fth->loc);
132 };
133  
134 8778 ▶ if(! $loc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loc) 0 8778 8778
135 0 $fth->warn("exception while parsing location line [" . $fth->loc .
136 "] in reading $source, ignoring feature " .
137 $fth->key() . " (seqid=" . $seqid . "): " . $@);
138 0 return;
139 }
140  
141 # set additional location attributes
142 8778 ▶ if($seqid && (! $loc->is_remote())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqid and not $loc->is_remote) 8386 392 8778
Condition100%3/3
$seqid and not $loc->is_remote
!ll&&!rl&&r
39118386
MC/DC100%2/2
$seqid and not $loc->is_remote
$seqid not $loc->is_remote
Truth table100%3/3
A and not(B)
A= $seqidB= not $loc->is_remote
ABresult
0X0
100
111
143 8386 $loc->seq_id($seqid); # propagates if it is a split location
144 }
145  
146  
147 # set attributes of feature
148 8778 $sf->location($loc);
149 8778 $sf->primary_tag($fth->key);
150 8778 $sf->source_tag($source);
151 8778 $sf->seq_id($seqid);
152 8778 foreach my $key ( keys %{$fth->field} ){
153 40563 foreach my $value ( @{$fth->field->{$key}} ) {
154 57015 $sf->add_tag_value($key,$value);
155 }
156 }
157 8778 return $sf;
158 }
159  
160  
161 =head2 from_SeqFeature
162  
163 Title : from_SeqFeature
164 Usage : @fthelperlist = Bio::SeqIO::FTHelper::from_SeqFeature($sf,
165 $context_annseq);
166 Function: constructor of fthelpers from SeqFeatures
167 :
168 : The additional annseq argument is to allow the building of FTHelper
169 : lines relevant to particular sequences (ie, when features are spread over
170 : enteries, knowing how to build this)
171 Returns : an array of FThelpers
172 Args : seq features
173  
174  
175 =cut
176  
177 470 ▶sub from_SeqFeature {
Subroutine from_SeqFeature: called CC=9 SCAR=22.7
Pod documented
178 470 my ($sf, $context_annseq) = @_;
179 470 my @ret;
180  
181 #
182 # If this object knows how to make FThelpers, then let it
183 # - this allows us to store *really* weird objects that can write
184 # themselves to the EMBL/GenBank...
185 #
186  
187 470 ▶ if ( $sf->can("to_FTHelper") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf->can("to_FTHelper")) 0 470 470
188 0 return $sf->to_FTHelper($context_annseq);
189 }
190  
191 470 my $fth = Bio::SeqIO::FTHelper->new();
192 470 my $key = $sf->primary_tag();
193 470 my $locstr = $sf->location->to_FTstring;
194  
195 # ES 25/06/01 Commented out this code, Jason to double check
196 #The location FT string for all simple subseqfeatures is already
197 #in the Split location FT string
198  
199 # going into sub features
200 #foreach my $sub ( $sf->sub_SeqFeature() ) {
201 #my @subfth = &Bio::SeqIO::FTHelper::from_SeqFeature($sub);
202 #push(@ret, @subfth);
203 #}
204  
205 470 $fth->loc($locstr);
206 470 $fth->key($key);
207 470 $fth->field->{'note'} = [];
208
209 # the lines below take specific tags (e.g. /score=23 ) and re-enter them as
210 # new tags like /note="score=25" - if the file is round-tripped this creates
211 # duplicate values
212  
213 #$sf->source_tag && do { push(@{$fth->field->{'note'}},"source=" . $sf->source_tag ); };
214  
215 #($sf->can('score') && $sf->score) && do { push(@{$fth->field->{'note'}},
216 # "score=" . $sf->score ); };
217
218 #($sf->can('frame') && $sf->frame) && do { push(@{$fth->field->{'note'}},
219 # "frame=" . $sf->frame ); };
220
221 #$sf->strand && do { push(@{$fth->field->{'note'}},"strand=" . $sf->strand ); };
222  
223 470 foreach my $tag ( $sf->get_all_tags ) {
224 # Tags which begin with underscores are considered
225 # private, and are therefore not printed
226 939 ▶ next if $tag =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^_/ 0 939 939
227 939 ▶ if ( !defined $fth->field->{$tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fth->field->{$tag}) 631 308 939
228 631 $fth->field->{$tag} = [];
229 }
230 939 foreach my $val ( $sf->get_tag_values($tag) ) {
231 1219 push(@{$fth->field->{$tag}},$val);
232 }
233 }
234 470 push(@ret, $fth);
235  
236 470 ▶ unless (@ret) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ret) 0 470 470
237 0 $context_annseq->throw("Problem in processing seqfeature $sf - no fthelpers. Error!");
238 }
239 470 foreach my $ft (@ret) {
240 470 ▶ if ( !$ft->isa('Bio::SeqIO::FTHelper') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ft->isa("Bio::SeqIO::FTHelper")) 0 470 470
241 0 $sf->throw("Problem in processing seqfeature $sf - made a $fth!");
242 }
243 }
244  
245 470 return @ret;
246 }
247  
248  
249 =head2 key
250  
251 Title : key
252 Usage : $obj->key($newval)
253 Function:
254 Example :
255 Returns : value of key
256 Args : newvalue (optional)
257  
258  
259 =cut
260  
261 18998 ▶sub key {
Subroutine key: called CC=2 SCAR=6.9
Pod documented
262 18998 my ($obj, $value) = @_;
263 18998 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 9248 9750 18998
264 9248 $obj->{'key'} = $value;
265 }
266 18998 return $obj->{'key'};
267  
268 }
269  
270 =head2 loc
271  
272 Title : loc
273 Usage : $obj->loc($newval)
274 Function:
275 Example :
276 Returns : value of loc
277 Args : newvalue (optional)
278  
279  
280 =cut
281  
282 18498 ▶sub loc {
Subroutine loc: called CC=2 SCAR=6.9
Pod documented
283 18498 my ($obj, $value) = @_;
284 18498 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 9248 9250 18498
285 9248 $obj->{'loc'} = $value;
286 }
287 18498 return $obj->{'loc'};
288 }
289  
290  
291 =head2 field
292  
293 Title : field
294 Usage :
295 Function:
296 Example :
297 Returns :
298 Args :
299  
300  
301 =cut
302  
303 167825 ▶sub field {
Subroutine field: called CC=1 SCAR=0.0
Pod documented
304 167825 my ($self) = @_;
305  
306 167825 return $self->{'_field'};
307 }
308  
309 =head2 add_field
310  
311 Title : add_field
312 Usage :
313 Function:
314 Example :
315 Returns :
316 Args :
317  
318  
319 =cut
320  
321 0 ▶sub add_field {
Subroutine add_field: not called CC=2 SCAR=17.9
Pod documented
322 0 my ($self, $key, $val) = @_;
323  
324 0 ▶ if ( !exists $self->field->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->field->{$key}) 0 0 0
325 0 $self->field->{$key} = [];
326 }
327 0 push( @{$self->field->{$key}} , $val);
328  
329 }
330  
331 25 1;
« Bio/SeqI.pm ↑ Summary Bio/Annotation/DBLink.pm »