Bio::DB::Universal: move into its own distribution
[bioperl-live.git] / Bio / Tools / Coil.pm
blobbdbdc1ceeb9e0ffe93389d711ac7fa06e317cc45
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;
80 use strict;
82 use Bio::SeqFeature::FeaturePair;
83 use Bio::SeqFeature::Generic;
84 use base qw(Bio::Root::Root Bio::Root::IO);
88 sub new {
89 my($class,@args) = @_;
91 my $self = $class->SUPER::new(@args);
92 $self->_initialize_io(@args);
94 return $self;
97 =head2 parse_results
99 Title : parse_results
100 Usage : obj->parse_results
101 Function: Parses the coil output. Automatically called by
102 next_result() if not yet done.
103 Example :
104 Returns :
106 =cut
108 sub parse_results {
109 my ($self,$resfile) = @_;
110 my $filehandle = $resfile;
111 my %result_hash =_read_fasta($filehandle);#bala no file handle
112 my @ids = keys %result_hash;
113 my @feats;
114 foreach my $id (keys %result_hash){
115 my $pep = reverse ($result_hash{$id});
116 my $count = my $switch = 0;
117 my ($start, $end);
118 while (my $aa = chop $pep) {
119 $count++;
120 if (!$switch && $aa eq "x") {
121 $start = $count;
122 $switch = 1;
124 elsif ($switch && $aa ne "x") {
125 $end = $count-1;
126 my (%feature);
127 $feature{name} = $id;
128 $feature{start} = $start;
129 $feature{end} = $end;
130 $feature{source} = "Coils";
131 $feature{primary} = 'ncoils';
132 ($feature{program}) = 'ncoils';
133 $feature{logic_name} = 'Coils';
134 my $new_feat = $self->create_feature (\%feature);
135 $self->_add_prediction($new_feat);
136 $switch = 0;
141 $self->_predictions_parsed(1);
146 =head2 next_result
148 Title : next_result
149 Usage : while($feat = $coil->next_result($file)) {
150 # do something
152 Function: Returns the next protein feature of the coil output file
153 Returns :
154 Args :
156 =cut
158 sub next_result {
160 my ($self,$resfile) = @_;
161 my $gene;
163 $self->parse_results($resfile) unless $self->_predictions_parsed();
165 $gene = $self->_result();
167 return $gene;
171 =head2 _result
173 Title : _result
174 Usage : $feat = $obj->_result()
175 Function: internal
176 Example :
177 Returns :
179 =cut
181 sub _result {
182 my ($self) = @_;
184 return unless(exists($self->{'_feats'}) && @{$self->{'_feats'}});
185 return shift(@{$self->{'_feats'}});
188 =head2 _add_prediction
190 Title : _add_prediction()
191 Usage : $obj->_add_prediction($feat)
192 Function: internal
193 Example :
194 Returns :
196 =cut
198 sub _add_prediction {
199 my ($self, $gene) = @_;
201 if(! exists($self->{'_feats'})) {
202 $self->{'_feats'} = [];
204 push(@{$self->{'_feats'}}, $gene);
207 =head2 _predictions_parsed
209 Title : _predictions_parsed
210 Usage : $obj->_predictions_parsed
211 Function: internal
212 Example :
213 Returns : TRUE or FALSE
215 =cut
217 sub _predictions_parsed {
218 my ($self, $val) = @_;
220 $self->{'_preds_parsed'} = $val if $val;
221 if(! exists($self->{'_preds_parsed'})) {
222 $self->{'_preds_parsed'} = 0;
224 return $self->{'_preds_parsed'};
228 =head2 create_feature
230 Title : create_feature
231 Usage : obj->create_feature(\%feature)
232 Function: Internal(not to be used directly)
233 Returns :
234 Args :
237 =cut
239 sub create_feature {
240 my ($self, $feat) = @_;
243 # create feature object
244 my $feature = Bio::SeqFeature::Generic->new
245 (-seq_id => $feat->{name},
246 -start => $feat->{start},
247 -end => $feat->{end},
248 -score => $feat->{score},
249 -source => $feat->{source},
250 -primary => $feat->{primary},
251 -logic_name => $feat->{logic_name},
253 $feature->add_tag_value('evalue',0);
254 $feature->add_tag_value('percent_id','NULL');
255 $feature->add_tag_value("hid",$feat->{primary});
258 return $feature;
262 =head2 _read_fasta
264 Title : _read_fasta
265 Usage : obj->_read_fasta($file)
266 Function: Internal(not to be used directly)
267 Returns :
268 Args :
271 =cut
273 sub _read_fasta {
274 local (*FILE) = @_;
275 my( $id , $seq , %name2seq);#bala
276 while (<FILE>) {
277 chomp; #bala
278 if (/^>(\S+)/) {
280 my $new_id = $1;
281 if ($id) {
282 $name2seq{$id} = $seq;
284 $id = $new_id ; $seq = "" ;
285 } elsif (eof) {
286 if ($id) {
287 $seq .= $_ ;#bala line instead of $_
288 $name2seq{$id} = $seq;
291 else {
292 $seq .= $_;
295 return %name2seq;