speelink fixes, patch courtesy Charles Plessy, fixes #3256
[bioperl-run.git] / lib / Bio / Tools / Run / tRNAscanSE.pm
blob4c77c42a20fa7ab58c7f6c4fba4f86b26b613254
1 # BioPerl module for Bio::Tools::Run::tRNAscanSE
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 # Cared for by Bioperl
7 # Copyright Bioperl, Mark Johnson <mjohnson-at-watson-dot-wustl-dot-edu>
9 # Special thanks to Chris Fields, Sendu Bala
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Tools::Run::tRNAscanSE - Wrapper for local execution of tRNAscan-SE
19 =head1 SYNOPSIS
21 my $factory = Bio::Tools::Run::tRNAscanSE->new('-program' => 'tRNAscan-SE');
23 # Pass the factory Bio::Seq objects
24 # returns a Bio::Tools::tRNAscanSE object
25 my $factory = $factory->run($seq);
27 my $factory = $factory->run(@seq);
29 =head1 DESCRIPTION
31 Wrapper module for tRNAscan-SE.
33 tRNAscan-SE is open source and available at
34 L<http://selab.wustl.edu/cgi-bin/selab.pl?mode=software#trnascan/>.
36 =head1 FEEDBACK
38 =head2 Mailing Lists
40 User feedback is an integral part of the evolution of this and other
41 Bioperl modules. Send your comments and suggestions preferably to one
42 of the Bioperl mailing lists. Your participation is much appreciated.
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 =head2 Support
49 Please direct usage questions or support issues to the mailing list:
51 I<bioperl-l@bioperl.org>
53 rather than to the module maintainer directly. Many experienced and
54 reponsive experts will be able look at the problem and quickly
55 address it. Please include a thorough description of the problem
56 with code and data examples if at all possible.
58 =head2 Reporting Bugs
60 Report bugs to the Bioperl bug tracking system to help us keep track
61 the bugs and their resolution. Bug reports can be submitted via the
62 web:
64 http://redmine.open-bio.org/projects/bioperl/
66 =head1 AUTHOR - Mark Johnson
68 Email: mjohnson-at-watson-dot-wustl-dot-edu
70 =head1 APPENDIX
72 The rest of the documentation details each of the object
73 methods. Internal methods are usually preceded with a _
75 =cut
77 package Bio::Tools::Run::tRNAscanSE;
79 use strict;
80 use warnings;
82 use Bio::SeqIO;
83 use Bio::Root::Root;
84 use Bio::Tools::Run::WrapperBase;
85 use Bio::Tools::tRNAscanSE;
86 use English;
87 use IPC::Run; # Should be okay on WIN32 (See IPC::Run Docs)
89 use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
91 our @params = (qw(program));
92 our @tRNAscanSE_switches = (qw(A B C G O P));
94 =head2 program_name
96 Title : program_name
97 Usage : $factory>program_name()
98 Function: gets/sets the program name
99 Returns: string
100 Args : string
102 =cut
104 sub program_name {
106 my ($self, $val) = @_;
108 $self->program($val) if $val;
110 return $self->program();
114 =head2 program_dir
116 Title : program_dir
117 Usage : $factory->program_dir()
118 Function: gets/sets the program dir
119 Returns: string
120 Args : string
122 =cut
124 sub program_dir {
126 my ($self, $val) = @_;
128 $self->{'_program_dir'} = $val if $val;
130 return $self->{'_program_dir'};
134 =head2 new
136 Title : new
137 Usage : $tRNAscanSE->new(@params)
138 Function: creates a new tRNAscanSE factory
139 Returns: Bio::Tools::Run::tRNAscanSE
140 Args :
142 =cut
144 sub new {
146 my ($class,@args) = @_;
147 my $self = $class->SUPER::new(@args);
149 $self->io->_initialize_io();
151 $self->_set_from_args(
152 \@args,
153 -methods => [
154 @params,
155 @tRNAscanSE_switches,
157 -create => 1,
160 unless (defined($self->program())) {
161 $self->throw('Must specify program');
164 return $self;
168 =head2 run
170 Title : run
171 Usage : $obj->run($seq_file)
172 Function: Runs tRNAscan-SE
173 Returns : A Bio::Tools::tRNAscanSE object
174 Args : An array of Bio::PrimarySeqI objects
176 =cut
178 sub run{
180 my ($self, @seq) = @_;
182 unless (@seq) {
183 $self->throw("Must supply at least one Bio::PrimarySeqI");
186 foreach my $seq (@seq) {
188 unless ($seq->isa('Bio::PrimarySeqI')) {
189 $self->throw("Object does not implement Bio::PrimarySeqI");
194 my $program_name = $self->program_name();
195 my $file_name = $self->_write_seq_file(@seq);
197 return $self->_run($file_name);
201 =head2 _run
203 Title : _run
204 Usage : $obj->_run()
205 Function: Internal(not to be used directly)
206 Returns : An instance of Bio::Tools::tRNAscanSE
207 Args : file name
209 =cut
211 sub _run {
213 my ($self, $seq_file_name) = @_;
215 my @cmd = (
216 $self->executable(),
217 split(/\s+/, $self->_setparams()),
218 $seq_file_name,
221 my $cmd = join(' ', @cmd);
222 $self->debug("tRNAscan-SE Command = $cmd");
224 my $program_name = $self->program_name();
225 my ($program_stderr);
227 my ($output_fh, $output_file_name) = $self->io->tempfile(-dir=> $self->tempdir());
230 my @ipc_args = (\@cmd, \undef, '>', $output_file_name, '2>', \$program_stderr);
232 # Run the program via IPC::Run so:
233 # 1) The console doesn't get cluttered up with the program's STDERR/STDOUT
234 # 2) We don't have to embed STDERR/STDOUT redirection in $cmd
235 # 3) We don't have to deal with signal handling (IPC::Run should take care
236 # of everything automagically.
238 eval {
239 IPC::Run::run(@ipc_args) || die $CHILD_ERROR;;
242 if ($EVAL_ERROR) {
243 $self->throw("tRNAscan-SE call crashed: $EVAL_ERROR");
246 $self->debug(join("\n", 'tRNAscanSE STDERR:', $program_stderr)) if $program_stderr;
248 return Bio::Tools::tRNAscanSE->new(-file => $output_file_name);
252 sub _setparams {
254 my ($self) = @_;
256 my $param_string = $self->SUPER::_setparams(
257 -params => [ ],
258 -switches => [
259 @tRNAscanSE_switches,
261 -dash => 1
265 # Kill leading and trailing whitespace
266 $param_string =~ s/^\s+//g;
267 $param_string =~ s/\s+$//g;
269 return $param_string;
273 =head2 _write_seq_file
275 Title : _write_seq_file
276 Usage : obj->_write_seq_file($seq) or obj->_write_seq_file(@seq)
277 Function: Internal(not to be used directly)
278 Returns : Name of a temp file containing program output
279 Args : One or more Bio::PrimarySeqI objects
281 =cut
283 sub _write_seq_file {
285 my ($self, @seq) = @_;
287 my ($fh, $file_name) = $self->io->tempfile(-dir=>$self->tempdir());
288 my $out = Bio::SeqIO->new(-fh => $fh , '-format' => 'Fasta');
290 foreach my $seq (@seq){
291 $out->write_seq($seq);
294 close($fh);
295 $out->close();
297 return $file_name;