cleanup of tempfiles works
[bioperl-run.git] / Bio / Tools / Run / Eponine.pm
blob1fed49f8d71a18cc4a6aba43fda55d8086dfb7d3
1 # $Id$
3 # Cared for by Tania Oh
5 # Copyright Tania Oh
7 # You may distribute this module under the same terms as perl itself
9 # POD documentation - main docs before the code
11 =head1 NAME
13 Bio::Tools::Run::Eponine-
14 Object for execution of the Eponine which is a mammalian TSS predictor
16 =head1 SYNOPSIS
18 use Bio::Tools::Run::Eponine;
19 use strict;
20 my $seq = "/data/seq.fa";
21 my $threshold = "0.999";
22 my @params = ( '-seq' => $seq,
23 '-threshold' => $threshold,
24 '-epojar' => '/usr/local/bin/eponine-scan.jar',
25 '-java' => '/usr/local/bin/java');
27 my $factory = Bio::Tools::Run::Eponine->new(@params);
28 # run eponine against fasta
29 my $r = $factory->run_eponine();
30 my $parser = Bio::Tools::Eponine->new($r);
32 while (my $feat = $parser->next_prediction){
33 #$feat contains array of SeqFeature
34 foreach my $orf($feat){
35 print $orf->seqname. "\n";
42 Various additional options and input formats are available. See the
43 DESCRIPTION section for details.
45 =head1 DESCRIPTION
47 wrapper for eponine.. a mammalian TSS predictor
49 The environment variable EPONINEDIR must be set to point at either the
50 directory which contains eponine-scan.jar or directly at the jar which
51 eponine-scan classfiles.
53 =head1 FEEDBACK
55 =head2 Mailing Lists
57 User feedback is an integral part of the evolution of this and other
58 Bioperl modules. Send your comments and suggestions preferably to one
59 of the Bioperl mailing lists. Your participation is much appreciated.
61 bioperl-l@bioperl.org - General discussion
62 http://bio.perl.org/MailList.html - About the mailing lists
64 =head2 Reporting Bugs
66 Report bugs to the Bioperl bug tracking system to help us keep track
67 the bugs and their resolution. Bug reports can be submitted via email
68 or the web:
70 bioperl-bugs@bio.perl.org
71 http://bio.perl.org/bioperl-bugs/
73 =head1 AUTHOR
75 Email gisoht@nus.edu.sg
77 =head1 APPENDIX
79 The rest of the documentation details each of the object
80 methods. Internal methods are usually preceded with a _
82 =cut
84 package Bio::Tools::Run::Eponine;
86 #tgot to take inmore parameters
88 use vars qw($AUTOLOAD @ISA @EPONINE_PARAMS %EPONINE_PARAMS
89 $EPOJAR $JAVA $PROGRAMDIR $PROGRAMNAME $PROGRAM
90 $TMPDIR $TMPOUTFILE $DEFAULT_THRESHOLD
91 %OK_FIELD);
92 use strict;
94 use Bio::Tools::Eponine;
95 use Bio::Root::Root;
96 use Bio::Root::IO;
97 use Bio::Tools::Run::WrapperBase;
99 BEGIN {
100 $DEFAULT_THRESHOLD = 50;
101 $PROGRAMNAME = 'java';
102 $EPOJAR = 'eponine-scan.jar';
104 if( ! defined $PROGRAMDIR ) {
105 $PROGRAMDIR = $ENV{'JAVA_HOME'} || $ENV{'JAVA_DIR'};
107 if (defined $PROGRAMDIR) {
108 foreach my $progname ( [qw(java)],[qw(bin java)] ) {
109 my $f = Bio::Root::IO->catfile($PROGRAMDIR, @$progname);
110 if( -e $f && -x $f ) {
111 $PROGRAM = $f;
112 last;
117 if( defined $ENV{'EPONINEDIR'} ) {
118 $EPOJAR = Bio::Root::IO->catfile($ENV{'EPONINEDIR'}, $EPOJAR);
121 %EPONINE_PARAMS = ('SEQ' => '/tmp/test.fa',
122 'THRESHOLD' => '0.999',
123 'EPOJAR' => '/usr/local/bin/eponine-scan.jar',
124 'JAVA' => '/usr/java/jre1.3.1_02/bin/java');
126 @EPONINE_PARAMS=qw(SEQ THRESHOLD JAVA EPOJAR);
128 foreach my $attr ( @EPONINE_PARAMS)
129 { $OK_FIELD{$attr}++; }
132 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
133 sub AUTOLOAD {
134 my $self = shift;
135 my $attr = $AUTOLOAD;
136 $self->debug( "************ attr: $attr\n");
137 $attr =~ s/.*:://;
138 $attr = uc $attr;
139 $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
140 $self->{$attr} = shift if @_;
141 return $self->{$attr};
144 sub new {
145 my ($caller, @args) = @_;
146 # chained new
147 my $self = $caller->SUPER::new(@args);
148 # so that tempfiles are cleaned up
150 my $java;
151 my $seq;
152 my $threshold;
153 my $epojar;
155 my ($attr, $value);
156 (undef,$TMPDIR) = $self->tempdir(CLEANUP=>1);
157 (undef,$TMPOUTFILE) = $self->tempfile(-dir => $TMPDIR);
158 while (@args) {
159 $attr = shift @args;
160 $value = shift @args;
161 next if( $attr =~ /^-/ ); # don't want named parameters
162 if ($attr =~/JAVA/i) {
163 $java = $value;
164 next;
166 if ($attr =~ /EPOJAR/i){
167 $epojar = $value;
168 next;
170 if ($attr =~ /THRESHOLD/i){
171 $threshold = $value;
172 next;
174 if ($attr =~ /SEQ/i){
175 $seq = $value;
176 next;
178 $self->$attr($value);
181 $self->{'_java'} = undef; # location of java vm
182 $self->{'_epojar'} = undef; # location of eponine-scan.jar executable JAR file.
183 $self->{'_threshold'} = 0.999; # minimum posterior for filtering predictions
184 $self->{'_filename'} = undef; #location of seq
185 $seq = $EPONINE_PARAMS{'seq'} unless defined $seq;
186 $threshold = $EPONINE_PARAMS{'threshold'} unless defined $threshold;
188 $java = $EPONINE_PARAMS{'JAVA'} unless defined $java;
189 $epojar = $EPONINE_PARAMS{'epojar'} unless defined $epojar;
190 $self->filename($seq) if ($seq);
192 if (-x $java) {
193 # full path assumed
194 $self->java($java);
197 $self->epojar($epojar) if (defined $epojar && -e $epojar);
199 if (defined $threshold && $threshold >=0 ){
200 $self->threshold($threshold);
201 } else {
202 $self->threshold($DEFAULT_THRESHOLD);
205 return $self;
210 =head2 filename
212 Title : filename
213 Usage : my $filename= $self->filename
214 Function: Get/Set the method to submit the seq
215 Returns : string
216 Args :
218 =cut
220 sub filename{
221 my ($self, $val) = @_;
222 if( defined $val ) {
223 $self->{'_filename'} = $val;
225 return $self->{'_filename'};
228 =head2 java
230 Title : java
231 Usage : $obj->java('/usr/opt/java130/bin/java');
232 Function: Get/set method for the location of java VM
233 Args : File path (optional)
235 =cut
237 sub executable { shift->java(@_); }
239 sub java {
240 my ($self, $exe,$warn) = @_;
242 if( defined $exe ) {
243 $self->{'_pathtojava'} = $exe;
246 unless( defined $self->{'_pathtojava'} ) {
247 if( $PROGRAM && -e $PROGRAM && -x $PROGRAM ) {
248 $self->{'_pathtojava'} = $PROGRAM;
249 } else {
250 my $exe;
251 if( ( $exe = $self->io->exists_exe($PROGRAMNAME) ) &&
252 -x $exe ) {
253 $self->{'_pathtojava'} = $exe;
254 } else {
255 $self->warn("Cannot find executable for $PROGRAMNAME") if $warn;
256 $self->{'_pathtojava'} = undef;
260 $self->{'_pathtojava'};
264 =head2 epojar
266 Title : epojar
267 Usage : $obj->epojar('/some/path/to/eponine-scan.jar');
268 Function: Get/set method for the location of the eponine-scan executable JAR
269 Args : Path (optional)
271 =cut
273 sub epojar {
274 my ($self, $location) = @_;
275 if ($location)
277 unless( $location ) {
278 $self->warn("eponine-scan.jar not found at $location: $!\n");
279 return undef;
281 $self->{'_epojar'} = $location ;
283 return $self->{'_epojar'};
288 =head2 threshold
290 Title : threshold
291 Usage : my $threshold = $self->threshold
292 Function: Get/Set the threshold for Eponine
293 Returns : string
294 Args : b/w 0.9 and 1.0
296 =cut
298 sub threshold{
299 my ($self, $threshold) = @_;
300 if (defined $threshold) {
301 $self->{'_threshold'} = $threshold ;
303 return $self->{'_threshold'};
308 =head2 predict_TSS
310 Title : predict_TSS
311 Usage : my @genes = $self->predict_TSS($seq)
312 Function: runs Eponine and creates an array of genes
313 Returns : An Array of SeqFeatures
314 Args : A Bio::PrimarySeqI
316 =cut
318 sub predict_TSS{
319 my ($self,$seq) = @_;
320 my $infile = $self->_setinput($seq);
321 my @tss = $self->_run_eponine();
322 return @tss;
327 =head2 _setinput()
329 Title : _setinput
330 Usage : Internal function, not to be called directly
331 Function: writes input sequence to file and return the file name
332 Example :
333 Returns : string
334 Args :
336 =cut
338 sub _setinput {
339 my ($self,$seq) = @_;
340 my ($tfh1,$inputfile) = $self->tempfile(-dir=>$TMPDIR);
341 my $in = Bio::SeqIO->new(-fh=> $tfh1 , '-format' => 'Fasta');
342 $in->write_seq($seq);
343 return ($inputfile);
346 =head2 _run_eponine
348 Title : run_eponine
349 Usage : $obj->_run_eponine()
350 Function: execs the Java VM to run eponine
351 Returns : none
352 Args : none
354 =cut
355 sub run_eponine {
356 my ($self) = @_;
357 my $result = $TMPOUTFILE;
358 my @tss;
359 #run eponine
360 $self->debug( "Running eponine-scan\n");
361 my ($java,$epojar) = ( $self->java,
362 $self->epojar);
363 unless( defined $java && -e $java && -x $java ) {
364 $self->warn("Cannot find java");
365 return undef;
367 unless(defined $epojar && -e $epojar ) {
368 $self->warn("Cannot find Eponine jar");
369 return undef;
371 my $cmd = $self->java.' -jar '.$self->epojar.' -seq '.$self->filename.' -threshold '.$self->threshold." > ".$result;
372 $self->throw("Error running eponine-scan on ".$self->filename." \n Eponine crashed ($cmd) crashed: $? \n")
373 if (system ($cmd));
375 #parse results even though it's wierd.. thought parser and wrapper should be separate
376 my $epoParser = Bio::Tools::Eponine->new(-file =>$result);
378 while (my $tss = $epoParser->next_prediction()){
379 push (@tss, $tss);
381 return @tss;
388 __END__