speelink fixes, patch courtesy Charles Plessy, fixes #3256
[bioperl-run.git] / lib / Bio / Tools / Run / Coil.pm
blob7d3a61193616dc83ceac204f95bbd389a34b9e68
1 # Wrapper module for Coil Bio::Tools::Run::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::Run::Coil - wrapper for ncoils program
18 =head1 SYNOPSIS
20 # Build a Coil factory
21 my $factory = Bio::Tools::Run::Coil->new($params);
23 # Pass the factory a Bio::Seq object
24 # @feats is an array of Bio::SeqFeature::Generic objects
25 my @feats = $factory->run($seq);
27 =head1 DESCRIPTION
29 This module is a wrapper for the B<ncoils> program available via
30 L<http://www.russell.embl-heidelberg.de/coils/coils.tar.gz> for predicting
31 coiled coils in protein sequences.
33 By default it looks for an executable called I<ncoils> and data/parameter files
34 in the directory specified by the I<COILSDIR> environmental variable.
36 =head1 REFERENCES
38 Lupas, van Dyke & Stock,
39 I<Predicting coiled coils from protein sequences>,
40 Science B<252>:1162-1164, 1991.
42 Lupas, A.,
43 I<Prediction and Analysis of Coiled-Coil Structures>,
44 Meth. Enzymology B<266>:513-525, 1996.
46 =head1 FEEDBACK
48 =head2 Mailing Lists
50 User feedback is an integral part of the evolution of this and other
51 Bioperl modules. Send your comments and suggestions preferably to one
52 of the Bioperl mailing lists. Your participation is much appreciated.
54 bioperl-l@bioperl.org - General discussion
55 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
57 =head2 Support
59 Please direct usage questions or support issues to the mailing list:
61 I<bioperl-l@bioperl.org>
63 rather than to the module maintainer directly. Many experienced and
64 reponsive experts will be able look at the problem and quickly
65 address it. Please include a thorough description of the problem
66 with code and data examples if at all possible.
68 =head2 Reporting Bugs
70 Report bugs to the Bioperl bug tracking system to help us keep track
71 the bugs and their resolution. Bug reports can be submitted via the
72 web:
74 http://redmine.open-bio.org/projects/bioperl/
76 =head1 AUTHORS
78 Based on the EnsEMBL module Bio::EnsEMBL::Pipeline::Runnable::Protein::Coil
79 originally written by Marc Sohrmann (ms2@sanger.ac.uk)
81 Written in BioPipe by Balamurugan Kumarasamy <savikalpa@fugu-sg.org>
83 # Please direct questions and support issues to <bioperl-l@bioperl.org>
85 Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
87 =head1 APPENDIX
89 The rest of the documentation details each of the object
90 methods. Internal methods are usually preceded with a _
92 =cut
94 package Bio::Tools::Run::Coil;
96 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR
97 $PROGRAMNAME @COIL_PARAMS %OK_FIELD);
98 use strict;
99 use Bio::SeqIO;
100 use Bio::Root::Root;
101 use Bio::Root::IO;
102 use Bio::Tools::Coil;
103 use Bio::Tools::Run::WrapperBase;
105 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
107 BEGIN {
108 @COIL_PARAMS=qw(PROGRAM VERBOSE QUIET SILENT);
109 foreach my $attr ( @COIL_PARAMS)
110 { $OK_FIELD{$attr}++; }
113 sub AUTOLOAD {
114 my $self = shift;
115 my $attr = $AUTOLOAD;
116 $attr =~ s/.*:://;
117 $attr = uc $attr;
118 $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
119 $self->{$attr} = shift if @_;
120 return $self->{$attr};
123 =head2 program_name
125 Title : program_name
126 Usage : $factory>program_name()
127 Function: holds the program name
128 Returns: string
129 Args : None
131 =cut
133 sub program_name {
134 return 'ncoils';
137 =head2 program_dir
139 Title : program_dir
140 Usage : $factory->program_dir(@params)
141 Function: returns the program directory, obtained from ENV variable.
142 Returns: string
143 Args :
145 =cut
147 sub program_dir {
148 return Bio::Root::IO->catfile($ENV{COILSDIR}) if $ENV{COILSDIR};
151 =head2 new
153 Title : new
154 Usage : $coil->new(@params)
155 Function: creates a new Coil factory
156 Returns: Bio::Tools::Run::Coil
157 Args :
159 =cut
161 sub new {
162 my ($class,@args) = @_;
163 my $self = $class->SUPER::new(@args);
164 my ($attr, $value);
165 while (@args) {
166 $attr = shift @args;
167 $value = shift @args;
168 next if( $attr =~ /^-/ ); # don't want named parameters
169 if ($attr =~/PROGRAM/i) {
170 $self->executable($value);
171 next;
173 $self->$attr($value);
175 return $self;
178 =head2 predict_protein_features
180 Title : predict_protein_features()
181 Usage : DEPRECATED. Use $obj->run instead.
182 Function: Runs Coil and creates an array of featrues
183 Returns : An array of Bio::SeqFeature::Generic objects
184 Args : A Bio::PrimarySeqI
186 =cut
188 sub predict_protein_features{
189 return shift->run(@_);
192 =head2 run
194 Title : run
195 Usage : $obj->run($seq)
196 Function: Runs Coil and creates an array of featrues
197 Returns : An array of Bio::SeqFeature::Generic objects
198 Args : A Bio::PrimarySeqI, or a Fasta filename.
200 =cut
202 sub run{
203 my ($self,$seq) = @_;
204 my @feats;
206 if (ref($seq) ) { # it is an object
207 if (ref($seq) =~ /GLOB/) {
208 $self->throw("cannot use filehandle");
211 my $infile1 = $self->_writeSeqFile($seq);
213 $self->_input($infile1);
215 @feats = $self->_run();
216 unlink $infile1;
218 else {
219 #The argument is not a seq object but a sequence in a fasta file.
220 #Perhaps should check here or before if this file is fasta format...if not die
221 #Here the file does not need to be created or deleted. Its already written and may be used by other runnables.
223 $self->_input($seq);
225 @feats = $self->_run();
229 return @feats;
233 =head2 _input
235 Title : _input
236 Usage : obj->_input($seqFile)
237 Function: Internal(not to be used directly)
238 Returns :
239 Args :
241 =cut
243 sub _input() {
244 my ($self,$infile1) = @_;
245 if(defined $infile1){
247 $self->{'input'}=$infile1;
249 return $self->{'input'};
253 =head2 _run
255 Title : _run
256 Usage : $obj->_run()
257 Function: Internal(not to be used directly)
258 Returns : An array of Bio::SeqFeature::Generic objects
259 Args :
261 =cut
263 sub _run {
264 my ($self)= @_;
266 my ($tfh1,$outfile) = $self->io->tempfile(-dir=>$self->tempdir());
267 my $str =$self->executable." -f < ".$self->{'input'}." > ".$outfile;
268 if($self->quiet || $self->verbose <=0 || $self->silent){
269 $str.=" 2>/dev/null";
271 my $status = system($str);
272 $self->throw( "Coil call ($str) crashed: $? \n") unless $status==0;
274 my $coil_parser = Bio::Tools::Coil->new();
275 my $filehandle;
276 if (ref ($outfile) !~ /GLOB/) {
277 open (COIL, "<".$outfile) or $self->throw ("Couldn't open file ".$outfile.": $!\n");
278 $filehandle = \*COIL;
280 else {
281 $filehandle = $outfile;
284 my @coil_feat;
286 while(my $coil_feat = $coil_parser->next_result($filehandle)){
288 push @coil_feat, $coil_feat;
291 $self->cleanup();
292 close($tfh1);
293 undef $tfh1;
295 unlink $outfile;
296 return @coil_feat;
300 =head2 _writeSeqFile
302 Title : _writeSeqFile
303 Usage : obj->_writeSeqFile($seq)
304 Function: Internal(not to be used directly)
305 Returns :
306 Args :
308 =cut
310 sub _writeSeqFile{
311 my ($self,$seq) = @_;
312 my ($tfh,$inputfile) = $self->io->tempfile(-dir=>$self->tempdir());
313 my $in = Bio::SeqIO->new(-fh => $tfh , '-format' => 'Fasta');
314 $in->write_seq($seq);
316 return $inputfile;