Bio/SearchIO/rnamotif.pm

filter: Statementstmt 88.6% 195 / 220 Branchbran 60.5% 86 / 142 Conditioncond 38.7% 24 / 62 MC/DCmcdc 13.1% 5 / 38 Subroutinesub 91.3% 21 / 23 Podpod 100% 19 / 19 totaltotal 69.4% 350 / 504 CC 96 SCAR 37.7
CC
96
Cov
72%
next_result
109.7
_initialize
12.6
element_hash
12.1
CRAP 43.3
« Bio/SeqFeature/Gene/Intron.pm ↑ Summary Bio/SearchIO/sim4.pm »
1 #
2 # BioPerl module for Bio::SearchIO::rnamotif
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Chris Fields <cjfields-at-uiuc-dot-edu>
7 #
8 # Copyright Chris Fields
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::SearchIO::rnamotif - SearchIO-based RNAMotif parser
17  
18 =head1 SYNOPSIS
19  
20 # do not call this module directly. Use Bio::SearchIO.
21  
22 =head1 DESCRIPTION
23  
24 This is a highly experimental SearchIO-based parser for output from the rnamotif
25 program (one of the programs in the RNAMotif suite). It currently parses only
26 raw rnamotif output for RNAMotif versions 3.0 and above; older versions may work
27 but will not be supported. rmfmt output will not be supported at this time.
28  
29 =head1 FEEDBACK
30  
31 =head2 Mailing Lists
32  
33 User feedback is an integral part of the evolution of this and other
34 Bioperl modules. Send your comments and suggestions preferably to
35 the Bioperl mailing list. Your participation is much appreciated.
36  
37 bioperl-l@bioperl.org - General discussion
38 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
39  
40 =head2 Support
41  
42 Please direct usage questions or support issues to the mailing list:
43  
44 I<bioperl-l@bioperl.org>
45  
46 rather than to the module maintainer directly. Many experienced and
47 reponsive experts will be able look at the problem and quickly
48 address it. Please include a thorough description of the problem
49 with code and data examples if at all possible.
50  
51 =head2 Reporting Bugs
52  
53 Report bugs to the Bioperl bug tracking system to help us keep track
54 of the bugs and their resolution. Bug reports can be submitted via the
55 web:
56  
57 https://github.com/bioperl/bioperl-live/issues
58  
59 =head1 AUTHOR - Chris Fields
60  
61 Email cjfields-at-uiuc-dot-edu
62  
63 =head1 APPENDIX
64  
65 The rest of the documentation details each of the object methods.
66 Internal methods are usually preceded with a _
67  
68 =cut
69  
70 # Let the code begin...
71  
72 package Bio::SearchIO::rnamotif;
73 2 $Bio::SearchIO::rnamotif::VERSION = '1.7.8';
74 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 2 ▶use base qw(Bio::SearchIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 2 my %MODEMAP = (
79 'Result' => 'result',
80 'Hit' => 'hit',
81 'Hsp' => 'hsp'
82 );
83  
84 2 my %MAPPING = (
85 # commented out tags have not been assigned
86
87 'Hsp_score' => 'HSP-score',
88 'Hsp_custom-data' => 'HSP-custom_score',
89
90 # rnamotif has no evalue
91
92 # descriptor has no start, end; same as hit start, end
93 'Hsp_query-from' => 'HSP-query_start',
94 'Hsp_query-to' => 'HSP-query_end',
95 'Hsp_hit-from' => 'HSP-hit_start',
96 'Hsp_hit-to' => 'HSP-hit_end',
97
98 # descriptor has no start, end
99
100 'Hsp_hseq' => 'HSP-hit_seq',
101 'Hsp_align-len' => 'HSP-hsp_length',
102
103 # build this from scratch, simple WUSS-format
104 'Hsp_structure' => 'HSP-meta',
105 'Hsp_stranded' => 'HSP-stranded',
106
107 # not supported for RNAMotif
108  
109 'Hit_id' => 'HIT-name',
110 'Hit_accession' => 'HIT-accession',
111 'Hit_gi' => 'HIT-ncbi_gi',
112 'Hit_def' => 'HIT-description',
113 'Hit_score' => 'HIT-score', # best HSP score
114
115 'RNAMotif_program' => 'RESULT-algorithm_name', # get/set
116 'RNAMotif_version' => 'RESULT-algorithm_version', # get/set
117 'RNAMotif_query-def'=> 'RESULT-query_name', # get/set
118 # No length (query is a descriptor)
119 'RNAMotif_query-acc'=> 'RESULT-query_accession', # get/set
120 'RNAMotif_querydesc'=> 'RESULT-query_description', # get/set
121 'RNAMotif_db' => 'RESULT-database_name', # get/set
122 );
123  
124 # use structure_delimiters to set custom delimiters
125  
126 2 my @VALID_SYMBOLS = qw(5-prime 3-prime single-strand unknown);
127 2 my %STRUCTURE_SYMBOLS = (
128 '5-prime' => '<',
129 '3-prime' => '>',
130 'single-strand' => '.',
131 'unknown' => '?'
132 # may add more for quartets, triplets
133 );
134  
135 2 my $DEFAULT_VERSION = '3.0.3';
136  
137 =head2 new
138  
139 Title : new
140 Usage : my $obj = Bio::SearchIO->new();
141 Function: Builds a new Bio::SearchIO::rnamotif object
142 Returns : Bio::SearchIO::rnamotif parser
143 Args : -fh/-file => RNAMotif filename
144 -format => 'rnamotif'
145 -model => query model (or descriptor, in this case)
146 -database => database name (default undef)
147 -query_acc => query accession (default undef)
148 -hsp_minscore => minimum HSP score cutoff
149 -hsp_maxscore => maximum HSP score cutoff
150 -symbols => hash ref of structure symbols to use
151 (default symbols in %STRUCTURE_SYMBOLS hash)
152  
153 =cut
154  
155 1 ▶sub _initialize {
Subroutine _initialize: called CC=10 SCAR=25.4
156 1 my ( $self, @args ) = @_;
157 1 $self->SUPER::_initialize(@args);
158 1 my ($version, $model, $database, $maxcutoff, $mincutoff, $seqdistance,
159 $accession, $symbols) =
160 $self->_rearrange([qw(VERSION MODEL DATABASE HSP_MAXSCORE
161 HSP_MINSCORE SEQ_DISTANCE QUERY_ACC SYMBOLS)],@args);
162 1 my $handler = $self->_eventHandler;
163 1 $handler->register_factory(
164 'result',
165 Bio::Factory::ObjectFactory->new(
166 -type => 'Bio::Search::Result::GenericResult',
167 -interface => 'Bio::Search::Result::ResultI',
168 -verbose => $self->verbose
169 )
170 );
171  
172 1 $handler->register_factory(
173 'hit',
174 Bio::Factory::ObjectFactory->new(
175 -type => 'Bio::Search::Hit::ModelHit',
176 -interface => 'Bio::Search::Hit::HitI',
177 -verbose => $self->verbose
178 )
179 );
180  
181 1 $handler->register_factory(
182 'hsp',
183 Bio::Factory::ObjectFactory->new(
184 -type => 'Bio::Search::HSP::ModelHSP',
185 -interface => 'Bio::Search::HSP::HSPI',
186 -verbose => $self->verbose
187 )
188 );
189 1 ▶ $model && $self->model($model);
Branch: 1 branch
BranchTrueFalseTotal
$model and $self->model($model) 1 0 1
190 1 ▶ $database && $self->database($database);
Branch: 1 branch
BranchTrueFalseTotal
$database and $self->database($database) 1 0 1
191 1 ▶ $accession && $self->query_accession($accession);
Branch: 1 branch
BranchTrueFalseTotal
$accession and $self->query_accession($accession) 1 0 1
192 1 ▶ $version ||= $DEFAULT_VERSION;
Condition33%1/3
$version ||= $DEFAULT_VERSION
l!l&&r!l&&!r
010
MC/DC0%0/2
$version ||= $DEFAULT_VERSION
$version $DEFAULT_VERSION
Truth table33%1/3
A ||= B
A= $versionB= $DEFAULT_VERSION
ABresult
1X1
011
000
193 1 $self->algorithm_version($version);
194 1 ▶ $self->throw("Cannot define both a minimal and maximal cutoff")
Branch: 1 branch
BranchTrueFalseTotal
if defined $mincutoff and defined $maxcutoff 0 1 1
Condition33%1/3
defined $mincutoff and defined $maxcutoff
!ll&&!rl&&r
100
MC/DC0%0/2
defined $mincutoff and defined $maxcutoff
defined $mincutoff defined $maxcutoff
Truth table33%1/3
A and B
A= defined $mincutoffB= defined $maxcutoff
ABresult
0X0
100
111
195 if (defined($mincutoff) && defined($maxcutoff));
196 1 ▶ defined($mincutoff) && $self->hsp_minscore($mincutoff);
Branch: 1 branch
BranchTrueFalseTotal
defined $mincutoff and $self->hsp_minscore($mincutoff) 0 1 1
197 1 ▶ defined($maxcutoff) && $self->hsp_maxscore($maxcutoff);
Branch: 1 branch
BranchTrueFalseTotal
defined $maxcutoff and $self->hsp_maxscore($maxcutoff) 0 1 1
198 1 ▶ $symbols ||= \%STRUCTURE_SYMBOLS;
Condition50%1/2
$symbols ||= \%STRUCTURE_SYMBOLS
l!l
01
MC/DC0%0/1
$symbols ||= \%STRUCTURE_SYMBOLS
$symbols
Truth table50%1/2
A
A= $symbols
Aresult
11
00
199 1 $self->structure_symbols($symbols);
200 }
201  
202 =head2 next_result
203  
204 Title : next_result
205 Usage : my $hit = $searchio->next_result;
206 Function: Returns the next Result from a search
207 Returns : Bio::Search::Result::ResultI object
208 Args : none
209  
210 =cut
211  
212 1 ▶sub next_result {
Subroutine next_result: called CC=42 SCAR=47.0
Pod documented
213 1 my ($self) = @_;
214 1 my $seentop = 0;
215 1 local $/ = "\n";
216 1 local $_;
217 1 my ($rm, $d, $descriptor, $file, $oktobuild);
218 1 my ($hitid, $hitdesc, $hspid, $lastid, $lastscore);
219 1 my $sprintf;
220
221 # user-determined Result data
222 1 my ($accession, $db, $model) =
223 ($self->query_accession, $self->database, $self->model);
224 # HSP building options
225 1 my $hsp_min = $self->hsp_minscore;
226 1 my $hsp_max = $self->hsp_maxscore;
227 1 my $version = $self->algorithm_version;
228 1 my $laststart;
229
230 1 my $verbose = $self->verbose; # cache for speed?
231 1 $self->start_document();
232 PARSER:
233 1 ▶ while ( defined( my $line = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline)) 199 1 200
234 # start of report
235 199 ▶ next if $line =~ m{^\s+$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s+$/ 0 199 199
236 199 ▶ if (index($line,'#RM') == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (index($line, '#RM') == 0) { } 3 196 199
elsif ($line =~ s/^>//) { } 98 98 196
elsif ($line =~ /^(\S+)\s+(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s(.*)$/mx) { } 98 0 98
237 3 ▶ if (index($line,'#RM scored') == 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (index($line, '#RM scored') == 0) { } 1 2 3
elsif (index($line, '#RM descr') == 0) { } 1 1 2
elsif (index($line, '#RM dfile') == 0) { } 1 0 1
238 1 ▶ if ($seentop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seentop) 0 1 1
239 0 $self->_pushback($line);
240 0 last PARSER;
241 }
242 1 $self->start_element({'Name' => 'Result'});
243 1 $self->element_hash({
244 'RNAMotif_program' => 'rnamotif',
245 'RNAMotif_version' => $version,
246 'RNAMotif_query-acc' => $accession,
247 'RNAMotif_db' => $db
248 });
249 1 $seentop = 1;
250 #$self->debug("Start result\n");
251 } elsif (index($line,'#RM descr') == 0) {
252 1 ($rm, $d, $descriptor) = split ' ', $line, 3;
253 # toss $rm, $d; keep $descr
254 1 chomp $descriptor;
255 1 $self->{'_descriptor'} = $descriptor;
256 1 $self->element(
257 {'Name' => 'RNAMotif_querydesc',
258 'Data' => $descriptor}
259 );
260 } elsif(index($line,'#RM dfile') == 0) {
261 1 ($rm, $d, $file) = split ' ', $line, 3;
262 # toss $rm, $d; keep $file
263 1 chomp $file;
264 1 $self->element(
265 {'Name' => 'RNAMotif_query-def',
266 'Data' => $file}
267 );
268 } else {
269 0 $self->debug("Unrecognized line: $line");
270 }
271 } elsif ($line =~ s{^>}{}) {
272 98 chomp $line;
273 98 ($hitid, $hitdesc) = split ' ',$line,2;
274
275 98 ▶ if ($self->within_element('hit') && ($hitid ne $lastid)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->within_element('hit') and $hitid ne $lastid) { } 27 71 98
elsif (not $self->within_element('hit')) { } 1 70 71
Condition100%3/3
$self->within_element("hit") and $hitid ne $lastid
!ll&&!rl&&r
17027
MC/DC100%2/2
$self->within_element("hit") and $hitid ne $lastid
$self->within_element("hit") $hitid ne $lastid
Truth table100%3/3
A and B
A= $self->within_element("hit")B= $hitid ne $lastid
ABresult
0X0
100
111
276 27 ▶ $self->element(
Branch: 1 branch
BranchTrueFalseTotal
if $lastscore 0 27 27
277 {'Name' => 'Hit_score',
278 'Data' => $lastscore}
279 ) if $lastscore;
280 27 $self->end_element({'Name' => 'Hit'});
281 27 $self->start_element({'Name' => 'Hit'});
282 } elsif (!$self->within_element('hit')) {
283 1 $self->start_element({'Name' => 'Hit'});
284 }
285 98 my ($gi, $acc, $ver) = $self->_get_seq_identifiers($hitid);
286
287 98 ▶ $self->element_hash({
Branch: 2 branches
BranchTrueFalseTotal
$ver ? : 0 98 98
$acc ? : 98 0 98
288 'Hit_id' => $hitid,
289 'Hit_gi' => $gi,
290 'Hit_accession' => $ver ? "$acc.$ver" :
291 $acc ? $acc : $hitid,
292 'Hit_def' => $hitdesc}
293 );
294 98 $lastid = $hitid;
295 } elsif ($line =~ m{^(\S+)\s+(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s(.*)$}xm) {
296 98 chomp $line;
297 98 my $hspid = $1;
298 98 my ($score, $strand, $start, $length , $seq) = ($2, $3, $4, $5, $6);
299 98 $score *= 1; # implicitly cast any odd '0.000' to float
300 # sanity check ids
301 98 ▶ unless ($hitid eq $hspid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hitid eq $hspid) 0 98 98
302 0 $self->throw("IDs do not match!");
303 }
304 # check score for possible sprintf data, mark as such, cache result
305 98 ▶ if (!defined($sprintf)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sprintf) 1 97 98
306 1 ▶ if ($score =~ m{[^0-9.-]+}gxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($score =~ /[^0-9.-]+/gmsx) { } 0 1 1
307 0 ▶ if (defined $hsp_min || defined $hsp_max ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hsp_min or defined $hsp_max) 0 0 0
Condition0%0/3
defined $hsp_min or defined $hsp_max
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $hsp_min or defined $hsp_max
defined $hsp_min defined $hsp_max
Truth table0%0/3
A or B
A= defined $hsp_minB= defined $hsp_max
ABresult
1X1
011
000
308 0 $self->warn("HSP data likely contains custom score; ".
309 "ignoring min/maxscore");
310 }
311 0 $sprintf = $oktobuild = 1;
312 } else {
313 1 $sprintf = 0;
314 }
315 }
316
317 98 ▶ if (!$sprintf) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sprintf) 98 0 98
318 98 ▶ if (($hsp_min && $score <= $hsp_min)
Branch: 1 branch
BranchTrueFalseTotal
if ($hsp_min and $score <= $hsp_min or $hsp_max and $score >= $hsp_max) { } 0 98 98
Condition33%3/9
$hsp_min and $score <= $hsp_min or $hsp_max and $score >= $hsp_max
l!l&&r!l&&!r
0098
$hsp_min and $score <= $hsp_min
!ll&&!rl&&r
9800
$hsp_max and $score >= $hsp_max
!ll&&!rl&&r
9800
MC/DC0%0/4
$hsp_min and $score <= $hsp_min or $hsp_max and $score >= $hsp_max
$hsp_min $score <= $hsp_min $hsp_max $score >= $hsp_max
Truth table14%1/7
A and B or C and D
A= $hsp_minB= $score <= $hsp_minC= $hsp_maxD= $score >= $hsp_max
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
319 || ($hsp_max && ($score >= $hsp_max)) ) {
320 # do not build HSP
321 0 $oktobuild = 0;
322 } else {
323 98 $oktobuild = 1;
324
325 # store best hit score based on the hsp min/maxscore only
326 98 ▶ if (defined $hsp_min && $score > $hsp_min) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $hsp_min and $score > $hsp_min) { } 0 98 98
elsif (defined $hsp_max and $score < $hsp_max) { } 0 196 196
Condition33%1/3
defined $hsp_min and $score > $hsp_min
!ll&&!rl&&r
9800
MC/DC0%0/2
defined $hsp_min and $score > $hsp_min
defined $hsp_min $score > $hsp_min
Truth table33%1/3
A and B
A= defined $hsp_minB= $score > $hsp_min
ABresult
0X0
100
111
327 0 ▶ $lastscore = $score if !$lastscore || $score > $lastscore;
Branch: 1 branch
BranchTrueFalseTotal
if not $lastscore or $score > $lastscore 0 0 0
Condition0%0/3
not $lastscore or $score > $lastscore
l!l&&r!l&&!r
000
MC/DC0%0/2
not $lastscore or $score > $lastscore
not $lastscore $score > $lastscore
Truth table0%0/3
not(A) or B
A= not $lastscoreB= $score > $lastscore
ABresult
1X1
011
000
328 ▶ } elsif (defined $hsp_max && $score < $hsp_max) {
Condition33%1/3
defined $hsp_max and $score < $hsp_max
!ll&&!rl&&r
9800
MC/DC0%0/2
defined $hsp_max and $score < $hsp_max
defined $hsp_max $score < $hsp_max
Truth table33%1/3
A and B
A= defined $hsp_maxB= $score < $hsp_max
ABresult
0X0
100
111
329 0 ▶ $lastscore = $score if !$lastscore || $score < $lastscore;
Branch: 1 branch
BranchTrueFalseTotal
if not $lastscore or $score < $lastscore 0 0 0
Condition0%0/3
not $lastscore or $score < $lastscore
l!l&&r!l&&!r
000
MC/DC0%0/2
not $lastscore or $score < $lastscore
not $lastscore $score < $lastscore
Truth table0%0/3
not(A) or B
A= not $lastscoreB= $score < $lastscore
ABresult
1X1
011
000
330 }
331 }
332 }
333
334 # build HSP
335 98 ▶ if ($oktobuild) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oktobuild) 98 0 98
336 98 my $end;
337 # calculate start/end
338 98 ▶ if( $strand==0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand == 0) { } 98 0 98
339 98 $end = $start + $length -1;
340 } else {
341 0 $end = $start - $length + 1;
342 }
343
344 98 my ($rna, $meta) = $self->_motif2meta($seq, $descriptor);
345
346 98 $self->start_element({'Name' => 'Hsp'});
347 98 my $rnalen = $rna =~ tr{ATGCatgc}{ATGCatgc};
348 98 ▶ $self->element_hash({
Branch: 2 branches
BranchTrueFalseTotal
$sprintf ? : 0 98 98
$sprintf ? : 0 98 98
349 'Hsp_stranded' => 'HIT',
350 'Hsp_hseq' => $rna,
351 'Hsp_query-from' => 1,
352 'Hsp_query-to' =>length($rna),
353 'Hsp_hit-from' => $start,
354 'Hsp_hit-to' => $end,
355 'Hsp_structure' => $meta,
356 'Hsp_align-len' => length($rna),
357 'Hsp_score' => $sprintf ? undef : $score,
358 'Hsp_custom-data' => $sprintf ? $score : undef,
359 });
360 98 $self->end_element({'Name' => 'Hsp'});
361 98 ▶ $oktobuild = 0 if (!$sprintf);
Branch: 1 branch
BranchTrueFalseTotal
unless $sprintf 98 0 98
362 }
363 }
364 }
365 1 ▶ if ($self->within_element('hit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->within_element("hit")) 1 0 1
366 1 ▶ $self->element(
Branch: 1 branch
BranchTrueFalseTotal
if $lastscore 0 1 1
367 {'Name' => 'Hit_score',
368 'Data' => $lastscore}
369 ) if $lastscore;
370 1 $self->end_element( { 'Name' => 'Hit' } );
371 }
372 1 ▶ if ($seentop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seentop) 1 0 1
373 1 $self->end_element( { 'Name' => 'Result' } );
374 }
375 1 return $self->end_document();
376 }
377  
378 =head2 start_element
379  
380 Title : start_element
381 Usage : $eventgenerator->start_element
382 Function: Handles a start element event
383 Returns : none
384 Args : hashref with at least 2 keys 'Data' and 'Name'
385  
386  
387 =cut
388  
389 127 ▶sub start_element {
Subroutine start_element: called CC=5 SCAR=16.2
Pod documented
390 127 my ( $self, $data ) = @_;
391  
392 # we currently don't care about attributes
393 127 my $nm = $data->{'Name'};
394 127 my $type = $MODEMAP{$nm};
395 127 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 127 0 127
396 127 ▶ if ( $self->_eventHandler->will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eventHandler->will_handle($type)) 127 0 127
397 127 my $func = sprintf( "start_%s", lc $type );
398 127 $self->_eventHandler->$func( $data->{'Attributes'} );
399 }
400 127 unshift @{ $self->{'_elements'} }, $type;
401 }
402 127 ▶ if ( defined $type
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type and $type eq "result") 1 126 127
Condition66%2/3
defined $type and $type eq "result"
!ll&&!rl&&r
01261
MC/DC50%1/2
defined $type and $type eq "result"
defined $type $type eq "result"
Truth table66%2/3
A and B
A= defined $typeB= $type eq "result"
ABresult
0X0
100
111
403 && $type eq 'result' )
404 {
405 1 $self->{'_values'} = {};
406 1 $self->{'_result'} = undef;
407 }
408 }
409  
410 =head2 end_element
411  
412 Title : start_element
413 Usage : $eventgenerator->end_element
414 Function: Handles an end element event
415 Returns : none
416 Args : hashref with at least 2 keys, 'Data' and 'Name'
417  
418  
419 =cut
420  
421 129 ▶sub end_element {
Subroutine end_element: called CC=7 SCAR=20.2
Pod documented
422 129 my ( $self, $data ) = @_;
423 129 my $nm = $data->{'Name'};
424 129 my $type = $MODEMAP{$nm};
425 129 my $rc;
426  
427 129 ▶ if ($type) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type) { } 127 2 129
elsif ($MAPPING{$nm}) { } 2 0 2
428 127 ▶ if ( $self->_eventHandler->will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eventHandler->will_handle($type)) 127 0 127
429 127 my $func = sprintf( "end_%s", lc $type );
430 $rc = $self->_eventHandler->$func( $self->{'_reporttype'},
431 127 $self->{'_values'} );
432 }
433 127 my $lastelem = shift @{ $self->{'_elements'} };
434 }
435 elsif ( $MAPPING{$nm} ) {
436 2 ▶ if ( ref( $MAPPING{$nm} ) =~ /hash/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($MAPPING{$nm}) =~ /hash/i) { } 0 2 2
437 0 my $key = ( keys %{ $MAPPING{$nm} } )[0];
438 $self->{'_values'}->{$key}->{ $MAPPING{$nm}->{$key} } =
439 0 $self->{'_last_data'};
440 }
441 else {
442 2 $self->{'_values'}->{ $MAPPING{$nm} } = $self->{'_last_data'};
443 }
444 }
445 else {
446 0 $self->debug("unknown nm $nm, ignoring\n");
447 }
448 129 $self->{'_last_data'} = ''; # remove read data if we are at
449 # end of an element
450 129 ▶ $self->{'_result'} = $rc if ( defined $type && $type eq 'result' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and $type eq "result" 1 128 129
Condition100%3/3
defined $type and $type eq "result"
!ll&&!rl&&r
21261
MC/DC100%2/2
defined $type and $type eq "result"
defined $type $type eq "result"
Truth table100%3/3
A and B
A= defined $typeB= $type eq "result"
ABresult
0X0
100
111
451 129 return $rc;
452 }
453  
454 =head2 element
455  
456 Title : element
457 Usage : $eventhandler->element({'Name' => $name, 'Data' => $str});
458 Function: Convenience method that calls start_element, characters, end_element
459 Returns : none
460 Args : Hash ref with the keys 'Name' and 'Data'
461  
462  
463 =cut
464  
465 2 ▶sub element {
Subroutine element: called CC=1 SCAR=0.0
Pod documented
466 2 my ( $self, $data ) = @_;
467 # simple data calls (%MAPPING) do not need start_element
468 2 $self->characters($data);
469 2 $self->end_element($data);
470 }
471  
472  
473 =head2 element_hash
474  
475 Title : element
476 Usage : $eventhandler->element_hash({'Hsp_hit-from' => $start,
477 'Hsp_hit-to' => $end,
478 'Hsp_score' => $lastscore});
479 Function: Convenience method that takes multiple simple data elements and
480 maps to appropriate parameters
481 Returns : none
482 Args : Hash ref with the mapped key (in %MAPPING) and value
483  
484 =cut
485  
486 197 ▶sub element_hash {
Subroutine element_hash: called CC=8 SCAR=24.9
Pod documented
487 197 my ($self, $data) = @_;
488 197 ▶ $self->throw("Must provide data hash ref") if !$data || !ref($data);
Branch: 1 branch
BranchTrueFalseTotal
unless $data and ref $data 0 197 197
Condition33%1/3
$data and ref $data
!ll&&!rl&&r
00197
MC/DC0%0/2
$data and ref $data
$data ref $data
Truth table33%1/3
A and B
A= $dataB= ref $data
ABresult
0X0
100
111
489 197 for my $nm (sort keys %{$data}) {
490 1376 ▶ next if $data->{$nm} && $data->{$nm} =~ m{^\s*$}o;
Branch: 1 branch
BranchTrueFalseTotal
if $data->{$nm} and $data->{$nm} =~ /^\s*$/o 0 1376 1376
Condition66%2/3
$data->{$nm} and $data->{$nm} =~ /^\s*$/o
!ll&&!rl&&r
19611800
MC/DC0%0/2
$data->{$nm} and $data->{$nm} =~ /^\s*$/o
$data->{$nm} $data->{$nm} =~ /^\s*$/o
Truth table66%2/3
A and B
A= $data->{$nm}B= $data->{$nm} =~ /^\s*$/o
ABresult
0X0
100
111
491 1376 ▶ if ( $MAPPING{$nm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MAPPING{$nm}) 1376 0 1376
492 1376 ▶ if ( ref( $MAPPING{$nm} ) =~ /hash/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($MAPPING{$nm}) =~ /hash/i) { } 0 1376 1376
493 0 my $key = ( keys %{ $MAPPING{$nm} } )[0];
494 $self->{'_values'}->{$key}->{ $MAPPING{$nm}->{$key} } =
495 0 $data->{$nm};
496 }
497 else {
498 1376 $self->{'_values'}->{ $MAPPING{$nm} } = $data->{$nm};
499 }
500 }
501 }
502 }
503  
504 =head2 characters
505  
506 Title : characters
507 Usage : $eventgenerator->characters($str)
508 Function: Send a character events
509 Returns : none
510 Args : string
511  
512  
513 =cut
514  
515 2 ▶sub characters {
Subroutine characters: called CC=3 SCAR=12.5
Pod documented
516 2 my ( $self, $data ) = @_;
517 2 ▶ return unless ( defined $data->{'Data'} && $data->{'Data'} !~ /^\s+$/o );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/o 0 2 2
Condition33%1/3
defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/o
!ll&&!rl&&r
002
MC/DC0%0/2
defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/o
defined $data->{"Data"} not $data->{"Data"} =~ /^\s+$/o
Truth table33%1/3
A and not(B)
A= defined $data->{"Data"}B= not $data->{"Data"} =~ /^\s+$/o
ABresult
0X0
100
111
518 2 $self->{'_last_data'} = $data->{'Data'};
519 }
520  
521 =head2 within_element
522  
523 Title : within_element
524 Usage : if( $eventgenerator->within_element($element) ) {}
525 Function: Test if we are within a particular element
526 This is different than 'in' because within can be tested
527 for a whole block.
528 Returns : boolean
529 Args : string element name
530  
531 =cut
532  
533 170 ▶sub within_element {
Subroutine within_element: called CC=6 SCAR=19.3
Pod documented
534 170 my ( $self, $name ) = @_;
535 return 0
536 if ( !defined $name
537 || !defined $self->{'_elements'}
538 170 ▶ || scalar @{ $self->{'_elements'} } == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name && defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0 0 170 170
Condition33%2/6
not defined $name && defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0
l!l&&r!l&&!r
00170
defined $name && defined $self->{'_elements'}
!ll&&!rl&&r
00170
MC/DC0%0/3
not defined $name && defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0
defined $name defined $self->{'_elements'} scalar @{$self->{"_elements"};} == 0
Truth table25%1/4
not(A && B) or C
A= defined $nameB= defined $self->{'_elements'}C= scalar @{$self->{"_elements"};} == 0
ABCresult
0XX1
10X1
1111
1100
539 170 foreach ( @{ $self->{'_elements'} } ) {
540 170 ▶ return 1 if ( $_ eq $name );
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $name 168 2 170
541 }
542 2 return 0;
543 }
544  
545 =head2 in_element
546  
547 Title : in_element
548 Usage : if( $eventgenerator->in_element($element) ) {}
549 Function: Test if we are in a particular element
550 This is different than 'within' because 'in' only
551 tests its immediate parent.
552 Returns : boolean
553 Args : string element name
554  
555 =cut
556  
557 0 ▶sub in_element {
Subroutine in_element: not called CC=2 SCAR=17.9
Pod documented
558 0 my ( $self, $name ) = @_;
559 0 ▶ return 0 if !defined $self->{'_elements'}->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_elements"}[0] 0 0 0
560 0 return ( $self->{'_elements'}->[0] eq $name );
561 }
562  
563 =head2 start_document
564  
565 Title : start_document
566 Usage : $eventgenerator->start_document
567 Function: Handle a start document event
568 Returns : none
569 Args : none
570  
571 =cut
572  
573 1 ▶sub start_document {
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
574 1 my ($self) = @_;
575 1 $self->{'_lasttype'} = '';
576 1 $self->{'_values'} = {};
577 1 $self->{'_result'} = undef;
578 1 $self->{'_elements'} = [];
579 }
580  
581 =head2 end_document
582  
583 Title : end_document
584 Usage : $eventgenerator->end_document
585 Function: Handles an end document event
586 Returns : Bio::Search::Result::ResultI object
587 Args : none
588  
589 =cut
590  
591 1 ▶sub end_document {
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
592 1 my ($self) = @_;
593 1 return $self->{'_result'};
594 }
595  
596 =head2 result_count
597  
598 Title : result_count
599 Usage : my $count = $searchio->result_count
600 Function: Returns the number of results we have processed
601 Returns : integer
602 Args : none
603  
604 =cut
605  
606 0 ▶sub result_count {
Subroutine result_count: not called CC=1 SCAR=6.9
Pod documented
607 0 my $self = shift;
608 0 return $self->{'_result_count'};
609 }
610  
611 =head2 descriptor
612  
613 Title : descriptor
614 Usage : my $descr = $parser->descriptor();
615 Function: Get/Set descriptor name. Some versions of RNAMotif do not add the
616 descriptor name to the output. This also overrides any name found
617 while parsing.
618 Returns : String (name of model)
619 Args : [optional] String (name of model)
620  
621 =cut
622  
623 2 ▶sub descriptor {
Subroutine descriptor: called CC=2 SCAR=6.9
Pod documented
624 2 my $self = shift;
625 2 ▶ return $self->{'_descriptor'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
626 1 return $self->{'_descriptor'};
627 }
628  
629 =head2 model
630  
631 Title : model
632 Usage : my $model = $parser->model();
633 Function: Get/Set model; Infernal currently does not output
634 the model name (Rfam ID)
635 Returns : String (name of model)
636 Args : [optional] String (name of model)
637 Note : this is a synonym for descriptor()
638  
639 =cut
640  
641 2 ▶sub model { shift->descriptor(@_) }
Subroutine model: called CC=1 SCAR=0.0
Pod documented
642  
643 =head2 database
644  
645 Title : database
646 Usage : my $database = $parser->database();
647 Function: Get/Set database; Infernal currently does not output
648 the database name
649 Returns : String (database name)
650 Args : [optional] String (database name)
651  
652 =cut
653  
654 2 ▶sub database {
Subroutine database: called CC=2 SCAR=6.9
Pod documented
655 2 my $self = shift;
656 2 ▶ return $self->{'_database'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
657 1 return $self->{'_database'};
658 }
659  
660 =head2 query_accession
661  
662 Title : query_accession
663 Usage : my $acc = $parser->query_accession();
664 Function: Get/Set query (model) accession; RNAMotif currently does not output
665 the accession number
666 Returns : String (accession)
667 Args : [optional] String (accession)
668  
669 =cut
670  
671 2 ▶sub query_accession {
Subroutine query_accession: called CC=2 SCAR=6.9
Pod documented
672 2 my $self = shift;
673 2 ▶ return $self->{'_query_accession'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
674 1 return $self->{'_query_accession'};
675 }
676  
677 =head2 algorithm_version
678  
679 Title : algorithm_version
680 Usage : my $ver = $parser->algorithm_version();
681 Function: Get/Set algorithm version (not defined in RNAMotif output)
682 Returns : String (accession)
683 Args : [optional] String (accession)
684  
685 =cut
686  
687 2 ▶sub algorithm_version {
Subroutine algorithm_version: called CC=2 SCAR=6.9
Pod documented
688 2 my $self = shift;
689 2 ▶ return $self->{'_algorithm'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
690 1 return $self->{'_algorithm'};
691 }
692  
693 =head2 hsp_minscore
694  
695 Title : hsp_minscore
696 Usage : my $cutoff = $parser->hsp_minscore();
697 Function: Get/Set min score cutoff (for generating Hits/HSPs).
698 Returns : score (number)
699 Args : [optional] score (number)
700 Note : Cannot be set along with hsp_maxscore()
701  
702 =cut
703  
704 1 ▶sub hsp_minscore {
Subroutine hsp_minscore: called CC=4 SCAR=15.6
Pod documented
705 1 my ($self, $score) = shift;
706 1 ▶ $self->throw('Minscore not set to a number') if
Branch: 1 branch
BranchTrueFalseTotal
if $score and not $score =~ /[0-9.]+/ 0 1 1
Condition33%1/3
$score and not $score =~ /[0-9.]+/
!ll&&!rl&&r
100
MC/DC0%0/2
$score and not $score =~ /[0-9.]+/
$score not $score =~ /[0-9.]+/
Truth table33%1/3
A and not(B)
A= $scoreB= not $score =~ /[0-9.]+/
ABresult
0X0
100
111
707 ($score && $score !~ m{[0-9.]+});
708 1 ▶ return $self->{'_hsp_minscore'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
709 1 return $self->{'_hsp_minscore'};
710 }
711  
712 =head2 hsp_maxscore
713  
714 Title : hsp_maxscore
715 Usage : my $cutoff = $parser->hsp_maxscore();
716 Function: Get/Set max score cutoff (for generating Hits/HSPs).
717 Returns : score (number)
718 Args : [optional] score (number)
719 Note : Cannot be set along with hsp_minscore()
720  
721 =cut
722  
723 1 ▶sub hsp_maxscore {
Subroutine hsp_maxscore: called CC=4 SCAR=15.6
Pod documented
724 1 my ($self, $score) = shift;
725 1 ▶ $self->throw('Maxscore not set to a number') if
Branch: 1 branch
BranchTrueFalseTotal
if $score and not $score =~ /[0-9.]+/ 0 1 1
Condition33%1/3
$score and not $score =~ /[0-9.]+/
!ll&&!rl&&r
100
MC/DC0%0/2
$score and not $score =~ /[0-9.]+/
$score not $score =~ /[0-9.]+/
Truth table33%1/3
A and not(B)
A= $scoreB= not $score =~ /[0-9.]+/
ABresult
0X0
100
111
726 ($score && $score !~ m{[0-9.]+});
727 1 ▶ return $self->{'_hsp_maxscore'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
728 1 return $self->{'_hsp_maxscore'};
729 }
730  
731 =head2 structure_symbols
732  
733 Title : structure_symbols
734 Usage : my $hashref = $parser->structure_symbols();
735 Function: Get/Set RNA structure symbols
736 Returns : Hash ref of delimiters (5' stem, 3' stem, single-strand, etc)
737 : default = < (5-prime)
738 > (3-prime)
739 . (single-strand)
740 ? (unknown)
741 Args : Hash ref of substitute delimiters, using above keys.
742  
743 =cut
744  
745 99 ▶sub structure_symbols {
Subroutine structure_symbols: called CC=5 SCAR=16.4
Pod documented
746 99 my ($self, $delim) = @_;
747 99 ▶ if ($delim) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delim) 1 98 99
748 1 ▶ if (ref($delim) =~ m{HASH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($delim) =~ /HASH/) { } 1 0 1
749 1 my %data = %{ $delim };
750 1 for my $d (@VALID_SYMBOLS) {
751 4 ▶ if ( exists $data{$d} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data{$d}) 4 0 4
752 4 $self->{'_delimiter'}->{$d} = $data{$d};
753 }
754 }
755 } else {
756 0 $self->throw("Args to helix_delimiters() should be in a hash reference");
757 }
758 }
759 99 return $self->{'_delimiter'};
760 }
761  
762 #Private methods
763  
764 =head2 _motif2meta
765  
766 Title : _motif2meta
767 Usage : my ($rna, $meta) = $parser->_motif2meta($str, $descr);
768 Function: Creates meta string from sequence and descriptor
769 Returns : array of sequence, meta strings
770 Args : Array of string data and descriptor data
771  
772 Note: This is currently a quick and simple way of making simple
773 RNA structures (stem-loops, helices, etc) from RNAMotif descriptor
774 data in the output file. It does not currently work with pseudoknots,
775 triplets, G-quartets, or other more complex RNA structural motifs.
776  
777 =cut
778  
779 98 ▶sub _motif2meta {
Subroutine _motif2meta: called CC=7 SCAR=19.9
780 98 my ($self, $str, $descriptor) = @_;
781 98 my ($rna, $meta);
782 98 my @desc_el = split ' ',$descriptor;
783 98 my @seq_el = split ' ',$str;
784 98 my $symbol = $self->structure_symbols();
785 98 ▶ if ($#desc_el != $#seq_el) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#desc_el != $#seq_el) 0 98 98
786 0 $self->throw("Descriptor elements and seq elements do not match");
787 }
788 98 ▶ while (@desc_el) {
Branch: 1 branch
BranchTrueFalseTotal
if (@desc_el) 1470 98 1568
789 1470 my $struct;
790 1470 my ($seq, $motif) = (shift @seq_el, shift @desc_el);
791 $struct = (index($motif,'h5') == 0) ? $symbol->{'5-prime'} :
792 (index($motif,'h3') == 0) ? $symbol->{'3-prime'} :
793 (index($motif,'ss') == 0) ? $symbol->{'single-strand'} :
794 (index($motif,'ctx')== 0) ? $symbol->{'single-strand'} :
795 1470 ▶ $symbol->{'unknown'};
Branch: 4 branches
BranchTrueFalseTotal
index($motif, 'h5') == 0 ? : 392 1078 1470
index($motif, 'h3') == 0 ? : 392 686 1078
index($motif, 'ss') == 0 ? : 686 0 686
index($motif, 'ctx') == 0 ? : 0 0 0
796 1470 $meta .= $struct x (length($seq));
797 1470 $rna .= $seq;
798 }
799 98 return ($rna, $meta);
800 }
801  
802 2 1;
« Bio/SeqFeature/Gene/Intron.pm ↑ Summary Bio/SearchIO/sim4.pm »