File Coverage

blib/lib/Bio/Tools/Run/Eponine.pm
Criterion Covered Total %
statement 29 153 18.9
branch 3 74 4.0
condition 1 30 3.3
subroutine 7 17 41.1
pod 7 7 100.0
total 47 281 16.7


line stmt bran cond sub pod time code
1             #
2             # Please direct questions and support issues to
3             #
4             # Cared for by Tania Oh
5             #
6             # Copyright Tania Oh
7             #
8             # You may distribute this module under the same terms as perl itself
9              
10             # POD documentation - main docs before the code
11              
12             =head1 NAME
13              
14             Bio::Tools::Run::Eponine - Object for execution of the Eponine which
15             is a mammalian TSS predictor
16              
17             =head1 SYNOPSIS
18              
19             use Bio::Tools::Run::Eponine;
20             use strict;
21             my $seq = "/data/seq.fa";
22             my $threshold = "0.999";
23             my @params = ( '-seq' => $seq,
24             '-threshold' => $threshold,
25             '-epojar' => '/usr/local/bin/eponine-scan.jar',
26             '-java' => '/usr/local/bin/java');
27              
28             my $factory = Bio::Tools::Run::Eponine->new(@params);
29             # run eponine against fasta
30             my $r = $factory->run($seq);
31             my $parser = Bio::Tools::Eponine->new($r);
32              
33             while (my $feat = $parser->next_prediction){
34             #$feat contains array of SeqFeature
35             foreach my $orf($feat){
36             print $orf->seqname. "\n";
37             }
38             }
39              
40             # Various additional options and input formats are available. See
41             # the DESCRIPTION section for details.
42              
43             =head1 DESCRIPTION
44              
45             wrapper for eponine, a mammalian TSS predictor.
46              
47             The environment variable EPONINEDIR must be set to point at either the
48             directory which contains eponine-scan.jar or directly at the jar which
49             eponine-scan classfiles. NOTE: EPONINEDIR must point at the real file
50             not a symlink.
51              
52             =head1 FEEDBACK
53              
54             =head2 Mailing Lists
55              
56             User feedback is an integral part of the evolution of this and other
57             Bioperl modules. Send your comments and suggestions preferably to one
58             of the Bioperl mailing lists. Your participation is much appreciated.
59              
60             bioperl-l@bioperl.org - General discussion
61             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
62              
63             =head2 Support
64              
65             Please direct usage questions or support issues to the mailing list:
66              
67             I
68              
69             rather than to the module maintainer directly. Many experienced and
70             reponsive experts will be able look at the problem and quickly
71             address it. Please include a thorough description of the problem
72             with code and data examples if at all possible.
73              
74             =head2 Reporting Bugs
75              
76             Report bugs to the Bioperl bug tracking system to help us keep track
77             the bugs and their resolution. Bug reports can be submitted via the
78             web:
79              
80             http://redmine.open-bio.org/projects/bioperl/
81              
82             =head1 AUTHOR
83              
84             Email gisoht@nus.edu.sg
85              
86             =head1 APPENDIX
87              
88             The rest of the documentation details each of the object
89             methods. Internal methods are usually preceded with a _
90              
91             =cut
92              
93             package Bio::Tools::Run::Eponine;
94              
95             #tgot to take inmore parameters
96              
97 1         146 use vars qw($AUTOLOAD @ISA @EPONINE_PARAMS %EPONINE_PARAMS
98             $EPOJAR $JAVA $PROGRAMDIR $PROGRAMNAME $PROGRAM
99             $TMPDIR $TMPOUTFILE $DEFAULT_THRESHOLD
100 1     1   116843 %OK_FIELD);
  1         2  
101 1     1   7 use strict;
  1         2  
  1         31  
102              
103 1     1   652 use Bio::Tools::Eponine;
  1         93125  
  1         25  
104 1     1   6 use Bio::Root::Root;
  1         1  
  1         15  
105 1     1   3 use Bio::Root::IO;
  1         1  
  1         14  
106 1     1   405 use Bio::Tools::Run::WrapperBase;
  1         1  
  1         241  
107             @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
108              
109             BEGIN {
110 1     1   3 $DEFAULT_THRESHOLD = 50;
111 1         1 $PROGRAMNAME = 'java';
112 1         2 $EPOJAR = 'eponine-scan.jar';
113              
114 1 50       5 if( ! defined $PROGRAMDIR ) {
115 1   33     5 $PROGRAMDIR = $ENV{'JAVA_HOME'} || $ENV{'JAVA_DIR'};
116             }
117 1 50       5 if (defined $PROGRAMDIR) {
118 0         0 foreach my $progname ( [qw(java)],[qw(bin java)] ) {
119 0         0 my $f = Bio::Root::IO->catfile($PROGRAMDIR, @$progname);
120 0 0 0     0 if( -e $f && -x $f ) {
121 0         0 $PROGRAM = $f;
122 0         0 last;
123             }
124             }
125             }
126              
127 1 50       4 if( $ENV{'EPONINEDIR'} ) {
128 0 0       0 if ( -d $ENV{'EPONINEDIR'} ) {
    0          
129 0         0 $EPOJAR = Bio::Root::IO->catfile($ENV{'EPONINEDIR'}, $EPOJAR)
130             } elsif(-e $ENV{'EPONINEDIR'}) {
131 0         0 $EPOJAR = $ENV{'EPONINEDIR'};
132             }
133 0 0       0 if ( ! -e $EPOJAR) {
134 0         0 $EPOJAR =undef;
135             }
136             }
137              
138 1         5 %EPONINE_PARAMS = ('SEQ' => '/tmp/test.fa',
139             'THRESHOLD' => '0.999',
140             'EPOJAR' => '/usr/local/bin/eponine-scan.jar',
141             'JAVA' => '/usr/java/jre1.3.1_02/bin/java');
142              
143 1         3 @EPONINE_PARAMS=qw(SEQ THRESHOLD JAVA EPOJAR);
144              
145 1         2 foreach my $attr ( @EPONINE_PARAMS)
146 4         1079 { $OK_FIELD{$attr}++; }
147             }
148              
149             sub AUTOLOAD {
150 0     0     my $self = shift;
151 0           my $attr = $AUTOLOAD;
152 0           $self->debug( "************ attr: $attr\n");
153 0           $attr =~ s/.*:://;
154 0           $attr = uc $attr;
155 0 0         $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
156 0 0         $self->{$attr} = shift if @_;
157 0           return $self->{$attr};
158             }
159              
160             sub new {
161 0     0 1   my ($caller, @args) = @_;
162             # chained new
163 0           my $self = $caller->SUPER::new(@args);
164             # so that tempfiles are cleaned up
165              
166 0           my $java;
167             my $seq;
168 0           my $threshold;
169 0           my $epojar;
170              
171 0           my ($attr, $value);
172 0           ($TMPDIR) = $self->tempdir(CLEANUP=>1);
173 0           my $tfh;
174 0           ($tfh,$TMPOUTFILE) = $self->io->tempfile(-dir => $TMPDIR);
175 0           close($tfh);
176 0           undef $tfh;
177 0           while (@args) {
178 0           $attr = shift @args;
179 0           $value = shift @args;
180 0 0         next if( $attr =~ /^-/ ); # don't want named parameters
181 0 0         if ($attr =~/JAVA/i) {
182 0           $java = $value;
183 0           next;
184             }
185 0 0         if ($attr =~ /EPOJAR/i){
186 0           $epojar = $value;
187 0           next;
188             }
189 0 0         if ($attr =~ /THRESHOLD/i){
190 0           $threshold = $value;
191 0           next;
192             }
193 0 0         if ($attr =~ /SEQ/i){
194 0           $seq = $value;
195 0           next;
196             }
197 0           $self->$attr($value);
198             }
199              
200 0           $self->{'_java'} = undef; # location of java vm
201 0           $self->{'_epojar'} = undef; # location of eponine-scan.jar executable JAR file.
202 0           $self->{'_threshold'} = 0.999; # minimum posterior for filtering predictions
203 0           $self->{'_filename'} = undef; #location of seq
204 0 0         $seq = $EPONINE_PARAMS{'seq'} unless defined $seq;
205 0 0         $threshold = $EPONINE_PARAMS{'threshold'} unless defined $threshold;
206 0 0 0       if (! defined $epojar && defined $EPOJAR) {
207 0           $epojar = $EPOJAR;
208             }
209             else {
210 0 0         $epojar = $EPONINE_PARAMS{'epojar'} unless defined $epojar;
211             }
212 0 0 0       if (! defined $java && defined $PROGRAM) {
213 0           $java = $PROGRAM;
214             }
215             else {
216 0 0         $java = $EPONINE_PARAMS{'JAVA'} unless defined $java;
217             }
218 0 0         $self->filename($seq) if ($seq);
219              
220 0 0         if (-x $java) {
221             # full path assumed
222 0           $self->java($java);
223             }
224            
225 0 0         $self->epojar($epojar) if (defined $epojar);
226            
227 0 0 0       if (defined $threshold && $threshold >=0 ){
228 0           $self->threshold($threshold);
229             } else {
230 0           $self->threshold($DEFAULT_THRESHOLD);
231             }
232            
233 0           return $self;
234             }
235              
236             =head2 java
237              
238             Title : java
239             Usage : $obj->java('/usr/opt/java130/bin/java');
240             Function: Get/set method for the location of java VM
241             Args : File path (optional)
242              
243             =cut
244              
245 0     0 1   sub executable { shift->java(@_); }
246              
247             sub java {
248 0     0 1   my ($self, $exe,$warn) = @_;
249              
250 0 0         if( defined $exe ) {
251 0           $self->{'_pathtojava'} = $exe;
252             }
253              
254 0 0         unless( defined $self->{'_pathtojava'} ) {
255 0 0 0       if( $PROGRAM && -e $PROGRAM && -x $PROGRAM ) {
      0        
256 0           $self->{'_pathtojava'} = $PROGRAM;
257             } else {
258 0           my $exe;
259 0 0 0       if( ( $exe = $self->io->exists_exe($PROGRAMNAME) ) &&
260             -x $exe ) {
261 0           $self->{'_pathtojava'} = $exe;
262             } else {
263 0 0         $self->warn("Cannot find executable for $PROGRAMNAME") if $warn;
264 0           $self->{'_pathtojava'} = undef;
265             }
266             }
267             }
268 0           $self->{'_pathtojava'};
269             }
270              
271              
272             =head2 epojar
273              
274             Title : epojar
275             Usage : $obj->epojar('/some/path/to/eponine-scan.jar');
276             Function: Get/set method for the location of the eponine-scan executable JAR
277             Args : Path (optional)
278              
279             =cut
280              
281             sub epojar {
282 0     0 1   my ($self, $location) = @_;
283 0 0         if ($location)
284             {
285 0 0         unless( $location ) {
286 0           $self->warn("eponine-scan.jar not found at $location: $!\n");
287 0           return;
288             }
289 0           $self->{'_epojar'} = $location ;
290             }
291 0           return $self->{'_epojar'};
292             }
293              
294              
295              
296             =head2 threshold
297              
298             Title : threshold
299             Usage : my $threshold = $self->threshold
300             Function: Get/Set the threshold for Eponine
301             Returns : string
302             Args : b/w 0.9 and 1.0
303              
304             =cut
305              
306             sub threshold{
307 0     0 1   my ($self, $threshold) = @_;
308 0 0         if (defined $threshold) {
309 0           $self->{'_threshold'} = $threshold ;
310             }
311 0           return $self->{'_threshold'};
312              
313             }
314              
315              
316             =head2 run
317              
318             Title : run
319             Usage : my @genes = $self->run($seq)
320             Function: runs Eponine and creates an array of features
321             Returns : An Array of SeqFeatures
322             Args : A Bio::PrimarySeqI
323              
324             =cut
325              
326             sub run{
327 0     0 1   my ($self,$seq) = @_;
328 0           my $infile = $self->_setinput($seq);
329 0           my @tss = $self->_run_eponine($infile);
330 0           return @tss;
331              
332             }
333              
334             =head2 predict_TSS
335              
336             Title : predict_TSS
337             Usage : Alias for run()
338              
339             =cut
340              
341             sub predict_TSS {
342 0     0 1   return shift->run(@_);
343             }
344              
345             =head2 _setinput()
346              
347             Title : _setinput
348             Usage : Internal function, not to be called directly
349             Function: writes input sequence to file and return the file name
350             Example :
351             Returns : string
352             Args :
353              
354             =cut
355              
356             sub _setinput {
357 0     0     my ($self,$seq) = @_;
358             #better be a file
359 0 0         if(!ref $seq){
360 0           return $seq;
361             }
362 0           my ($tfh1,$inputfile) = $self->tempfile(-dir=>$TMPDIR);
363 0           my $in = Bio::SeqIO->new(-fh=> $tfh1 , '-format' => 'Fasta');
364 0           $in->write_seq($seq);
365 0           close($tfh1);
366 0           undef $tfh1;
367 0           return ($inputfile);
368             }
369              
370             =head2 _run_eponine
371              
372             Title : run_eponine
373             Usage : $obj->_run_eponine()
374             Function: execs the Java VM to run eponine
375             Returns : none
376             Args : none
377              
378             =cut
379              
380             sub _run_eponine {
381 0     0     my ($self,$infile) = @_;
382 0           my $result = $TMPOUTFILE;
383 0           my @tss;
384             #run eponine
385 0           $self->debug( "Running eponine-scan\n");
386 0           my ($java,$epojar) = ( $self->java,
387             $self->epojar);
388 0 0 0       unless( defined $java && -e $java && -x $java ) {
      0        
389 0           $self->warn("Cannot find java");
390 0           return;
391             }
392 0 0         if (! defined $epojar) { $self->warn("Don't know the name of the Eponine jar file"); return; }
  0            
  0            
393 0 0         if (! -e $epojar) {
394 0           $self->warn("Cannot find Eponine jar: $epojar - either you specified an incorrect path in\nEPONINEDIR or it was not in the current working directory");
395 0           return;
396             }
397 0           my $cmd = $self->java.' -jar '.$self->epojar.' -seq '.$infile.' -threshold '.$self->threshold." > ".$result;
398 0 0         $self->throw("Error running eponine-scan on ".$self->filename.
399             " \n Check your java version, it has to be version 1.2 or later. Eponine crashed ($cmd) crashed: $? \n")
400             if (system ($cmd));
401            
402             #parse results even though it's wierd.. thought parser and wrapper should be separate
403 0           my $epoParser = Bio::Tools::Eponine->new(-file =>$result);
404            
405 0           while (my $tss = $epoParser->next_prediction()){
406 0           push (@tss, $tss);
407             }
408 0           return @tss;
409             }
410              
411             1;
412             __END__