speelink fixes, patch courtesy Charles Plessy, fixes #3256
[bioperl-run.git] / lib / Bio / Tools / Run / Eponine.pm
blob04ae029219f381d6b6ce419ae9db6b268ab04878
1 # $Id$
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 # Cared for by Tania Oh
7 # Copyright Tania Oh
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
13 =head1 NAME
15 Bio::Tools::Run::Eponine - Object for execution of the Eponine which
16 is a mammalian TSS predictor
18 =head1 SYNOPSIS
20 use Bio::Tools::Run::Eponine;
21 use strict;
22 my $seq = "/data/seq.fa";
23 my $threshold = "0.999";
24 my @params = ( '-seq' => $seq,
25 '-threshold' => $threshold,
26 '-epojar' => '/usr/local/bin/eponine-scan.jar',
27 '-java' => '/usr/local/bin/java');
29 my $factory = Bio::Tools::Run::Eponine->new(@params);
30 # run eponine against fasta
31 my $r = $factory->run($seq);
32 my $parser = Bio::Tools::Eponine->new($r);
34 while (my $feat = $parser->next_prediction){
35 #$feat contains array of SeqFeature
36 foreach my $orf($feat){
37 print $orf->seqname. "\n";
41 # Various additional options and input formats are available. See
42 # the DESCRIPTION section for details.
44 =head1 DESCRIPTION
46 wrapper for eponine, a mammalian TSS predictor.
48 The environment variable EPONINEDIR must be set to point at either the
49 directory which contains eponine-scan.jar or directly at the jar which
50 eponine-scan classfiles. NOTE: EPONINEDIR must point at the real file
51 not a symlink.
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://bioperl.org/wiki/Mailing_lists - About the mailing lists
64 =head2 Support
66 Please direct usage questions or support issues to the mailing list:
68 I<bioperl-l@bioperl.org>
70 rather than to the module maintainer directly. Many experienced and
71 reponsive experts will be able look at the problem and quickly
72 address it. Please include a thorough description of the problem
73 with code and data examples if at all possible.
75 =head2 Reporting Bugs
77 Report bugs to the Bioperl bug tracking system to help us keep track
78 the bugs and their resolution. Bug reports can be submitted via the
79 web:
81 http://redmine.open-bio.org/projects/bioperl/
83 =head1 AUTHOR
85 Email gisoht@nus.edu.sg
87 =head1 APPENDIX
89 The rest of the documentation details each of the object
90 methods. Internal methods are usually preceded with a _
92 =cut
94 package Bio::Tools::Run::Eponine;
96 #tgot to take inmore parameters
98 use vars qw($AUTOLOAD @ISA @EPONINE_PARAMS %EPONINE_PARAMS
99 $EPOJAR $JAVA $PROGRAMDIR $PROGRAMNAME $PROGRAM
100 $TMPDIR $TMPOUTFILE $DEFAULT_THRESHOLD
101 %OK_FIELD);
102 use strict;
104 use Bio::Tools::Eponine;
105 use Bio::Root::Root;
106 use Bio::Root::IO;
107 use Bio::Tools::Run::WrapperBase;
108 @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
110 BEGIN {
111 $DEFAULT_THRESHOLD = 50;
112 $PROGRAMNAME = 'java';
113 $EPOJAR = 'eponine-scan.jar';
115 if( ! defined $PROGRAMDIR ) {
116 $PROGRAMDIR = $ENV{'JAVA_HOME'} || $ENV{'JAVA_DIR'};
118 if (defined $PROGRAMDIR) {
119 foreach my $progname ( [qw(java)],[qw(bin java)] ) {
120 my $f = Bio::Root::IO->catfile($PROGRAMDIR, @$progname);
121 if( -e $f && -x $f ) {
122 $PROGRAM = $f;
123 last;
128 if( $ENV{'EPONINEDIR'} ) {
129 if ( -d $ENV{'EPONINEDIR'} ) {
130 $EPOJAR = Bio::Root::IO->catfile($ENV{'EPONINEDIR'}, $EPOJAR)
131 } elsif(-e $ENV{'EPONINEDIR'}) {
132 $EPOJAR = $ENV{'EPONINEDIR'};
134 if ( ! -e $EPOJAR) {
135 $EPOJAR =undef;
139 %EPONINE_PARAMS = ('SEQ' => '/tmp/test.fa',
140 'THRESHOLD' => '0.999',
141 'EPOJAR' => '/usr/local/bin/eponine-scan.jar',
142 'JAVA' => '/usr/java/jre1.3.1_02/bin/java');
144 @EPONINE_PARAMS=qw(SEQ THRESHOLD JAVA EPOJAR);
146 foreach my $attr ( @EPONINE_PARAMS)
147 { $OK_FIELD{$attr}++; }
150 sub AUTOLOAD {
151 my $self = shift;
152 my $attr = $AUTOLOAD;
153 $self->debug( "************ attr: $attr\n");
154 $attr =~ s/.*:://;
155 $attr = uc $attr;
156 $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
157 $self->{$attr} = shift if @_;
158 return $self->{$attr};
161 sub new {
162 my ($caller, @args) = @_;
163 # chained new
164 my $self = $caller->SUPER::new(@args);
165 # so that tempfiles are cleaned up
167 my $java;
168 my $seq;
169 my $threshold;
170 my $epojar;
172 my ($attr, $value);
173 ($TMPDIR) = $self->tempdir(CLEANUP=>1);
174 my $tfh;
175 ($tfh,$TMPOUTFILE) = $self->io->tempfile(-dir => $TMPDIR);
176 close($tfh);
177 undef $tfh;
178 while (@args) {
179 $attr = shift @args;
180 $value = shift @args;
181 next if( $attr =~ /^-/ ); # don't want named parameters
182 if ($attr =~/JAVA/i) {
183 $java = $value;
184 next;
186 if ($attr =~ /EPOJAR/i){
187 $epojar = $value;
188 next;
190 if ($attr =~ /THRESHOLD/i){
191 $threshold = $value;
192 next;
194 if ($attr =~ /SEQ/i){
195 $seq = $value;
196 next;
198 $self->$attr($value);
201 $self->{'_java'} = undef; # location of java vm
202 $self->{'_epojar'} = undef; # location of eponine-scan.jar executable JAR file.
203 $self->{'_threshold'} = 0.999; # minimum posterior for filtering predictions
204 $self->{'_filename'} = undef; #location of seq
205 $seq = $EPONINE_PARAMS{'seq'} unless defined $seq;
206 $threshold = $EPONINE_PARAMS{'threshold'} unless defined $threshold;
207 if (! defined $epojar && defined $EPOJAR) {
208 $epojar = $EPOJAR;
210 else {
211 $epojar = $EPONINE_PARAMS{'epojar'} unless defined $epojar;
213 if (! defined $java && defined $PROGRAM) {
214 $java = $PROGRAM;
216 else {
217 $java = $EPONINE_PARAMS{'JAVA'} unless defined $java;
219 $self->filename($seq) if ($seq);
221 if (-x $java) {
222 # full path assumed
223 $self->java($java);
226 $self->epojar($epojar) if (defined $epojar);
228 if (defined $threshold && $threshold >=0 ){
229 $self->threshold($threshold);
230 } else {
231 $self->threshold($DEFAULT_THRESHOLD);
234 return $self;
237 =head2 java
239 Title : java
240 Usage : $obj->java('/usr/opt/java130/bin/java');
241 Function: Get/set method for the location of java VM
242 Args : File path (optional)
244 =cut
246 sub executable { shift->java(@_); }
248 sub java {
249 my ($self, $exe,$warn) = @_;
251 if( defined $exe ) {
252 $self->{'_pathtojava'} = $exe;
255 unless( defined $self->{'_pathtojava'} ) {
256 if( $PROGRAM && -e $PROGRAM && -x $PROGRAM ) {
257 $self->{'_pathtojava'} = $PROGRAM;
258 } else {
259 my $exe;
260 if( ( $exe = $self->io->exists_exe($PROGRAMNAME) ) &&
261 -x $exe ) {
262 $self->{'_pathtojava'} = $exe;
263 } else {
264 $self->warn("Cannot find executable for $PROGRAMNAME") if $warn;
265 $self->{'_pathtojava'} = undef;
269 $self->{'_pathtojava'};
273 =head2 epojar
275 Title : epojar
276 Usage : $obj->epojar('/some/path/to/eponine-scan.jar');
277 Function: Get/set method for the location of the eponine-scan executable JAR
278 Args : Path (optional)
280 =cut
282 sub epojar {
283 my ($self, $location) = @_;
284 if ($location)
286 unless( $location ) {
287 $self->warn("eponine-scan.jar not found at $location: $!\n");
288 return;
290 $self->{'_epojar'} = $location ;
292 return $self->{'_epojar'};
297 =head2 threshold
299 Title : threshold
300 Usage : my $threshold = $self->threshold
301 Function: Get/Set the threshold for Eponine
302 Returns : string
303 Args : b/w 0.9 and 1.0
305 =cut
307 sub threshold{
308 my ($self, $threshold) = @_;
309 if (defined $threshold) {
310 $self->{'_threshold'} = $threshold ;
312 return $self->{'_threshold'};
317 =head2 run
319 Title : run
320 Usage : my @genes = $self->run($seq)
321 Function: runs Eponine and creates an array of features
322 Returns : An Array of SeqFeatures
323 Args : A Bio::PrimarySeqI
325 =cut
327 sub run{
328 my ($self,$seq) = @_;
329 my $infile = $self->_setinput($seq);
330 my @tss = $self->_run_eponine($infile);
331 return @tss;
335 =head2 predict_TSS
337 Title : predict_TSS
338 Usage : Alias for run()
340 =cut
342 sub predict_TSS {
343 return shift->run(@_);
346 =head2 _setinput()
348 Title : _setinput
349 Usage : Internal function, not to be called directly
350 Function: writes input sequence to file and return the file name
351 Example :
352 Returns : string
353 Args :
355 =cut
357 sub _setinput {
358 my ($self,$seq) = @_;
359 #better be a file
360 if(!ref $seq){
361 return $seq;
363 my ($tfh1,$inputfile) = $self->tempfile(-dir=>$TMPDIR);
364 my $in = Bio::SeqIO->new(-fh=> $tfh1 , '-format' => 'Fasta');
365 $in->write_seq($seq);
366 close($tfh1);
367 undef $tfh1;
368 return ($inputfile);
371 =head2 _run_eponine
373 Title : run_eponine
374 Usage : $obj->_run_eponine()
375 Function: execs the Java VM to run eponine
376 Returns : none
377 Args : none
379 =cut
381 sub _run_eponine {
382 my ($self,$infile) = @_;
383 my $result = $TMPOUTFILE;
384 my @tss;
385 #run eponine
386 $self->debug( "Running eponine-scan\n");
387 my ($java,$epojar) = ( $self->java,
388 $self->epojar);
389 unless( defined $java && -e $java && -x $java ) {
390 $self->warn("Cannot find java");
391 return;
393 if (! defined $epojar) { $self->warn("Don't know the name of the Eponine jar file"); return; }
394 if (! -e $epojar) {
395 $self->warn("Cannot find Eponine jar: $epojar - either you specified an incorrect path in\nEPONINEDIR or it was not in the current working directory");
396 return;
398 my $cmd = $self->java.' -jar '.$self->epojar.' -seq '.$infile.' -threshold '.$self->threshold." > ".$result;
399 $self->throw("Error running eponine-scan on ".$self->filename.
400 " \n Check your java version, it has to be version 1.2 or later. Eponine crashed ($cmd) crashed: $? \n")
401 if (system ($cmd));
403 #parse results even though it's wierd.. thought parser and wrapper should be separate
404 my $epoParser = Bio::Tools::Eponine->new(-file =>$result);
406 while (my $tss = $epoParser->next_prediction()){
407 push (@tss, $tss);
409 return @tss;
413 __END__