1# Wrapper  module for SignalP Bio::Tools::Run::Signalp
2#
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>
7#
8# Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
9
10=head1 NAME
11
12Bio::Tools::Run::Signalp
13
14=head1 SYNOPSIS
15
16  Build a Signalp factory
17
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);
22
23=head1 DESCRIPTION
24
25  wrapper module for Signalp program
26
27=head1 FEEDBACK
28
29=head2 Mailing Lists
30
31User feedback is an integral part of the evolution of this and other
32Bioperl modules. Send your comments and suggestions preferably to one
33of the Bioperl mailing lists.  Your participation is much appreciated.
34
35  bioperl-l@bioperl.org                  - General discussion
36  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists
37
38=head2 Support
39
40Please direct usage questions or support issues to the mailing list:
41
42I<bioperl-l@bioperl.org>
43
44rather than to the module maintainer directly. Many experienced and
45reponsive experts will be able look at the problem and quickly
46address it. Please include a thorough description of the problem
47with code and data examples if at all possible.
48
49=head2 Reporting Bugs
50
51Report bugs to the Bioperl bug tracking system to help us keep track
52the bugs and their resolution.  Bug reports can be submitted via the
53web:
54
55  http://redmine.open-bio.org/projects/bioperl/
56
57=head1 AUTHOR
58
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>
65#
66 Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
67
68=head1 APPENDIX
69
70 The rest of the documentation details each of the object
71 methods. Internal methods are usually preceded with a _
72
73=cut
74
75package Bio::Tools::Run::Signalp;
76
77use vars qw($AUTOLOAD @ISA $PROGRAM  $PROGRAMDIR
78            $PROGRAMNAME @SIGNALP_PARAMS %OK_FIELD);
79use strict;
80use Bio::SeqIO;
81use Bio::Root::Root;
82use Bio::Root::IO;
83use Bio::Factory::ApplicationFactoryI;
84use Bio::Tools::Signalp;
85use Bio::Tools::Run::WrapperBase;
86
87@ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
88
89BEGIN {
90       @SIGNALP_PARAMS=qw(PROGRAM VERBOSE);
91       foreach my $attr ( @SIGNALP_PARAMS)
92                        { $OK_FIELD{$attr}++; }
93}
94
95=head2 program_name
96
97 Title   : program_name
98 Usage   : $factory>program_name()
99 Function: holds the program name
100 Returns:  string
101 Args    : None
102
103=cut
104
105sub program_name {
106    return 'signalp';
107}
108
109=head2 program_dir
110
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    :
116
117=cut
118
119sub program_dir {
120    return Bio::Root::IO->catfile($ENV{SIGNALPDIR}) if $ENV{SIGNALPDIR};
121}
122
123sub 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};
132}
133
134=head2 new
135
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    :
141
142=cut
143
144sub new {
145       my ($class,@args) = @_;
146       my $self = $class->SUPER::new(@args);
147
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;
156           }
157           $self->$attr($value);
158       }
159       return $self;
160}
161
162=head2 predict_protein_features
163
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
169
170=cut
171
172sub predict_protein_features{
173    return shift->run(@_);
174}
175
176=head2 run
177
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
183
184=cut
185
186sub run {
187    my ($self,$seq) = @_;
188    my @feats;
189
190    if (ref($seq) ) {
191
192        if (ref($seq) =~ /GLOB/) {
193            $self->throw("cannot use filehandle");
194        }
195
196	my $infile1 = $self->_writeSeqFile($seq);
197
198	$self->_input($infile1);
199
200	@feats = $self->_run();
201	unlink $infile1;
202
203    }
204    else {
205	my $in  = Bio::SeqIO->new(-file => $seq, '-format' =>'fasta');
206	my $infile1;
207
208	while ( my $tmpseq = $in->next_seq() ) {
209	    $infile1 = $self->_writeSeqFile($tmpseq);
210	}
211
212	$self->_input($infile1);
213
214	@feats = $self->_run();
215    }
216
217    return @feats;
218}
219
220=head2 _input
221
222 Title   :   _input
223 Usage   :   $factory->_input($seqFile)
224 Function:   get/set for input file
225 Returns :
226 Args    :
227
228=cut
229
230sub _input() {
231     my ($self,$infile1) = @_;
232     $self->{'input'} = $infile1 if(defined $infile1);
233     return $self->{'input'};
234 }
235
236=head2 _run
237
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    :
243
244=cut
245
246sub _run {
247     my ($self)= @_;
248
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;
253
254     my $filehandle;
255     if (ref ($outfile) !~ /GLOB/) {
256        open (SIGNALP, "<".$outfile) or $self->throw ("Couldn't open file ".$outfile.": $!\n");
257        $filehandle = \*SIGNALP;
258     }
259     else {
260        $filehandle = $outfile;
261     }
262
263     my $signalp_parser = Bio::Tools::Signalp->new(-fh=>$filehandle);
264
265     my @signalp_feat;
266
267    while(my $signalp_feat = $signalp_parser->next_result){
268
269        push @signalp_feat, $signalp_feat;
270    }
271
272     $self->cleanup();
273     close($tfh1);
274     undef $tfh1;
275     unlink $outfile;
276
277     return @signalp_feat;
278}
279
280
281=head2 _writeSeqFile
282
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
288
289=cut
290
291sub _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;
300
301}
3021;
303