File Coverage

blib/lib/Bio/Tools/Run/Signalp.pm
Criterion Covered Total %
statement 34 96 35.4
branch 1 24 4.1
condition n/a
subroutine 12 18 66.6
pod 5 5 100.0
total 52 143 36.3


line stmt bran cond sub pod time code
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
6             # Please direct questions and support issues to
7             #
8             # Cared for by the Fugu Informatics team (fuguteam@fugu-sg.org)
9              
10             =head1 NAME
11              
12             Bio::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              
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.
34              
35             bioperl-l@bioperl.org - General discussion
36             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
37              
38             =head2 Support
39              
40             Please direct usage questions or support issues to the mailing list:
41              
42             I
43              
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.
48              
49             =head2 Reporting Bugs
50              
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:
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
62             Contributions by David Vilanova (david.vilanova@urbanet.ch)
63             Shawn Hoon (shawnh@fugu-sg.org)
64             # Please direct questions and support issues to
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              
75             package Bio::Tools::Run::Signalp;
76              
77 1         63 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR
78 1     1   99634 $PROGRAMNAME @SIGNALP_PARAMS %OK_FIELD);
  1         2  
79 1     1   4 use strict;
  1         2  
  1         17  
80 1     1   340 use Bio::SeqIO;
  1         37206  
  1         25  
81 1     1   6 use Bio::Root::Root;
  1         2  
  1         14  
82 1     1   3 use Bio::Root::IO;
  1         2  
  1         14  
83 1     1   232 use Bio::Factory::ApplicationFactoryI;
  1         107  
  1         26  
84 1     1   289 use Bio::Tools::Signalp;
  1         39183  
  1         25  
85 1     1   315 use Bio::Tools::Run::WrapperBase;
  1         2  
  1         49  
86              
87             @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
88              
89             BEGIN {
90 1     1   4 @SIGNALP_PARAMS=qw(PROGRAM VERBOSE);
91 1         2 foreach my $attr ( @SIGNALP_PARAMS)
92 2         608 { $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              
105             sub program_name {
106 6     6 1 22 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              
119             sub program_dir {
120 3 50   3 1 12 return Bio::Root::IO->catfile($ENV{SIGNALPDIR}) if $ENV{SIGNALPDIR};
121             }
122              
123             sub AUTOLOAD {
124 0     0   0 my $self = shift;
125 0         0 my $attr = $AUTOLOAD;
126 0 0       0 return $self->$attr if $self->$attr;
127 0         0 $attr =~ s/.*:://;
128 0         0 $attr = uc $attr;
129 0 0       0 $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
130 0 0       0 $self->{$attr} = shift if @_;
131 0         0 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              
144             sub new {
145 1     1 1 106 my ($class,@args) = @_;
146 1         12 my $self = $class->SUPER::new(@args);
147            
148 1         16 my ($attr, $value);
149 1         5 while (@args) {
150 0         0 $attr = shift @args;
151 0         0 $value = shift @args;
152 0 0       0 next if( $attr =~ /^-/ ); # don't want named parameters
153 0 0       0 if ($attr =~/PROGRAM/i) {
154 0         0 $self->executable($value);
155 0         0 next;
156             }
157 0         0 $self->$attr($value);
158             }
159 1         4 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              
172             sub predict_protein_features{
173 0     0 1   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              
186             sub run {
187 0     0 1   my ($self,$seq) = @_;
188 0           my @feats;
189              
190 0 0         if (ref($seq) ) {
191              
192 0 0         if (ref($seq) =~ /GLOB/) {
193 0           $self->throw("cannot use filehandle");
194             }
195              
196 0           my $infile1 = $self->_writeSeqFile($seq);
197              
198 0           $self->_input($infile1);
199              
200 0           @feats = $self->_run();
201 0           unlink $infile1;
202              
203             }
204             else {
205 0           my $in = Bio::SeqIO->new(-file => $seq, '-format' =>'fasta');
206 0           my $infile1;
207              
208 0           while ( my $tmpseq = $in->next_seq() ) {
209 0           $infile1 = $self->_writeSeqFile($tmpseq);
210             }
211              
212 0           $self->_input($infile1);
213              
214 0           @feats = $self->_run();
215             }
216              
217 0           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              
230             sub _input() {
231 0     0     my ($self,$infile1) = @_;
232 0 0         $self->{'input'} = $infile1 if(defined $infile1);
233 0           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              
246             sub _run {
247 0     0     my ($self)= @_;
248              
249 0           my ($tfh1,$outfile) = $self->io->tempfile(-dir=>$self->tempdir());
250 0           my $str =$self->executable." -t euk -trunc 50 ".$self->{'input'}." > ".$outfile;
251 0           my $status = system($str);
252 0 0         $self->throw( "Signalp call ($str) crashed: $? \n") unless $status==0;
253            
254 0           my $filehandle;
255 0 0         if (ref ($outfile) !~ /GLOB/) {
256 0 0         open (SIGNALP, "<".$outfile) or $self->throw ("Couldn't open file ".$outfile.": $!\n");
257 0           $filehandle = \*SIGNALP;
258             }
259             else {
260 0           $filehandle = $outfile;
261             }
262              
263 0           my $signalp_parser = Bio::Tools::Signalp->new(-fh=>$filehandle);
264              
265 0           my @signalp_feat;
266              
267 0           while(my $signalp_feat = $signalp_parser->next_result){
268              
269 0           push @signalp_feat, $signalp_feat;
270             }
271            
272 0           $self->cleanup();
273 0           close($tfh1);
274 0           undef $tfh1;
275 0           unlink $outfile;
276            
277 0           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              
291             sub _writeSeqFile{
292 0     0     my ($self,$seq) = @_;
293 0           my ($tfh,$inputfile) = $self->io->tempfile(-dir=>$self->tempdir());
294 0           my $in = Bio::SeqIO->new(-fh => $tfh , '-format' => 'fasta');
295 0           $in->write_seq($seq);
296 0           $in->close();
297 0           close($tfh);
298 0           undef $tfh;
299 0           return $inputfile;
300              
301             }
302             1;