Bio::Tools::CodonTable::is_start_codon: check in case of ambiguous codons (#266)
[bioperl-live.git] / lib / Bio / Tools / Coil.pm
blobdee51de54cdc860d3de827da59adab0b82d05768
1 # Parser module for Coil Bio::Tools::Coil
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 # Please direct questions and support issues to <bioperl-l@bioperl.org>
8 # Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Tools::Coil - parser for Coil output
18 =head1 SYNOPSIS
20 use Bio::Tools::Coil
21 my $parser = Bio::Tools::Coil->new();
22 while( my $sp_feat = $parser->next_result($file) ) {
23 #do something
24 #eg
25 push @sp_feat, $sp_feat;
28 =head1 DESCRIPTION
30 Parser for Coil output
32 =head1 FEEDBACK
34 =head2 Mailing Lists
36 User feedback is an integral part of the evolution of this and other
37 Bioperl modules. Send your comments and suggestions preferably to
38 the Bioperl mailing list. Your participation is much appreciated.
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
43 =head2 Support
45 Please direct usage questions or support issues to the mailing list:
47 I<bioperl-l@bioperl.org>
49 rather than to the module maintainer directly. Many experienced and
50 reponsive experts will be able look at the problem and quickly
51 address it. Please include a thorough description of the problem
52 with code and data examples if at all possible.
54 =head2 Reporting Bugs
56 Report bugs to the Bioperl bug tracking system to help us keep track
57 of the bugs and their resolution. Bug reports can be submitted via the
58 web:
60 https://github.com/bioperl/bioperl-live/issues
62 =head1 AUTHOR
64 Based on the EnsEMBL module Bio::EnsEMBL::Pipeline::Runnable::Protein::Coil
65 originally written by Marc Sohrmann (ms2@sanger.ac.uk)
66 Written in BioPipe by Balamurugan Kumarasamy <savikalpa@fugu-sg.org>
67 # Please direct questions and support issues to <bioperl-l@bioperl.org>
69 Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
71 =head1 APPENDIX
73 The rest of the documentation details each of the object methods.
74 Internal methods are usually preceded with a _
77 =cut
79 package Bio::Tools::Coil;
81 use strict;
83 use Bio::SeqFeature::FeaturePair;
84 use Bio::SeqFeature::Generic;
85 use base qw(Bio::Root::Root Bio::Root::IO);
89 sub new {
90 my($class,@args) = @_;
92 my $self = $class->SUPER::new(@args);
93 $self->_initialize_io(@args);
95 return $self;
98 =head2 parse_results
100 Title : parse_results
101 Usage : obj->parse_results
102 Function: Parses the coil output. Automatically called by
103 next_result() if not yet done.
104 Example :
105 Returns :
107 =cut
109 sub parse_results {
110 my ($self,$resfile) = @_;
111 my $filehandle = $resfile;
112 my %result_hash =_read_fasta($filehandle);#bala no file handle
113 my @ids = keys %result_hash;
114 my @feats;
115 foreach my $id (keys %result_hash){
116 my $pep = reverse ($result_hash{$id});
117 my $count = my $switch = 0;
118 my ($start, $end);
119 while (my $aa = chop $pep) {
120 $count++;
121 if (!$switch && $aa eq "x") {
122 $start = $count;
123 $switch = 1;
125 elsif ($switch && $aa ne "x") {
126 $end = $count-1;
127 my (%feature);
128 $feature{name} = $id;
129 $feature{start} = $start;
130 $feature{end} = $end;
131 $feature{source} = "Coils";
132 $feature{primary} = 'ncoils';
133 ($feature{program}) = 'ncoils';
134 $feature{logic_name} = 'Coils';
135 my $new_feat = $self->create_feature (\%feature);
136 $self->_add_prediction($new_feat);
137 $switch = 0;
142 $self->_predictions_parsed(1);
147 =head2 next_result
149 Title : next_result
150 Usage : while($feat = $coil->next_result($file)) {
151 # do something
153 Function: Returns the next protein feature of the coil output file
154 Returns :
155 Args :
157 =cut
159 sub next_result {
161 my ($self,$resfile) = @_;
162 my $gene;
164 $self->parse_results($resfile) unless $self->_predictions_parsed();
166 $gene = $self->_result();
168 return $gene;
172 =head2 _result
174 Title : _result
175 Usage : $feat = $obj->_result()
176 Function: internal
177 Example :
178 Returns :
180 =cut
182 sub _result {
183 my ($self) = @_;
185 return unless(exists($self->{'_feats'}) && @{$self->{'_feats'}});
186 return shift(@{$self->{'_feats'}});
189 =head2 _add_prediction
191 Title : _add_prediction()
192 Usage : $obj->_add_prediction($feat)
193 Function: internal
194 Example :
195 Returns :
197 =cut
199 sub _add_prediction {
200 my ($self, $gene) = @_;
202 if(! exists($self->{'_feats'})) {
203 $self->{'_feats'} = [];
205 push(@{$self->{'_feats'}}, $gene);
208 =head2 _predictions_parsed
210 Title : _predictions_parsed
211 Usage : $obj->_predictions_parsed
212 Function: internal
213 Example :
214 Returns : TRUE or FALSE
216 =cut
218 sub _predictions_parsed {
219 my ($self, $val) = @_;
221 $self->{'_preds_parsed'} = $val if $val;
222 if(! exists($self->{'_preds_parsed'})) {
223 $self->{'_preds_parsed'} = 0;
225 return $self->{'_preds_parsed'};
229 =head2 create_feature
231 Title : create_feature
232 Usage : obj->create_feature(\%feature)
233 Function: Internal(not to be used directly)
234 Returns :
235 Args :
238 =cut
240 sub create_feature {
241 my ($self, $feat) = @_;
244 # create feature object
245 my $feature = Bio::SeqFeature::Generic->new
246 (-seq_id => $feat->{name},
247 -start => $feat->{start},
248 -end => $feat->{end},
249 -score => $feat->{score},
250 -source => $feat->{source},
251 -primary => $feat->{primary},
252 -logic_name => $feat->{logic_name},
254 $feature->add_tag_value('evalue',0);
255 $feature->add_tag_value('percent_id','NULL');
256 $feature->add_tag_value("hid",$feat->{primary});
259 return $feature;
263 =head2 _read_fasta
265 Title : _read_fasta
266 Usage : obj->_read_fasta($file)
267 Function: Internal(not to be used directly)
268 Returns :
269 Args :
272 =cut
274 sub _read_fasta {
275 local (*FILE) = @_;
276 my( $id , $seq , %name2seq);#bala
277 while (<FILE>) {
278 chomp; #bala
279 if (/^>(\S+)/) {
281 my $new_id = $1;
282 if ($id) {
283 $name2seq{$id} = $seq;
285 $id = $new_id ; $seq = "" ;
286 } elsif (eof) {
287 if ($id) {
288 $seq .= $_ ;#bala line instead of $_
289 $name2seq{$id} = $seq;
292 else {
293 $seq .= $_;
296 return %name2seq;