Bio/Tools/FootPrinter.pm

filter: Statementstmt 96.8% 92 / 95 Branchbran 75.0% 24 / 32 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 85.7% 132 / 154 CC 22 SCAR 21.4
CC
22
Cov
88%
_parse
15.0
_parse_predictions
6.0
_add_feature
2.0
CRAP 8.5
« Bio/Search/Result/BlastResult.pm ↑ Summary Bio/Ontology/RelationshipType.pm »
1 # BioPerl module for Bio::Tools::FootPrinter
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Shawn Hoon <shawnh@fugu-sg.org>
6 #
7 # Copyright Shawn Hoon
8 #
9 # You may distribute this module under the same terms as perl itself
10  
11 # POD documentation - main docs before the code
12  
13 =head1 NAME
14  
15 Bio::Tools::FootPrinter - write sequence features in FootPrinter format
16  
17 =head1 SYNOPSIS
18  
19 use Bio::Tools::FootPrinter;
20  
21 my $tool = Bio::Tools::FootPrinter->new(-file=>"footprinter.out");
22  
23 while (my $result = $tool->next_feature){
24 foreach my $feat($result->sub_SeqFeature){
25 print $result->seq_id."\t".$feat->start."\t".$feat->end."\t".$feat->seq->seq."\n";
26 }
27 }
28  
29 =head1 DESCRIPTION
30  
31 This module writes sequence features in FootPrinter format.
32 See L<http://bio.cs.washington.edu/software.html> for more details.
33  
34 =head1 FEEDBACK
35  
36 =head2 Mailing Lists
37  
38 User feedback is an integral part of the evolution of this and other
39 Bioperl modules. Send your comments and suggestions preferably to
40 the Bioperl mailing list. Your participation is much appreciated.
41  
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44  
45 =head2 Support
46  
47 Please direct usage questions or support issues to the mailing list:
48  
49 I<bioperl-l@bioperl.org>
50  
51 rather than to the module maintainer directly. Many experienced and
52 reponsive experts will be able look at the problem and quickly
53 address it. Please include a thorough description of the problem
54 with code and data examples if at all possible.
55  
56 =head2 Reporting Bugs
57  
58 Report bugs to the Bioperl bug tracking system to help us keep track
59 of the bugs and their resolution. Bug reports can be submitted via the
60 web:
61  
62 https://github.com/bioperl/bioperl-live/issues
63  
64 =head1 AUTHOR - Shawn Hoon
65  
66 Email shawnh@fugu-sg.org
67  
68 =head1 APPENDIX
69  
70 The rest of the documentation details each of the object methods.
71 Internal methods are usually preceded with a _
72  
73 =cut
74  
75  
76 # Let the code begin...
77  
78  
79 package Bio::Tools::FootPrinter;
80 2 $Bio::Tools::FootPrinter::VERSION = '1.7.8';
81 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 2 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶use Bio::PrimarySeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 2 ▶use base qw(Bio::Root::Root Bio::Root::IO);
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 =head2 new
89  
90 Title : new
91 Usage : my $obj = Bio::Tools::FootPrinter->new();
92 Function: Builds a new Bio::Tools::FootPrinter object
93 Returns : Bio::Tools::FootPrinter
94 Args : -fh/-file => $val, # for initing input, see Bio::Root::IO
95  
96 =cut
97  
98 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
99 1 my($class,@args) = @_;
100  
101 1 my $self = $class->SUPER::new(@args);
102 1 $self->_initialize_io(@args);
103  
104 1 return $self;
105 }
106  
107 =head2 next_feature
108  
109 Title : next_feature
110 Usage : my $r = $footprint->next_feature
111 Function: Get the next feature from parser data
112 Returns : L<Bio::SeqFeature::Generic>
113 Args : none
114  
115 =cut
116  
117 7 ▶sub next_feature{
Subroutine next_feature: called CC=2 SCAR=6.9
Pod documented
118 7 my ($self) = @_;
119 7 ▶ $self->_parse_predictions() unless $self->_predictions_parsed();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_predictions_parsed 1 6 7
120 7 return shift @{$self->{'_feature'}};
121  
122 }
123  
124 =head2 _add_feature
125  
126 Title : _add_feature
127 Usage : $footprint->_add_feature($feat)
128 Function: Add feature to array
129 Returns : none
130 Args : none
131  
132 =cut
133  
134 6 ▶sub _add_feature {
Subroutine _add_feature: called CC=2 SCAR=7.0
135 6 my ($self,$feat) = @_;
136 6 ▶ if($feat){
Branch: 1 branch
BranchTrueFalseTotal
if ($feat) 6 0 6
137 6 push @{$self->{'_feature'}},$feat;
138 }
139 }
140  
141 =head2 _parse_predictions
142  
143 Title : _parse_predictions
144 Usage : my $r = $footprint->_parse_predictions
145 Function: do the parsing
146 Returns : none
147 Args : none
148  
149 =cut
150  
151 1 ▶sub _parse_predictions {
Subroutine _parse_predictions: called CC=6 SCAR=18.0
152 1 my ($self) = @_;
153 1 $/="";
154 1 my ($seq,$second,$third,$name);
155 1 ▶ while ($_ = $self->_readline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $self->_readline) 59 1 60
156 59 chomp;
157 59 my @array = split("\n",$_);
158 59 ▶ if ($#array == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#array == 5) 0 59 59
159 # get rid of header
160 0 shift(@array); shift(@array);
161 }
162 59 ▶ if($#array == 3){
Branch: 1 branch
BranchTrueFalseTotal
if ($#array == 3) 6 53 59
163 6 ▶ if($name){
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 5 1 6
164 5 $name=~s/>//;
165 5 my $feat = $self->_parse($name,$seq,$second,$third);
166 5 $self->_add_feature($feat);
167 }
168 6 $name = shift @array;
169 6 $seq = $array[0];
170 6 $second = $array[1];
171 6 $third = $array[2];
172 6 next;
173 }
174 53 $seq .= $array[0];
175 53 $third .= $array[2];
176 }
177
178 1 ▶ $seq || return;
Branch: 1 branch
BranchTrueFalseTotal
$seq or return 1 0 1
179
180 1 $name=~s/>//;
181 1 my $feat = $self->_parse($name,$seq,$second,$third);
182 1 $self->_add_feature($feat);
183  
184 1 $self->_predictions_parsed(1);
185 }
186  
187 =head2 _predictions_parsed
188  
189 Title : _predictions_parsed
190 Usage : $footprint->_predictions_parsed(1)
191 Function: Get/Set for whether predictions parsed
192 Returns : 1/0
193 Args : none
194  
195 =cut
196  
197 8 ▶sub _predictions_parsed {
Subroutine _predictions_parsed: called CC=2 SCAR=6.9
198 8 my ($self,$val) = @_;
199 8 ▶ if($val){
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 1 7 8
200 1 $self->{'_predictions_parsed'} = $val;
201 }
202 8 return $self->{'_predictions_parsed'};
203 }
204  
205  
206 =head2 _parse
207  
208 Title : _parse
209 Usage : $footprint->_parse($name,$seq,$pattern)
210 Function: do the actual parsing
211 Returns : L<Bio::SeqFeature::Generic>
212 Args : none
213  
214 =cut
215  
216 6 ▶sub _parse {
Subroutine _parse: called CC=14 SCAR=27.1
217 6 my ($self,$name,$seq,$score,$pattern) = @_;
218 6 my @char = split('',$pattern);
219 6 my @score = split('',$score);
220  
221 6 my ($prev,$word,@words,@word_scores,$word_score);
222  
223 6 my $i = 0;
224 6 for my $c ( @char ) {
225 4702 ▶ if( ! $word) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $word) { } 6 4696 4702
elsif ($c eq $prev) { } 4677 19 4696
226 6 $word .= $c;
227 6 $prev = $c;
228 6 ▶ defined $score[$i] &&
Branch: 1 branch
BranchTrueFalseTotal
defined $score[$i] and $score[$i] =~ /\d/ and $word_score += $score[$i] 0 6 6
Condition33%1/3
defined $score[$i] and $score[$i] =~ /\d/
!ll&&!rl&&r
060
MC/DC0%0/2
defined $score[$i] and $score[$i] =~ /\d/
defined $score[$i] $score[$i] =~ /\d/
Truth table33%1/3
A and B
A= defined $score[$i]B= $score[$i] =~ /\d/
ABresult
0X0
100
111
229 ($score[$i] =~ /\d/) && ($word_score += $score[$i]);
230 } elsif ($c eq $prev){
231 4677 $word .=$c;
232 4677 $prev = $c;
233 4677 ▶ defined $score[$i] &&
Branch: 1 branch
BranchTrueFalseTotal
defined $score[$i] and $score[$i] =~ /\d/ and $word_score += $score[$i] 0 4677 4677
Condition66%2/3
defined $score[$i] and $score[$i] =~ /\d/
!ll&&!rl&&r
42034740
MC/DC0%0/2
defined $score[$i] and $score[$i] =~ /\d/
defined $score[$i] $score[$i] =~ /\d/
Truth table66%2/3
A and B
A= defined $score[$i]B= $score[$i] =~ /\d/
ABresult
0X0
100
111
234 ($score[$i] =~ /\d/) && ($word_score += $score[$i]);
235 } else {
236 # remove words with only \s
237 19 $word=~s/\s+//g;
238 19 ▶ if ($word ne ''){
Branch: 1 branch
BranchTrueFalseTotal
if ($word ne "") 12 7 19
239 12 push @words, $word;
240 12 push @word_scores, ($word_score/length($word));
241 }
242 19 $word =$c;
243 19 $prev = $c;
244 19 $word_score = 0;
245 19 ▶ defined $score[$i] &&
Branch: 1 branch
BranchTrueFalseTotal
defined $score[$i] and $score[$i] =~ /\d/ and $word_score += $score[$i] 0 19 19
Condition33%1/3
defined $score[$i] and $score[$i] =~ /\d/
!ll&&!rl&&r
1900
MC/DC0%0/2
defined $score[$i] and $score[$i] =~ /\d/
defined $score[$i] $score[$i] =~ /\d/
Truth table33%1/3
A and B
A= defined $score[$i]B= $score[$i] =~ /\d/
ABresult
0X0
100
111
246 ($score[$i] =~ /\d/) && ($word_score += $score[$i]);
247 }
248 4702 $i++;
249 }
250 6 $word =~s/\s+//g;
251 6 ▶ if( length($word) ){
Branch: 1 branch
BranchTrueFalseTotal
if (length $word) 0 6 6
252 0 push @words, $word;
253 }
254 6 my $last;
255 6 my $feat = Bio::SeqFeature::Generic->new(-seq_id=>$name);
256 6 my $offset = $i = 0;
257 6 my $count = 1;
258 6 for my $w (@words){
259 12 ▶ if(length($w) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $w) 12 0 12
260 12 my $index = index($pattern,$w,$offset);
261 12 $offset = $index + length($w);
262 12 my $subfeat = Bio::SeqFeature::Generic->new
263 ( -seq_id =>"$name-motif".$count++,
264 -start => $index+1,
265 -end => $index+length($w),
266 -source =>"FootPrinter",
267 -score => $word_scores[$i]
268 );
269 # ugh - not sure the sub_SeqFeature situation will
270 # be around forever- things should probably be
271 # grouped by a 'group' tag instead ala GFF3
272 # perhaps when Lincoln's API changes are
273 # made to SeqFeatures this will get changed
274 12 $feat->add_sub_SeqFeature($subfeat,'EXPAND');
275 }
276 12 $i++;
277 }
278 6 my $priseq = Bio::PrimarySeq->new(-id=>$name,-seq=>$seq);
279 6 $feat->attach_seq($priseq);
280 6 return $feat;
281  
282 }
283  
284 2 1;
« Bio/Search/Result/BlastResult.pm ↑ Summary Bio/Ontology/RelationshipType.pm »