Bio/Tools/Genewise.pm

filter: Statementstmt 95.4% 125 / 131 Branchbran 77.5% 31 / 40 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 18 / 18 Podpod 66.6% 2 / 3 totaltotal 90.8% 179 / 197 CC 24 SCAR 19.4
CC
24
Cov
91%
_parse_genes
15.2
_get_strand
5.1
parsed
3.0
CRAP 6.9
« Bio/Tools/Primer3.pm ↑ Summary Bio/TreeIO.pm »
1 #
2 # BioPerl module for Bio::Tools::Genewise
3 #
4 # Copyright Fugu Team
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::Genewise - Results of one Genewise run
13  
14 =head1 SYNOPSIS
15  
16 use Bio::Tools::Genewise;
17 my $gw = Bio::Tools::Genewise(-file=>"genewise.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.
34  
35 =head1 FEEDBACK
36  
37 =head2 Mailing Lists
38  
39 User feedback is an integral part of the evolution of this and other
40 Bioperl modules. Send your comments and suggestions preferably to one
41 of the Bioperl mailing lists. Your participation is much appreciated.
42  
43 bioperl-l@bioperl.org - General discussion
44 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
45  
46 =head2 Support
47  
48 Please direct usage questions or support issues to the mailing list:
49  
50 I<bioperl-l@bioperl.org>
51  
52 rather than to the module maintainer directly. Many experienced and
53 reponsive experts will be able look at the problem and quickly
54 address it. Please include a thorough description of the problem
55 with code and data examples if at all possible.
56  
57 =head2 Reporting Bugs
58  
59 Report bugs to the Bioperl bug tracking system to help us keep track
60 the bugs and their resolution. Bug reports can be submitted via the
61 web:
62  
63 https://github.com/bioperl/bioperl-live/issues
64  
65 =head1 AUTHOR - Fugu Team, Jason Stajich
66  
67 Email: fugui@worf.fugu-sg.org
68 Email: jason-at-bioperl.org
69  
70 =head1 APPENDIX
71  
72 The rest of the documentation details each of the object
73 methods. Internal methods are usually preceded with a _
74  
75 =cut
76  
77  
78 # Let the code begin...
79  
80  
81 package Bio::Tools::Genewise;
82 6 $Bio::Tools::Genewise::VERSION = '1.7.8';
83 6 ▶use vars qw($Srctag);
Subroutine BEGIN: called CC=1 SCAR=0.0
84 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 6 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 6 ▶use Bio::Tools::AnalysisResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 6 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 6 ▶use Bio::SeqFeature::Gene::Exon;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 6 ▶use Bio::SeqFeature::FeaturePair;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 6 ▶use Bio::SeqFeature::Gene::Transcript;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 6 ▶use Bio::SeqFeature::Gene::GeneStructure;
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 6 ▶use base qw(Bio::Root::Root Bio::Root::IO);
Subroutine BEGIN: called CC=1 SCAR=0.0
95 6 $Srctag = 'genewise';
96  
97 =head2 new
98  
99 Title : new
100 Usage : $obj->new(-file=>"genewise.out");
101 $obj->new(-fh=>\*GW);
102 Function: Constructor for genewise wrapper. Takes either a file or filehandle
103 Example :
104 Returns : Bio::Tools::Genewise object
105  
106 See L<Bio::Tools::Genewise>
107  
108 =cut
109  
110 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
111 5 my($class,@args) = @_;
112 5 my $self = $class->SUPER::new(@args);
113 5 $self->_initialize_io(@args);
114 5 return $self;
115 }
116  
117 =head2 _get_strand
118  
119 Title : _get_strand
120 Usage : $obj->_get_strand
121 Function: takes start and end values, swap them if start>end and
122 returns end
123 Example :
124 Returns :$start,$end,$strand
125  
126 =cut
127  
128 185 ▶sub _get_strand {
Subroutine _get_strand: called CC=4 SCAR=16.3
129 185 my ($self,$start,$end) = @_;
130 185 ▶ defined($start) || $self->throw("Need a start");
Branch: 1 branch
BranchTrueFalseTotal
defined $start or $self->throw("Need a start") 185 0 185
131 185 ▶ defined($end) || $self->throw("Need an end");
Branch: 1 branch
BranchTrueFalseTotal
defined $end or $self->throw("Need an end") 185 0 185
132 185 my $strand;
133 185 ▶ if ($start > $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $end) { } 0 185 185
134 0 my $tmp = $start;
135 0 $start = $end;
136 0 $end = $tmp;
137 0 $strand = -1;
138 }
139 else {
140 185 $strand = 1;
141 }
142 185 return ($start,$end,$strand);
143 }
144  
145 =head2 _score
146  
147 Title : _score
148 Usage : $obj->_score
149 Function: get/set for score info
150 Returns : a score value
151  
152 =cut
153  
154 25 ▶sub _score {
Subroutine _score: called CC=2 SCAR=6.9
155 25 my $self = shift;
156 25 ▶ return $self->{'_score'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 22 25
157 22 return $self->{'_score'};
158 }
159  
160 =head2 _prot_id
161  
162 Title : _prot_id
163 Usage : $obj->_prot_id
164 Function: get/set for protein id
165 Returns :a protein id
166  
167 =cut
168  
169 283 ▶sub _prot_id {
Subroutine _prot_id: called CC=2 SCAR=6.9
170 283 my $self = shift;
171 283 ▶ return $self->{'_prot_id'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 280 283
172 280 return $self->{'_prot_id'};
173 }
174  
175 =head2 _target_id
176  
177 Title : _target_id
178 Usage : $obj->_target_id
179 Function: get/set for genomic sequence id
180 Example :
181 Returns :a target id
182  
183 =cut
184  
185 150 ▶sub _target_id {
Subroutine _target_id: called CC=2 SCAR=6.9
186 150 my $self = shift;
187 150 ▶ return $self->{'_target_id'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 147 150
188 147 return $self->{'_target_id'};
189 }
190  
191  
192 =head2 next_prediction
193  
194 Title : next_prediction
195 Usage : while($gene = $genewise->next_prediction()) {
196 # do something
197 }
198 Function: Returns the gene structure prediction of the Genewise result
199 file. Call this method repeatedly until FALSE is returned.
200  
201 Example :
202 Returns : a Bio::SeqFeature::Gene::GeneStructure object
203 Args :
204  
205 See L<Bio::SeqFeature::Gene::GeneStructure>
206  
207 =cut
208  
209  
210 5 ▶sub next_prediction {
Subroutine next_prediction: called CC=2 SCAR=6.9
Pod documented
211 5 my ($self) = @_;
212  
213 5 ▶ unless ( $self->parsed ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->parsed) 3 2 5
214 3 $self->_parse_genes;
215 3 $self->parsed(1);
216 }
217 5 return shift @{$self->{'_genes'}};
218 }
219  
220 8 ▶sub parsed {
Subroutine parsed: called CC=3 SCAR=11.0
Pod undocumented
221 8 my $self = shift;
222 8 ▶ return $self->{'_parsed'} = 1 if @_ && $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if @_ and $_[0] 3 5 8
Condition66%2/3
@_ and $_[0]
!ll&&!rl&&r
503
MC/DC50%1/2
@_ and $_[0]
@_ $_[0]
Truth table66%2/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
223 5 return $self->{'_parsed'};
224 }
225
226 3 ▶sub _parse_genes {
Subroutine _parse_genes: called CC=15 SCAR=27.2
227 3 my ($self) = @_;
228 3 my (@alignments,@genes);
229 3 local ($/) = "//";
230  
231 3 ▶ while ( defined($_ = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 9 3 12
232 9 $self->debug( $_ );
233 9 ▶ while( /Alignment\s+(\d+)\s+Score\s+(\S+)\s+\(Bits\)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Alignment\s+(\d+)\s+Score\s+(\S+)\s+\(Bits\)/g) 0 9 9
234 0 $alignments[$1] = $2;
235 }
236 9 ▶ if( /Score\s+(\-?\d+(\.\d+)?)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Score\s+(\-?\d+(\.\d+)?)/) 3 6 9
237 3 $self->_score($1);# unless defined $self->_score;
238 }
239  
240 9 ▶ if( /Query\s+(?:protein|model)\:\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Query\s+(?:protein|model)\:\s+(\S+)/) 3 6 9
241 3 $self->_prot_id($1); #unless defined $self->_prot_id;
242 }
243  
244 9 ▶ if( /Target Sequence\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Target Sequence\s+(\S+)/) 3 6 9
245 3 $self->_target_id($1);# unless defined $self->_target_id;
246 }
247
248 9 ▶ next unless /Gene\s+\d+\n/;
Branch: 1 branch
BranchTrueFalseTotal
unless /Gene\s+\d+\n/ 6 3 9
249 3 my @genes_txt = split(/Gene\s+\d+\n/,$_);
250 3 shift @genes_txt; #remove first empty entry
251 3 my $gene_num = 1;
252 3 foreach my $gene_txt (@genes_txt) {
253 3 my $score = $alignments[$gene_num];
254 # If genewise has assigned a strand to the gene as a whole
255 # overall gene start and end
256 3 my ($g_start, $g_end, $type) =
257 $gene_txt =~ m/Gene\s+
258 (\d+)[\s-]+ # start (1-based)
259 (\d+)\s+ # end
260 (?:\[(\w+)\])? #
261 /x;
262 3 my $g_strand;
263 3 ▶ my $source_tag = $type ? "$Srctag". "_$type" : $Srctag;
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 0 3 3
264 3 my $genes = Bio::SeqFeature::Gene::GeneStructure->new
265 (-source => $source_tag,
266 -score => $self->_score,
267 );
268 3 $genes->add_tag_value('ID', $self->_prot_id.".gene");
269 3 my $transcript = Bio::SeqFeature::Gene::Transcript->new
270 (-source => $source_tag,
271 -score => $score);
272 3 ($g_start, $g_end, $g_strand) = $self->_get_strand($g_start,$g_end);
273 3 $genes->strand($g_strand);
274  
275 # grab exon + supporting feature info
276 3 my @exons;
277 3 ▶ unless ( @exons = $gene_txt =~ m/(Exon .+\s+Supporting .+)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@exons = $gene_txt =~ /(Exon .+\s+Supporting .+)/g) 0 3 3
278 0 @exons = $gene_txt =~ m/(Exon .+\s+)/g;
279 }
280 3 my $nbr = 1;
281  
282 # loop through each exon-supporting feature pair
283 3 foreach my $e (@exons){
284 54 my ($e_start,$e_end,$phase) =
285 $e =~ m/Exon\s+
286 (\d+)[\s-]+ # start (1 based)
287 (\d+)\s+ # end
288 phase\s+(\d+) # phase
289 /x;
290 54 my $e_strand;
291 54 ($e_start,$e_end,$e_strand) = $self->_get_strand($e_start,
292 $e_end);
293 54 ▶ $transcript->strand($e_strand) unless $transcript->strand != 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $transcript->strand != 0 3 51 54
294 54 my $exon = Bio::SeqFeature::Gene::Exon->new
295 (-seq_id =>$self->_target_id,
296 -source => $source_tag,
297 -start =>$e_start,
298 -end =>$e_end,
299 -score => $score,
300 #-frame => $phase,
301 -strand =>$e_strand);
302  
303 54 $exon->add_tag_value('phase',$phase);
304 54 $exon->is_coding(1);
305 54 ▶ if( $self->_prot_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_prot_id) 54 0 54
306 54 $exon->add_tag_value('Parent',$self->_prot_id);
307 }
308 54 $exon->add_tag_value("Exon",$nbr++);
309 54 ▶ if( $e =~ m/Supporting\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /Supporting\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) 54 0 54
310 54 my ($geno_start,$geno_end,
311 $prot_start, $prot_end) = ($1,$2,$3,$4);
312 54 my $prot_strand;
313 54 ($prot_start,$prot_end,
314 $prot_strand) = $self->_get_strand($prot_start,$prot_end);
315 54 my $pf = Bio::SeqFeature::Generic->new
316 ( -start => $prot_start,
317 -end => $prot_end,
318 -seq_id => $self->_prot_id,
319 -score => $score,
320 -strand => $prot_strand,
321 -source => $source_tag,
322 -primary_tag => 'supporting_protein_feature',);
323 54 my $geno_strand;
324 54 ($geno_start,$geno_end,
325 $geno_strand) = $self->_get_strand($geno_start,$geno_end);
326 54 my $gf = Bio::SeqFeature::Generic->new
327 ( -start => $geno_start,
328 -end => $geno_end,
329 -seq_id => $self->_target_id,
330 -score => $score,
331 -strand => $geno_strand,
332 -source => $source_tag,
333 -primary_tag => 'supporting_genomic_feature',);
334 54 my $fp = Bio::SeqFeature::FeaturePair->new
335 (-feature1 =>$gf,
336 -feature2 =>$pf);
337 54 $exon->add_tag_value( 'supporting_feature',$fp );
338 54 ▶ if( $self->_prot_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_prot_id) 54 0 54
339 54 $exon->add_tag_value('Target','Protein:'.$self->_prot_id);
340 54 $exon->add_tag_value('Target',$prot_start);
341 54 $exon->add_tag_value('Target',$prot_end);
342 }
343 }
344 54 $transcript->add_exon($exon);
345 }
346 3 $transcript->seq_id($self->_target_id);
347 3 $transcript->add_tag_value('ID', $self->_prot_id);
348 3 $transcript->add_tag_value('Parent', $self->_prot_id.".gene");
349 3 $genes->add_transcript($transcript);
350 3 $genes->seq_id($self->_target_id);
351 3 push @genes, $genes;
352 3 $gene_num++;
353 }
354 }
355 3 $self->{'_genes'} = \@genes;
356 }
357  
358 6 1;
« Bio/Tools/Primer3.pm ↑ Summary Bio/TreeIO.pm »