speelink fixes, patch courtesy Charles Plessy, fixes #3256
[bioperl-run.git] / lib / Bio / Tools / Run / Signalp.pm
blob2756dae1faa66494448ba09b594ca0888640fcfc
1 # Wrapper module for SignalP Bio::Tools::Run::Signalp
3 # Based on the EnsEMBL module Bio::EnsEMBL::Pipeline::Runnable::Protein::Signalp
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 =head1 NAME
12 Bio::Tools::Run::Signalp
14 =head1 SYNOPSIS
16 Build a Signalp factory
18 my $factory = Bio::Tools::Run::Signalp->new();
19 # Pass the factory a Bio::Seq object
20 # @feats is an array of Bio::SeqFeature::Generic objects
21 my @feats = $factory->run($seq);
23 =head1 DESCRIPTION
25 wrapper module for Signalp program
27 =head1 FEEDBACK
29 =head2 Mailing Lists
31 User feedback is an integral part of the evolution of this and other
32 Bioperl modules. Send your comments and suggestions preferably to one
33 of the Bioperl mailing lists. Your participation is much appreciated.
35 bioperl-l@bioperl.org - General discussion
36 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
38 =head2 Support
40 Please direct usage questions or support issues to the mailing list:
42 I<bioperl-l@bioperl.org>
44 rather than to the module maintainer directly. Many experienced and
45 reponsive experts will be able look at the problem and quickly
46 address it. Please include a thorough description of the problem
47 with code and data examples if at all possible.
49 =head2 Reporting Bugs
51 Report bugs to the Bioperl bug tracking system to help us keep track
52 the bugs and their resolution. Bug reports can be submitted via the
53 web:
55 http://redmine.open-bio.org/projects/bioperl/
57 =head1 AUTHOR
59 Based on the EnsEMBL module Bio::EnsEMBL::Pipeline::Runnable::Protein::Signalp
60 originally written by Marc Sohrmann (ms2@sanger.ac.uk)
61 Written in BioPipe by Balamurugan Kumarasamy <savikalpa@fugu-sg.org>
62 Contributions by David Vilanova (david.vilanova@urbanet.ch)
63 Shawn Hoon (shawnh@fugu-sg.org)
64 # Please direct questions and support issues to <bioperl-l@bioperl.org>
66 Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
68 =head1 APPENDIX
70 The rest of the documentation details each of the object
71 methods. Internal methods are usually preceded with a _
73 =cut
75 package Bio::Tools::Run::Signalp;
77 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR
78 $PROGRAMNAME @SIGNALP_PARAMS %OK_FIELD);
79 use strict;
80 use Bio::SeqIO;
81 use Bio::Root::Root;
82 use Bio::Root::IO;
83 use Bio::Factory::ApplicationFactoryI;
84 use Bio::Tools::Signalp;
85 use Bio::Tools::Run::WrapperBase;
87 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
89 BEGIN {
90 @SIGNALP_PARAMS=qw(PROGRAM VERBOSE);
91 foreach my $attr ( @SIGNALP_PARAMS)
92 { $OK_FIELD{$attr}++; }
95 =head2 program_name
97 Title : program_name
98 Usage : $factory>program_name()
99 Function: holds the program name
100 Returns: string
101 Args : None
103 =cut
105 sub program_name {
106 return 'signalp';
109 =head2 program_dir
111 Title : program_dir
112 Usage : $factory->program_dir(@params)
113 Function: returns the program directory, obtained from ENV variable.
114 Returns: string
115 Args :
117 =cut
119 sub program_dir {
120 return Bio::Root::IO->catfile($ENV{SIGNALPDIR}) if $ENV{SIGNALPDIR};
123 sub AUTOLOAD {
124 my $self = shift;
125 my $attr = $AUTOLOAD;
126 return $self->$attr if $self->$attr;
127 $attr =~ s/.*:://;
128 $attr = uc $attr;
129 $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
130 $self->{$attr} = shift if @_;
131 return $self->{$attr};
134 =head2 new
136 Title : new
137 Usage : my $factory= Bio::Tools::Run::Signalp->new();
138 Function: creates a new Signalp factory
139 Returns: Bio::Tools::Run::Signalp
140 Args :
142 =cut
144 sub new {
145 my ($class,@args) = @_;
146 my $self = $class->SUPER::new(@args);
148 my ($attr, $value);
149 while (@args) {
150 $attr = shift @args;
151 $value = shift @args;
152 next if( $attr =~ /^-/ ); # don't want named parameters
153 if ($attr =~/PROGRAM/i) {
154 $self->executable($value);
155 next;
157 $self->$attr($value);
159 return $self;
162 =head2 predict_protein_features
164 Title : predict_protein_features()
165 Usage : DEPRECATED. Use $factory->run($seq) instead
166 Function: Runs Signalp and creates an array of featrues
167 Returns : An array of Bio::SeqFeature::Generic objects
168 Args : A Bio::PrimarySeqI
170 =cut
172 sub predict_protein_features{
173 return shift->run(@_);
176 =head2 run
178 Title : run()
179 Usage : my $feats = $factory->run($seq)
180 Function: Runs Signalp
181 Returns : An array of Bio::SeqFeature::Generic objects
182 Args : A Bio::PrimarySeqI
184 =cut
186 sub run {
187 my ($self,$seq) = @_;
188 my @feats;
190 if (ref($seq) ) {
192 if (ref($seq) =~ /GLOB/) {
193 $self->throw("cannot use filehandle");
196 my $infile1 = $self->_writeSeqFile($seq);
198 $self->_input($infile1);
200 @feats = $self->_run();
201 unlink $infile1;
204 else {
205 my $in = Bio::SeqIO->new(-file => $seq, '-format' =>'fasta');
206 my $infile1;
208 while ( my $tmpseq = $in->next_seq() ) {
209 $infile1 = $self->_writeSeqFile($tmpseq);
212 $self->_input($infile1);
214 @feats = $self->_run();
217 return @feats;
220 =head2 _input
222 Title : _input
223 Usage : $factory->_input($seqFile)
224 Function: get/set for input file
225 Returns :
226 Args :
228 =cut
230 sub _input() {
231 my ($self,$infile1) = @_;
232 $self->{'input'} = $infile1 if(defined $infile1);
233 return $self->{'input'};
236 =head2 _run
238 Title : _run
239 Usage : $factory->_run()
240 Function: Makes a system call and runs signalp
241 Returns : An array of Bio::SeqFeature::Generic objects
242 Args :
244 =cut
246 sub _run {
247 my ($self)= @_;
249 my ($tfh1,$outfile) = $self->io->tempfile(-dir=>$self->tempdir());
250 my $str =$self->executable." -t euk -trunc 50 ".$self->{'input'}." > ".$outfile;
251 my $status = system($str);
252 $self->throw( "Signalp call ($str) crashed: $? \n") unless $status==0;
254 my $filehandle;
255 if (ref ($outfile) !~ /GLOB/) {
256 open (SIGNALP, "<".$outfile) or $self->throw ("Couldn't open file ".$outfile.": $!\n");
257 $filehandle = \*SIGNALP;
259 else {
260 $filehandle = $outfile;
263 my $signalp_parser = Bio::Tools::Signalp->new(-fh=>$filehandle);
265 my @signalp_feat;
267 while(my $signalp_feat = $signalp_parser->next_result){
269 push @signalp_feat, $signalp_feat;
272 $self->cleanup();
273 close($tfh1);
274 undef $tfh1;
275 unlink $outfile;
277 return @signalp_feat;
281 =head2 _writeSeqFile
283 Title : _writeSeqFile
284 Usage : $factory->_writeSeqFile($seq)
285 Function: Creates a file from the given seq object
286 Returns : A string(filename)
287 Args : Bio::PrimarySeqI
289 =cut
291 sub _writeSeqFile{
292 my ($self,$seq) = @_;
293 my ($tfh,$inputfile) = $self->io->tempfile(-dir=>$self->tempdir());
294 my $in = Bio::SeqIO->new(-fh => $tfh , '-format' => 'fasta');
295 $in->write_seq($seq);
296 $in->close();
297 close($tfh);
298 undef $tfh;
299 return $inputfile;