comparison variant_effect_predictor/Bio/Tools/Coil.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 # Parser module for Coil Bio::Tools::Coil
2 #
3 # Based on the EnsEMBL module Bio::EnsEMBL::Pipeline::Runnable::Protein::Coil
4 # originally written by Marc Sohrmann (ms2@sanger.ac.uk)
5 # Written in BioPipe by Balamurugan Kumarasamy <savikalpa@fugu-sg.org>
6 # Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
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::Coil
15
16 =head1 SYNOPSIS
17
18 use Bio::Tools::Coil
19 my $parser = new Bio::Tools::Coil();
20 while( my $sp_feat = $parser->next_result($file) ) {
21 #do something
22 #eg
23 push @sp_feat, $sp_feat;
24 }
25
26 =head1 DESCRIPTION
27
28 Parser for Coil output
29
30 =head1 FEEDBACK
31
32 =head2 Mailing Lists
33
34 User feedback is an integral part of the evolution of this and other
35 Bioperl modules. Send your comments and suggestions preferably to
36 the Bioperl mailing list. Your participation is much appreciated.
37
38 bioperl-l@bioperl.org - General discussion
39 http://bioperl.org/MailList.shtml - About the mailing lists
40
41 =head2 Reporting Bugs
42
43 Report bugs to the Bioperl bug tracking system to help us keep track
44 of the bugs and their resolution. Bug reports can be submitted via
45 email or the web:
46
47 bioperl-bugs@bio.perl.org
48 http://bugzilla.bioperl.org/
49
50 =head1 AUTHOR
51
52 Based on the EnsEMBL module Bio::EnsEMBL::Pipeline::Runnable::Protein::Coil
53 originally written by Marc Sohrmann (ms2@sanger.ac.uk)
54 Written in BioPipe by Balamurugan Kumarasamy <savikalpa@fugu-sg.org>
55 Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
56
57 =head1 APPENDIX
58
59 The rest of the documentation details each of the object methods.
60 Internal methods are usually preceded with a _
61
62
63 =cut
64
65 package Bio::Tools::Coil;
66 use vars qw(@ISA);
67 use strict;
68
69 use Bio::Root::Root;
70 use Bio::SeqFeature::FeaturePair;
71 use Bio::Root::IO;
72 use Bio::SeqFeature::Generic;
73 @ISA = qw(Bio::Root::Root Bio::Root::IO);
74
75
76
77 sub new {
78 my($class,@args) = @_;
79
80 my $self = $class->SUPER::new(@args);
81 $self->_initialize_io(@args);
82
83 return $self;
84 }
85
86 =head2 parse_results
87
88 Title : parse_results
89 Usage : obj->parse_results
90 Function: Parses the coil output. Automatically called by
91 next_result() if not yet done.
92 Example :
93 Returns :
94
95 =cut
96
97 sub parse_results {
98 my ($self,$resfile) = @_;
99 my $filehandle = $resfile;
100 my %result_hash =_read_fasta($filehandle);#bala no file handle
101 my @ids = keys %result_hash;
102 my @feats;
103 foreach my $id (keys %result_hash){
104 my $pep = reverse ($result_hash{$id});
105 my $count = my $switch = 0;
106 my ($start, $end);
107 while (my $aa = chop $pep) {
108 $count++;
109 if (!$switch && $aa eq "x") {
110 $start = $count;
111 $switch = 1;
112 }
113 elsif ($switch && $aa ne "x") {
114 $end = $count-1;
115 my (%feature);
116 $feature{name} = $id;
117 $feature{start} = $start;
118 $feature{end} = $end;
119 $feature{source} = "Coils";
120 $feature{primary} = 'ncoils';
121 ($feature{program}) = 'ncoils';
122 $feature{logic_name} = 'Coils';
123 my $new_feat = $self->create_feature (\%feature);
124 $self->_add_prediction($new_feat);
125 $switch = 0;
126 }
127 }
128 }
129
130 $self->_predictions_parsed(1);
131
132 }
133 =head2 next_result
134
135 Title : next_result
136 Usage : while($feat = $coil->next_result($file)) {
137 # do something
138 }
139 Function: Returns the next protein feature of the coil output file
140 Returns :
141 Args :
142
143 =cut
144
145 sub next_result{
146
147 my ($self,$resfile) = @_;
148 my $gene;
149
150 $self->parse_results($resfile) unless $self->_predictions_parsed();
151
152 $gene = $self->_result();
153
154 return $gene;
155
156 }
157
158 =head2 _result
159
160 Title : _result
161 Usage : $feat = $obj->_result()
162 Function: internal
163 Example :
164 Returns :
165
166 =cut
167
168 sub _result{
169 my ($self) = @_;
170
171 return undef unless(exists($self->{'_feats'}) && @{$self->{'_feats'}});
172 return shift(@{$self->{'_feats'}});
173
174 }
175
176 =head2 _add_prediction
177
178 Title : _add_prediction()
179 Usage : $obj->_add_prediction($feat)
180 Function: internal
181 Example :
182 Returns :
183
184 =cut
185
186 sub _add_prediction {
187 my ($self, $gene) = @_;
188
189 if(! exists($self->{'_feats'})) {
190 $self->{'_feats'} = [];
191 }
192 push(@{$self->{'_feats'}}, $gene);
193 }
194
195 =head2 _predictions_parsed
196
197 Title : _predictions_parsed
198 Usage : $obj->_predictions_parsed
199 Function: internal
200 Example :
201 Returns : TRUE or FALSE
202
203 =cut
204
205 sub _predictions_parsed {
206 my ($self, $val) = @_;
207
208 $self->{'_preds_parsed'} = $val if $val;
209 if(! exists($self->{'_preds_parsed'})) {
210 $self->{'_preds_parsed'} = 0;
211 }
212 return $self->{'_preds_parsed'};
213 }
214
215
216 =head2 create_feature
217
218 Title : create_feature
219 Usage : obj->create_feature(\%feature)
220 Function: Internal(not to be used directly)
221 Returns :
222 Args :
223
224
225 =cut
226
227 sub create_feature {
228 my ($self, $feat) = @_;
229
230
231 # create feature object
232 my $feature = Bio::SeqFeature::Generic->new(-seq_id => $feat->{name},
233 -start => $feat->{start},
234 -end => $feat->{end},
235 -score => $feat->{score},
236 -source => $feat->{source},
237 -primary => $feat->{primary},
238 -logic_name => $feat->{logic_name},
239 );
240 $feature->add_tag_value('evalue',0);
241 $feature->add_tag_value('percent_id','NULL');
242 $feature->add_tag_value("hid",$feat->{primary});
243
244
245 return $feature;
246
247 }
248
249 =head2 _read_fasta
250
251 Title : _read_fasta
252 Usage : obj->_read_fasta($file)
253 Function: Internal(not to be used directly)
254 Returns :
255 Args :
256
257
258 =cut
259
260 sub _read_fasta {
261 local (*FILE) = @_;
262 my( $id , $seq , %name2seq);#bala
263 while (<FILE>) {
264 chomp;#bala
265 if (/^>(\S+)/) {
266
267 my $new_id = $1;
268 if ($id) {
269 $name2seq{$id} = $seq;
270 }
271 $id = $new_id ; $seq = "" ;
272 }
273 elsif (eof) {
274 if ($id) {
275 $seq .= $_ ;#bala line instead of $_
276 $name2seq{$id} = $seq;
277 }
278 }
279 else {
280 $seq .= $_
281 }
282 }
283 return %name2seq;
284 }
285
286
287
288 1;
289
290