comparison variant_effect_predictor/Bio/Tools/Pseudowise.pm @ 0:2bc9b66ada89 draft default tip

Uploaded
author mahtabm
date Thu, 11 Apr 2013 06:29:17 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2bc9b66ada89
1 # BioPerl module for Bio::Tools::Pseudowise
2 #
3 # Copyright Fugu Team
4 #
5 # You may distribute this module under the same terms as perl itself
6
7 # POD documentation - main docs before the code
8
9 =head1 NAME
10
11 Bio::Tools::Pseudowise - Results of one Pseudowise run
12
13 =head1 SYNOPSIS
14
15 use Bio::Tools::Pseudowise;
16
17 my $parser = Bio::Tools::Pseudowise->new(-file=>"pw.out");
18 while(my $feat = $parser->next_result){
19 push @feat, $feat;
20 }
21
22 =head1 DESCRIPTION
23
24 Pseudowise is a pseudogene prediction program written by Ewan Birney as part of the
25 Wise Package. This module is the parser for the output of the program.
26
27 http://www.sanger.ac.uk/software/wise2
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 one
35 of the Bioperl mailing lists. Your participation is much appreciated.
36
37 bioperl-l@bioperl.org - General discussion
38 http://bio.perl.org/MailList.html - About the mailing lists
39
40 =head2 Reporting Bugs
41
42 Report bugs to the Bioperl bug tracking system to help us keep track
43 the bugs and their resolution. Bug reports can be submitted via email
44 or the web:
45
46 bioperl-bugs@bio.perl.org
47 http://bugzilla.bioperl.org/
48
49 =head1 AUTHOR - Fugu Team
50
51 Describe contact details here
52
53 =head1 APPENDIX
54
55 The rest of the documentation details each of the object methods.
56 Internal methods are usually preceded with a _
57
58 =cut
59
60
61 # Let the code begin...
62
63
64 package Bio::Tools::Pseudowise;
65 use vars qw(@ISA);
66 use strict;
67 use Symbol;
68
69 use Bio::Root::Root;
70 use Bio::Tools::AnalysisResult;
71 use Bio::SeqFeature::Generic;
72 use Bio::SeqFeature::Gene::Exon;
73 use Bio::Tools::Run::WrapperBase;
74 use Bio::SeqFeature::FeaturePair;
75 use Bio::SeqFeature::Gene::Transcript;
76 use Bio::SeqFeature::Gene::GeneStructure;
77
78 @ISA = qw(Bio::Tools::AnalysisResult);
79
80 sub _initialize_state {
81 my ($self,@args) = @_;
82
83 # first call the inherited method!
84 $self->SUPER::_initialize_state(@args);
85
86 # our private state variables
87 $self->{'_preds_parsed'} = 0;
88 $self->{'_has_cds'} = 0;
89 # array of pre-parsed predictions
90 $self->{'_preds'} = [];
91 # seq stack
92 $self->{'_seqstack'} = [];
93 }
94
95 =head2 analysis_method
96
97 Usage : $pseudowise->analysis_method();
98 Purpose : Inherited method. Overridden to ensure that the name matches
99 /pseudowise/i.
100 Returns : String
101 Argument : n/a
102
103 =cut
104
105 #-------------
106 sub analysis_method {
107 #-------------
108 my ($self, $method) = @_;
109 if($method && ($method !~ /pseudowise/i)) {
110 $self->throw("method $method not supported in " . ref($self));
111 }
112 return $self->SUPER::analysis_method($method);
113 }
114
115 =head2 next_prediction
116
117 Title : next_prediction
118 Usage : while($gene = $pseudowise->next_prediction()) {
119 # do something
120 }
121 Function: Returns the gene of the Pseudowise result
122 file. Call this method repeatedly until FALSE is returned.
123
124 Example :
125 Returns : a Bio::SeqFeature::Generic
126 Args :
127
128 =cut
129
130 sub next_prediction {
131 my ($self,$filehandle) = @_;
132 my $gene;
133
134 # if the prediction section hasn't been parsed yet, we do this now
135 $self->_parse_predictions($filehandle) unless $self->_predictions_parsed();
136
137 # get next gene structure
138 $gene = $self->_prediction();
139
140 return $gene;
141 }
142
143 =head2 _parse_predictions
144
145 Title : _parse_predictions()
146 Usage : $obj->_parse_predictions()
147 Function: Parses the prediction section. Automatically called by
148 next_prediction() if not yet done.
149 Example :
150 Returns :
151
152 =cut
153
154 sub _parse_predictions {
155 my ($self, $filehandle) = @_;
156 my $gene;
157 my @genes;
158 #The big parsing loop - parses exons and predicted peptides
159 while (<$filehandle>)
160 {
161 if (/Gene/i)
162 {
163 $gene = new Bio::SeqFeature::Generic (
164 -primary => 'pseudogene',
165 -source => 'pseudowise');
166 push @genes, $gene;
167
168 while(<$filehandle>) {
169 my @gene_elements = split;
170 my $no = scalar(@gene_elements);
171 if ((/Gene/i) && $no == 3) {
172 my @element = split;
173 my $no = scalar(@element);
174 my $gene_start = $element[1];
175 my $gene_end = $element[2];
176 $gene->start($gene_start);
177 $gene->end($gene_end);
178 }
179 elsif (/Exon/i) {
180 my @element = split;
181 my $no = scalar(@element);
182 my $exon_start = $element[1];
183 my $exon_end = $element[2];
184 my $exon_phase = $element[4];
185 my $exon = new Bio::SeqFeature::Generic (
186 -start => $exon_start,
187 -end => $exon_end,
188 -primary => 'exon',
189 -source => 'pseudowise',
190 -frame => $exon_phase);
191 $gene->add_sub_SeqFeature($exon);
192 }
193 elsif ((/Gene/i) && $no != 3) {
194 $gene = new Bio::SeqFeature::Generic (
195 -primary => 'pseudogene',
196 -source => 'pseudowise');
197 push @genes, $gene;
198 }
199 }
200 }
201 }
202 $self->_add_prediction(\@genes);
203 $self->_predictions_parsed(1);
204
205 }
206
207 =head1 _prediction
208
209 Title : _prediction()
210 Usage : $gene = $obj->_prediction()
211 Function: internal
212 Example :
213 Returns :
214
215 =cut
216
217 sub _prediction {
218 my ($self) = @_;
219
220 return undef unless(exists($self->{'_preds'}) && @{$self->{'_preds'}});
221 return shift(@{$self->{'_preds'}});
222 }
223
224 =head2 _add_prediction
225
226 Title : _add_prediction()
227 Usage : $obj->_add_prediction($gene)
228 Function: internal
229 Example :
230 Returns :
231
232 =cut
233
234 sub _add_prediction {
235 my ($self, $gene) = @_;
236
237 if(! exists($self->{'_preds'})) {
238 $self->{'_preds'} = [];
239 }
240 push(@{$self->{'_preds'}}, $gene);
241 }
242
243 =head2 _predictions_parsed
244
245 Title : _predictions_parsed
246 Usage : $obj->_predictions_parsed
247 Function: internal
248 Example :
249 Returns : TRUE or FALSE
250
251 =cut
252
253 sub _predictions_parsed {
254 my ($self, $val) = @_;
255
256 $self->{'_preds_parsed'} = $val if $val;
257 if(! exists($self->{'_preds_parsed'})) {
258 $self->{'_preds_parsed'} = 0;
259 }
260 return $self->{'_preds_parsed'};
261 }
262
263 1;