Bio/Tools/Spidey/Results.pm

filter: Statementstmt 91.4% 129 / 141 Branchbran 83.9% 47 / 56 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.3% 14 / 15 Podpod 100% 9 / 9 totaltotal 88.9% 201 / 226 CC 31 SCAR 24.5
CC
31
Cov
89%
parse_next_alignment
22.2
next_exonset
4.0
analysis_method
3.3
CRAP 11.6
« Bio/AlignIO.pm ↑ Summary Bio/Seq/Meta.pm »
1 #
2 # BioPerl module for Bio::Tools::Spidey::Results
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Ryan Golhar <golharam@umdnj.edu>
7 #
8 # You may distribute this module under the same terms as perl itself
9  
10 # POD documentation - main docs before the code
11  
12 =head1 NAME
13  
14 Bio::Tools::Spidey::Results - Results of a Spidey run
15  
16 =head1 SYNOPSIS
17  
18 use Bio::Tools::Spidey::Results;
19 my $spidey = Bio::Tools::Spidey::Results->new(-file => 'result.spidey' );
20  
21 # or
22  
23 my $spidey = Bio::Tools::Spidey::Results->new( -fh => \*INPUT );
24  
25 # get the exons before doing anything else
26 my $exonset = $spidey->next_exonset();
27  
28 # parse the results
29 my @exons = $exonset->sub_SeqFeature();
30 print "Total no of Exons: ", scalar(@exons), "\n";
31  
32 print "Genomic sequence length: ", $spidey->genomic_dna_length(), "\n";
33  
34 # $exonset is-a Bio::SeqFeature::Generic with Bio::Tools::Spidey::Exons
35 # as sub features
36 print "Delimited on sequence ", $exonset->seq_id(), " from ",
37 $exonset->start(), " to ", $exonset->end(), "\n";
38  
39 foreach my $exon ( $exonset->sub_SeqFeature() ) {
40 # $exon is-a Bio::SeqFeature::FeaturePair
41 print "Exon from ", $exon->start, " to ", $exon->end,
42 " on strand ", $exon->strand(), "\n";
43 # you can get out what it matched using the est_hit attribute
44 my $homol = $exon->est_hit();
45 print "Matched to sequence ", $homol->seq_id,
46 " at ", $homol->start," to ", $homol->end, "\n";
47 }
48  
49 # essential if you gave a filename at initialization (otherwise
50 # the file stays open)
51 $spidey->close();
52  
53 =head1 DESCRIPTION
54  
55 The spidey module provides a parser and results object for spidey
56 output. The spidey results are specialised types of SeqFeatures,
57 meaning you can add them to AnnSeq objects fine, and manipulate them
58 in the "normal" seqfeature manner.
59  
60 The spidey Exon objects are Bio::SeqFeature::FeaturePair inherited
61 objects. The $esthit = $exon-E<gt>est_hit() is the alignment as a
62 feature on the matching object (normally, a cDNA), in which the
63 start/end points are where the hit lies.
64  
65 To make this module work sensibly you need to run
66  
67 spidey -i genomic.fasta -m cDNA.fasta
68  
69 =head1 FEEDBACK
70  
71 =head2 Mailing Lists
72  
73 User feedback is an integral part of the evolution of this and other
74 Bioperl modules. Send your comments and suggestions preferably to one
75 of the Bioperl mailing lists. Your participation is much appreciated.
76  
77 bioperl-l@bioperl.org - General discussion
78 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
79  
80 =head2 Support
81  
82 Please direct usage questions or support issues to the mailing list:
83  
84 I<bioperl-l@bioperl.org>
85  
86 rather than to the module maintainer directly. Many experienced and
87 reponsive experts will be able look at the problem and quickly
88 address it. Please include a thorough description of the problem
89 with code and data examples if at all possible.
90  
91 =head2 Reporting Bugs
92  
93 Report bugs to the Bioperl bug tracking system to help us keep track
94 the bugs and their resolution. Bug reports can be submitted via the
95 web:
96  
97 https://github.com/bioperl/bioperl-live/issues
98  
99 =head1 AUTHOR - Ryan Golhar
100  
101 Email golharam@umdnj.edu
102  
103 =head1 APPENDIX
104  
105 The rest of the documentation details each of the object methods.
106 Internal methods are usually preceded with a _
107  
108 =cut
109  
110  
111 # Let the code begin...
112  
113  
114 package Bio::Tools::Spidey::Results;
115 2 $Bio::Tools::Spidey::Results::VERSION = '1.7.8';
116 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 2 ▶use Bio::Tools::Spidey::Exon;
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 2 ▶use base qw(Bio::Tools::AnalysisResult);
Subroutine BEGIN: called CC=1 SCAR=0.0
123  
124 2 ▶sub _initialize_state {
Subroutine _initialize_state: called CC=1 SCAR=0.0
125 2 my($self,@args) = @_;
126  
127 # call the inherited method first
128 2 my $make = $self->SUPER::_initialize_state(@args);
129  
130 # my ($est_is_first) = $self->_rearrange([qw(ESTFIRST)], @args);
131  
132 # delete($self->{'_est_is_first'});
133 # $self->{'_est_is_first'} = $est_is_first if(defined($est_is_first));
134 2 $self->analysis_method("Spidey");
135 }
136  
137 =head2 analysis_method
138  
139 Usage : $spidey->analysis_method();
140 Purpose : Inherited method. Overridden to ensure that the name matches
141 /Spidey/i.
142 Returns : String
143 Argument : n/a
144  
145 =cut
146  
147 #-------------
148 8 ▶sub analysis_method {
Subroutine analysis_method: called CC=3 SCAR=12.0
Pod documented
149 #-------------
150 8 my ($self, $method) = @_;
151 8 ▶ if($method && ($method !~ /Spidey/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method and not $method =~ /Spidey/i) 0 8 8
Condition66%2/3
$method and not $method =~ /Spidey/i
!ll&&!rl&&r
620
MC/DC0%0/2
$method and not $method =~ /Spidey/i
$method not $method =~ /Spidey/i
Truth table66%2/3
A and not(B)
A= $methodB= not $method =~ /Spidey/i
ABresult
0X0
100
111
152 0 $self->throw("method $method not supported in " . ref($self));
153 }
154 8 return $self->SUPER::analysis_method($method);
155 }
156  
157 =head2 parse_next_alignment
158  
159 Title : parse_next_alignment
160 Usage : @exons = $spidey_result->parse_next_alignment;
161 foreach $exon (@exons) {
162 # do something
163 }
164 Function: Parses the next alignment of the Spidey result file and returns the
165 found exons as an array of Bio::Tools::Spidey::Exon objects. Call
166 this method repeatedly until an empty array is returned to get the
167 results for all alignments.
168 Example :
169 Returns : An array of Bio::Tools::Spidey::Exon objects
170 Args :
171  
172  
173 =cut
174  
175 2 ▶sub parse_next_alignment {
Subroutine parse_next_alignment: called CC=21 SCAR=31.0
Pod documented
176 2 my ($self) = @_;
177 # for strand 1 = plus, -1 = minus
178 2 my ($started,$version,$strand, $exoncount) = (0,0,0,-1);
179 2 my (%seq1props,%seq2props,@exons);
180
181 # we refer to the properties of each seq by reference
182  
183 2 ▶ while(defined($_ = $self->_readline())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 164 2 166
184 164 chomp;
185 #
186 # bascially, parse a Spidey result...
187 #
188 # matches: --SPIDEY version 1.40--
189 164 ▶ if( /^--SPIDEY\s+version\s+(\d+\.\d+)--/) {
Branch: 11 branches
BranchTrueFalseTotal
if (/^--SPIDEY\s+version\s+(\d+\.\d+)--/) { } 1 163 164
elsif (/^Genomic:\s+(\S+)\s.*,\s+(\d+)\sbp$/) { } 1 162 163
elsif (/^mRNA:\s+(\S+)\s.*,(?:\s+mRNA\s+sequence,)?\s(\d+)\sbp$/) { } 1 161 162
elsif (/^Strand:/) { } 1 160 161
elsif (/^Number of exons: (\d+)/) { } 1 159 160
elsif (/^Number of splice sites:\s+(\d+)/) { } 1 158 159
elsif (/^mRNA coverage:\s+(\d+)%/) { } 1 157 158
elsif (/^overall percent identity:\s+([\d\.]+)%/) { } 1 156 157
elsif (/^Missing mRNA ends:\s+(\w+)/) { } 1 155 156
elsif (/^Exon (\d+): (\d+)-(\d+) \(gen\)\s+(\d+)-(\d+) \(mRNA\)/) { } 6 149 155
elsif (/No alignment found/) { } 0 149 149
190 1 ▶ if($started) {
Branch: 1 branch
BranchTrueFalseTotal
if ($started) 0 1 1
191 0 $self->_pushback($_);
192 0 return \@exons;
193 }
194 1 $version = $1;
195 1 ▶ if ($version != 1.40) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version != "1.4") 0 1 1
196 0 $self->throw("Spidey parser only designed to work with Spidey v1.40\n");
197 }
198 1 $started = 1;
199 } elsif (/^Genomic:\s+(\S+)\s.*,\s+(\d+)\sbp$/ ) {
200 # matches: Genomic: lcl|some_name other information, 1234 bp
201 # $seq1props{'filename'} = $1;
202 1 $seq1props{'seqname'} = $1;
203 1 $seq1props{'length'} = $2;
204 1 $self->genomic_dna_length($seq1props{'length'});
205  
206 } elsif( /^mRNA:\s+(\S+)\s.*,(?:\s+mRNA\s+sequence,)?\s(\d+)\sbp$/ ) {
207 # matches: mRNA:
208 # $seq2props{'filename'} = $1;
209 1 $seq2props{'seqname'} = $1;
210 1 $seq2props{'length'} = $2;
211  
212 } elsif( /^Strand:/ ) {
213 1 ▶ if (/plus/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/plus/) { } 0 1 1
214 0 $strand = 1;
215 } else {
216 1 $strand = -1;
217 }
218 } elsif( /^Number of exons: (\d+)/ ) {
219 1 $exoncount = $1;
220  
221 1 my ($genomic_start, $genomic_stop, $cdna_start, $cdna_stop,
222 $id, $mismatches, $gaps, $splice_donor,
223 $splice_acceptor, $uncertain);
224  
225 # the next $exoncount lines contains information
226 # about the matches of each exon. we should parse
227 # this information here
228  
229 1 ▶ for (my $ec = 1; $ec <= $exoncount; $ec++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ec <= $exoncount) 6 1 7
230 6 ▶ if (defined($_ = $self->_readline())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) { } 6 0 6
231 6 chomp;
232  
233 6 ▶ if (/^Exon\s$ec[\(\)-]*:\s(\d+)-(\d+)\s\(gen\)\s+(\d+)-(\d+)\s\(mRNA\)\s+id\s([\d\.inf-]+)%\s+mismatches\s(\d+)\s+gaps\s(\d+)\s+splice\ssite\s\(d\s+a\):\s(\d+)\s+(\d+)\s*(\w*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^Exon\s${ec}[\(\)-]*:\s(\d+)-(\d+)\s\(gen\)\s+(\d+)-(\d+)\s\(mRNA\)\s+id\s([\d\.inf-]+)%\s+mismatches\s(\d+)\s+gaps\s(\d+)\s+splice\ssite\s\(d\s+a\):\s(\d+)\s+(\d+)\s*(\w*)/) { } 6 0 6
234 6 $genomic_start = $1;
235 6 $genomic_stop = $2;
236 6 $cdna_start = $3;
237 6 $cdna_stop = $4;
238 6 $id = $5;
239 6 $mismatches = $6;
240 6 $gaps = $7;
241 6 $splice_donor = $8;
242 6 $splice_acceptor = $9;
243 6 $uncertain = $10;
244 } else {
245 0 $self->throw( "Failed to match anything:\n$_\n");
246 }
247  
248 6 my $exon = Bio::Tools::Spidey::Exon->new
249 (-start => $genomic_start,
250 -end => $genomic_stop,
251 -strand => $strand);
252 6 $exon->seq_id($seq1props{'seqname'});
253  
254 # feature1 is supposed to be initialized to a Similarity object, but we provide a safety net
255 6 ▶ if ($exon->feature1->can('seqlength')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exon->feature1->can('seqlength')) { } 6 0 6
256 6 $exon->feature1->seqlength($seq1props{'length'});
257 } else {
258 0 $exon->feature1->add_tag_value('seqlength', $seq1props{'length'});
259 }
260  
261 # create and initialize the feature wrapping the 'hit' (the cDNA)
262 my $fea2 = Bio::SeqFeature::Similarity->new
263 (-start => $cdna_start,
264 -end => $cdna_stop,
265 -strand => $strand,
266 6 -seq_id => $seq2props{'seqname'},
267 -primary => "aligning_cDNA");
268 6 $fea2->seqlength($seq2props{'length'});
269 # store
270 6 $exon->est_hit($fea2);
271  
272 # general properties
273 6 $exon->source_tag($self->analysis_method());
274 6 $exon->percentage_id($5);
275 6 $exon->mismatches($6);
276 6 $exon->gaps($7);
277 6 $exon->donor($8);
278 6 $exon->acceptor($9);
279  
280 # push onto array
281 6 push(@exons, $exon);
282 } else {
283 0 $self->throw("Unexpected end of file reached\n");
284 }
285 }
286 } elsif( /^Number of splice sites:\s+(\d+)/ ) {
287 1 $self->splicesites($1);
288 } elsif( /^mRNA coverage:\s+(\d+)%/ ) {
289 1 $self->est_coverage($1);
290 } elsif(/^overall percent identity:\s+([\d\.]+)%/ ) {
291 1 $self->overall_percentage_id($1);
292 } elsif(/^Missing mRNA ends:\s+(\w+)/ ) {
293 1 $self->missing_mrna_ends($1);
294 } elsif( /^Exon (\d+): (\d+)-(\d+) \(gen\)\s+(\d+)-(\d+) \(mRNA\)/ ) {
295 6 my ($exon_num, $gen_start, $gen_stop, $cdna_start, $cdna_stop);
296 6 $exon_num = $1;
297 6 $gen_start = $2;
298 6 $gen_stop = $3;
299 6 $cdna_start = $4;
300 6 $cdna_stop = $5;
301 } elsif( /No alignment found/ ) {
302 0 return [];
303 } else {
304 #$self->debug("unmatched $_\n");
305 }
306 }
307 # Typical format:
308 # Exon 1: 36375798-36375691 (gen) 1-108 (mRNA)
309 #
310 #
311 # CCTCTTTTTCTTTGCAGGGTATATACCCAGTTACTTAGACAAGGATGAGCTATGTGTAGT
312 # | ||||||||||||||||||||||||||||||||||||||||||||||
313 # ATGTCAGGGTATATACCCAGTTACTTAGACAAGGATGAGCTATGTGTAGT
314 # M S G Y I P S Y L D K D E L C V V
315 #
316 #
317 # ATGTGGGGACAAAGCCACCGGATATCATTATCGCTGCATCACTTGTGAAGGTTGCAAGGT
318 # ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
319 # ATGTGGGGACAAAGCCACCGGATATCATTATCGCTGCATCACTTGTGAAGGTTGCAAG
320 # C G D K A T G Y H Y R C I T C E G C K
321 #
322 #
323 # AAATGGCA
324 #
325 2 ▶ @exons ? return \@exons : return ;
Branch: 1 branch
BranchTrueFalseTotal
@exons ? : 1 1 2
326 }
327  
328 =head2 next_exonset
329  
330 Title : next_exonset
331 Usage : $exonset = $spidey_result->parse_next_exonset;
332 print "Exons start at ", $exonset->start(),
333 "and end at ", $exonset->end(), "\n";
334 for $exon ($exonset->sub_SeqFeature()) {
335 # do something
336 }
337 Function: Parses the next alignment of the Spidey result file and returns the
338 set of exons as a container of features. The container is itself
339 a Bio::SeqFeature::Generic object, with the Bio::Tools::Spidey::Exon
340 objects as sub features. Start, end, and strand of the container
341 will represent the total region covered by the exons of this set.
342  
343 See the documentation of parse_next_alignment() for further
344 reference about parsing and how the information is stored.
345 Example :
346 Returns : An Bio::SeqFeature::Generic object holding Bio::Tools::Spidey::Exon
347 objects as sub features.
348 Args :
349  
350 =cut
351  
352 2 ▶sub next_exonset {
Subroutine next_exonset: called CC=4 SCAR=13.9
Pod documented
353 2 my $self = shift;
354 2 my $exonset;
355  
356 # get the next array of exons
357 2 my $exons = $self->parse_next_alignment();
358 2 ▶ if( ! defined $exons ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $exons) 1 1 2
359 1 $self->warn("No exons returned");
360 1 return;
361 }
362 1 ▶ if( @$exons == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$exons == 0) 0 1 1
363 0 return Bio::SeqFeature::Generic->new();
364 }
365 # create the container of exons as a feature object itself, with the
366 # data of the first exon for initialization
367 1 $exonset = Bio::SeqFeature::Generic->new('-start' => $exons->[0]->start(),
368 '-end' => $exons->[-1]->end(),
369 '-strand' => $exons->[0]->strand(),
370 '-primary' => "ExonSet");
371 1 $exonset->source_tag($exons->[0]->source_tag());
372 1 $exonset->seq_id($exons->[0]->seq_id());
373 # now add all exons as sub features, with enabling EXPANsion of the region
374 # covered in total
375 1 foreach my $exon (@$exons) {
376 6 $exonset->add_sub_SeqFeature($exon, 'EXPAND');
377 }
378 1 return $exonset;
379 }
380  
381 =head2 next_feature
382  
383 Title : next_feature
384 Usage : while($exonset = $spidey->next_feature()) {
385 # do something
386 }
387 Function: Does the same as L<next_exonset()>. See there for documentation of
388 the functionality. Call this method repeatedly until FALSE is
389 returned.
390  
391 The returned object is actually a SeqFeatureI implementing object.
392 This method is required for classes implementing the
393 SeqAnalysisParserI interface, and is merely an alias for
394 next_exonset() at present.
395  
396 Example :
397 Returns : A Bio::SeqFeature::Generic object.
398 Args :
399  
400 =cut
401  
402 0 ▶sub next_feature {
Subroutine next_feature: not called CC=1 SCAR=6.9
Pod documented
403 0 my ($self,@args) = @_;
404 # even though next_exonset doesn't expect any args (and this method
405 # does neither), we pass on args in order to be prepared if this changes
406 # ever
407 0 return $self->next_exonset(@args);
408 }
409  
410 =head2 genomic_dna_length
411  
412 Title : genomic_dna_length
413 Usage : $spidey->genomic_dna_length();
414 Function: Returns the length of the genomic DNA used in this Spidey result
415 Example :
416 Returns : An integer value.
417 Args :
418  
419 =cut
420  
421 2 ▶sub genomic_dna_length {
Subroutine genomic_dna_length: called CC=2 SCAR=6.9
Pod documented
422 2 my ($self, @args) = @_;
423 2 my $val;
424  
425 2 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 1 1 2
426 1 $val = shift(@args);
427 1 $self->{'genomic_dna_length'} = $val;
428 } else {
429 1 $val = $self->{'genomic_dna_length'};
430 }
431 2 return $val;
432 }
433  
434 =head2 splicesites
435  
436 Title : splicesites
437 Usage : $spidey->splicesites();
438 Function: Returns the number of splice sites found in this Spidey result
439 Example :
440 Returns : An integer value.
441 Args :
442  
443 =cut
444  
445 2 ▶sub splicesites {
Subroutine splicesites: called CC=2 SCAR=6.9
Pod documented
446 2 my ($self, @args) = @_;
447 2 my $val;
448  
449 2 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 1 1 2
450 1 $val = shift(@args);
451 1 $self->{'splicesites'} = $val;
452 } else {
453 1 $val = $self->{'splicesites'};
454 }
455 2 return $val;
456 }
457  
458 =head2 est_coverage
459  
460 Title : est_coverage
461 Usage : $spidey->est_coverage();
462 Function: Returns the percent of est coverage in this Spidey result
463 Example :
464 Returns : An integer value.
465 Args :
466  
467 =cut
468  
469 2 ▶sub est_coverage {
Subroutine est_coverage: called CC=2 SCAR=6.9
Pod documented
470 2 my ($self, @args) = @_;
471 2 my $val;
472
473 2 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 1 1 2
474 1 $val = shift(@args);
475 1 $self->{'est_coverage'} = $val;
476 } else {
477 1 $val = $self->{'est_coverage'};
478 }
479 2 return $val;
480 }
481  
482 =head2 overall_percentage_id
483  
484 Title : overall_percentage_id
485 Usage : $spidey->overall_percentage_id();
486 Function: Returns the overall percent id in this Spidey result
487 Example :
488 Returns : An float value.
489 Args :
490  
491 =cut
492  
493 2 ▶sub overall_percentage_id {
Subroutine overall_percentage_id: called CC=2 SCAR=6.9
Pod documented
494 2 my ($self, @args) = @_;
495 2 my $val;
496  
497 2 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 1 1 2
498 1 $val = shift(@args);
499 1 $self->{'overall_percentage_id'} = $val;
500 } else {
501 1 $val = $self->{'overall_percentage_id'};
502 }
503 2 return $val;
504 }
505  
506 =head2 missing_mrna_ends
507  
508 Title : missing_mrna_ends
509 Usage : $spidey->missing_mrna_ends();
510 Function: Returns left/right/neither from Spidey
511 Example :
512 Returns : A string value.
513 Args :
514  
515 =cut
516  
517 2 ▶sub missing_mrna_ends {
Subroutine missing_mrna_ends: called CC=2 SCAR=6.9
Pod documented
518 2 my ($self, @args) = @_;
519 2 my $val;
520  
521 2 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 1 1 2
522 1 $val = shift(@args);
523 1 $self->{'missing_mrna_ends'} = $val;
524 } else {
525 1 $val = $self->{'missing_mrna_ends'};
526 }
527 2 return $val;
528 }
529  
530 2 1;
« Bio/AlignIO.pm ↑ Summary Bio/Seq/Meta.pm »