File Coverage

Bio/Tools/Genomewise.pm
Criterion Covered Total %
statement 57 59 96.6
branch 8 10 80.0
condition n/a
subroutine 11 11 100.0
pod 2 2 100.0
total 78 82 95.1


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Bio::Tools::Genomewise
3             #
4             # Copyright Jason Stajich
5             #
6             # You may distribute this module under the same terms as perl itself
7             #
8             # POD documentation - main docs before the code
9              
10             =head1 NAME
11              
12             Bio::Tools::Genomewise - Results of one Genomewise run
13              
14             =head1 SYNOPSIS
15              
16             use Bio::Tools::Genomewise;
17             my $gw = Bio::Tools::Genomewise(-file=>"genomewise.out");
18              
19             while (my $gene = $gw->next_prediction){
20             my @transcripts = $gene->transcripts;
21             foreach my $t(@transcripts){
22             my @exons = $t->exons;
23             foreach my $e(@exons){
24             print $e->start." ".$e->end."\n";
25             }
26             }
27             }
28              
29             =head1 DESCRIPTION
30              
31             This is the parser for the output of Genewise. It takes either a file
32             handle or a file name and returns a
33             Bio::SeqFeature::Gene::GeneStructure object. You will need to specify
34             the proper target sequence id on the object with the
35             $feature-Eseq_id($seqid).
36              
37             =head1 FEEDBACK
38              
39             =head2 Mailing Lists
40              
41             User feedback is an integral part of the evolution of this and other
42             Bioperl modules. Send your comments and suggestions preferably to one
43             of the Bioperl mailing lists. Your participation is much appreciated.
44              
45             bioperl-l@bioperl.org - General discussion
46             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47              
48             =head2 Support
49              
50             Please direct usage questions or support issues to the mailing list:
51              
52             I
53              
54             rather than to the module maintainer directly. Many experienced and
55             reponsive experts will be able look at the problem and quickly
56             address it. Please include a thorough description of the problem
57             with code and data examples if at all possible.
58              
59             =head2 Reporting Bugs
60              
61             Report bugs to the Bioperl bug tracking system to help us keep track
62             the bugs and their resolution. Bug reports can be submitted via the
63             web:
64              
65             https://github.com/bioperl/bioperl-live/issues
66              
67             =head1 AUTHOR - Fugu Team, Jason Stajich
68              
69             Email: fugui-at-worf.fugu-sg.org
70             jason-at-bioperl-dot-org
71              
72             =head1 APPENDIX
73              
74             The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
75              
76             =cut
77              
78              
79             # Let the code begin...
80              
81              
82             package Bio::Tools::Genomewise;
83 2     2   462 use vars qw($Srctag);
  2         4  
  2         74  
84 2     2   8 use strict;
  2         3  
  2         35  
85              
86 2     2   225 use Bio::Tools::AnalysisResult;
  2         3  
  2         41  
87 2     2   293 use Bio::SeqFeature::Generic;
  2         3  
  2         42  
88 2     2   242 use Bio::SeqFeature::Gene::Exon;
  2         3  
  2         41  
89 2     2   251 use Bio::SeqFeature::FeaturePair;
  2         4  
  2         45  
90 2     2   277 use Bio::SeqFeature::Gene::Transcript;
  2         4  
  2         49  
91 2     2   285 use Bio::SeqFeature::Gene::GeneStructure;
  2         3  
  2         74  
92              
93 2     2   10 use base qw(Bio::Tools::Genewise);
  2         2  
  2         620  
94              
95             $Srctag = 'genomewise';
96              
97             =head2 new
98              
99             Title : new
100             Usage : $obj->new(-file=>"genewise.out");
101             $obj->new(-fh=>\*GW);
102             Function: Constructor for genomewise wrapper. Takes either a file or filehandle
103             Example :
104             Returns : L
105              
106             =cut
107              
108             sub new {
109 2     2 1 502 my($class,@args) = @_;
110 2         14 my $self = $class->SUPER::new(@args);
111 2         11 return $self;
112             }
113              
114             =head2 _get_strand
115              
116             Title : _get_strand
117             Usage : $obj->_get_strand
118             Function: takes start and end values, swap them if start>end and returns end
119             Example :
120             Returns :$start,$end,$strand
121              
122             =cut
123              
124             =head2 score
125              
126             Title : score
127             Usage : $obj->score
128             Function: get/set for score info
129             Example :
130             Returns : a score value
131              
132             =cut
133              
134             =head2 _prot_id
135              
136             Title : _prot_id
137             Usage : $obj->_prot_id
138             Function: get/set for protein id
139             Example :
140             Returns :a protein id
141              
142             =cut
143              
144             =head2 _target_id
145              
146             Title : _target_id
147             Usage : $obj->_target_id
148             Function: get/set for genomic sequence id
149             Example :
150             Returns :a target id
151              
152             =cut
153              
154              
155             =head2 next_prediction
156              
157             Title : next_prediction
158             Usage : while($gene = $genewise->next_prediction()) {
159             # do something
160             }
161             Function: Returns the gene structure prediction of the Genomewise result
162             file. Call this method repeatedly until FALSE is returned.
163              
164             Example :
165             Returns : a Bio::SeqFeature::Gene::GeneStructure object
166             Args :
167              
168             =cut
169              
170              
171             sub next_prediction {
172 8     8 1 38 my ($self) = @_;
173              
174 8         9 my $genes;
175 8         17 while ($_ = $self->_readline) {
176 8         26 $self->debug( $_ );
177 8 100       20 last if m{^//};
178              
179 6 50       24 if( /^Gene\s+\d+\s*$/ ) {
180 6         19 $genes = Bio::SeqFeature::Gene::GeneStructure->new
181             (-source => $Srctag,
182             -seq_id => $self->_target_id, # if this had been specified
183             );
184 6         17 $_ = $self->_readline;
185 6         14 $self->debug( $_ );
186              
187 6 50       26 unless ( /^Gene\s+(\d+)\s+(\d+)\s*$/ ) {
188 0         0 $self->warn("Unparseable genomewise output");
189 0         0 last;
190             }
191 6         15 my $transcript = Bio::SeqFeature::Gene::Transcript->new
192             (-source => $Srctag,
193             -seq_id => $self->_target_id, # if this had been specified
194             -start => $1,
195             -end => $2,
196             );
197 6         9 my $nbr = 1;
198 6         16 while( $_ = $self->_readline ) {
199 26         84 $self->debug( $_ );
200              
201 26 100       113 unless( m/^\s+Exon\s+(\d+)\s+(\d+)\s+phase\s+(\d+)/ ){
202 6         22 $self->_pushback($_);
203 6         9 last;
204             }
205 20         64 my ($e_start,$e_end,$phase,$e_strand) = ($1,$2,$3);
206            
207 20         42 ($e_start,$e_end,$e_strand) = $self->_get_strand($e_start,
208             $e_end);
209 20 100       42 $transcript->strand($e_strand) unless $transcript->strand != 0;
210            
211 20         43 my $exon = Bio::SeqFeature::Gene::Exon->new
212             (-seq_id=>$self->_target_id,
213             -source => $Srctag,
214             -start=>$e_start,
215             -end=>$e_end,
216             -frame => $phase,
217             -strand=>$e_strand);
218 20         79 $exon->add_tag_value("Exon",$nbr++);
219 20         36 $exon->add_tag_value('phase',$phase);
220 20         42 $transcript->add_exon($exon);
221             }
222 6         18 $genes->add_transcript($transcript);
223 6         9 last; # only process a single gene at a time
224             }
225             }
226 8         17 return $genes;
227             }
228              
229             1;