Hide Show 81 lines of Pod
use
vars
qw($AUTOLOAD @ISA @EPONINE_PARAMS %EPONINE_PARAMS
$EPOJAR $JAVA $PROGRAMDIR $PROGRAMNAME $PROGRAM
$TMPDIR $TMPOUTFILE $DEFAULT_THRESHOLD
%OK_FIELD)
;
@ISA
=
qw(Bio::Root::Root Bio::Tools::Run::WrapperBase)
;
BEGIN {
$DEFAULT_THRESHOLD
= 50;
$PROGRAMNAME
=
'java'
;
$EPOJAR
=
'eponine-scan.jar'
;
if
( !
defined
$PROGRAMDIR
) {
$PROGRAMDIR
=
$ENV
{
'JAVA_HOME'
} ||
$ENV
{
'JAVA_DIR'
};
}
if
(
defined
$PROGRAMDIR
) {
foreach
my
$progname
( [
qw(java)
],[
qw(bin java)
] ) {
my
$f
= Bio::Root::IO->catfile(
$PROGRAMDIR
,
@$progname
);
if
( -e
$f
&& -x
$f
) {
$PROGRAM
=
$f
;
last
;
}
}
}
if
(
$ENV
{
'EPONINEDIR'
} ) {
if
( -d
$ENV
{
'EPONINEDIR'
} ) {
$EPOJAR
= Bio::Root::IO->catfile(
$ENV
{
'EPONINEDIR'
},
$EPOJAR
)
}
elsif
(-e
$ENV
{
'EPONINEDIR'
}) {
$EPOJAR
=
$ENV
{
'EPONINEDIR'
};
}
if
( ! -e
$EPOJAR
) {
$EPOJAR
=
undef
;
}
}
%EPONINE_PARAMS
= (
'SEQ'
=>
'/tmp/test.fa'
,
'THRESHOLD'
=>
'0.999'
,
'EPOJAR'
=>
'/usr/local/bin/eponine-scan.jar'
,
'JAVA'
=>
'/usr/java/jre1.3.1_02/bin/java'
);
@EPONINE_PARAMS
=
qw(SEQ THRESHOLD JAVA EPOJAR)
;
foreach
my
$attr
(
@EPONINE_PARAMS
)
{
$OK_FIELD
{
$attr
}++; }
}
sub
AUTOLOAD {
my
$self
=
shift
;
my
$attr
=
$AUTOLOAD
;
$self
->debug(
"************ attr: $attr\n"
);
$attr
=~ s/.*:://;
$attr
=
uc
$attr
;
$self
->throw(
"Unallowed parameter: $attr !"
)
unless
$OK_FIELD
{
$attr
};
$self
->{
$attr
} =
shift
if
@_
;
return
$self
->{
$attr
};
}
sub
new {
my
(
$caller
,
@args
) =
@_
;
my
$self
=
$caller
->SUPER::new(
@args
);
my
$java
;
my
$seq
;
my
$threshold
;
my
$epojar
;
my
(
$attr
,
$value
);
(
$TMPDIR
) =
$self
->tempdir(
CLEANUP
=>1);
my
$tfh
;
(
$tfh
,
$TMPOUTFILE
) =
$self
->io->tempfile(
-dir
=>
$TMPDIR
);
close
(
$tfh
);
undef
$tfh
;
while
(
@args
) {
$attr
=
shift
@args
;
$value
=
shift
@args
;
next
if
(
$attr
=~ /^-/ );
if
(
$attr
=~/JAVA/i) {
$java
=
$value
;
next
;
}
if
(
$attr
=~ /EPOJAR/i){
$epojar
=
$value
;
next
;
}
if
(
$attr
=~ /THRESHOLD/i){
$threshold
=
$value
;
next
;
}
if
(
$attr
=~ /SEQ/i){
$seq
=
$value
;
next
;
}
$self
->
$attr
(
$value
);
}
$self
->{
'_java'
} =
undef
;
$self
->{
'_epojar'
} =
undef
;
$self
->{
'_threshold'
} = 0.999;
$self
->{
'_filename'
} =
undef
;
$seq
=
$EPONINE_PARAMS
{
'seq'
}
unless
defined
$seq
;
$threshold
=
$EPONINE_PARAMS
{
'threshold'
}
unless
defined
$threshold
;
if
(!
defined
$epojar
&&
defined
$EPOJAR
) {
$epojar
=
$EPOJAR
;
}
else
{
$epojar
=
$EPONINE_PARAMS
{
'epojar'
}
unless
defined
$epojar
;
}
if
(!
defined
$java
&&
defined
$PROGRAM
) {
$java
=
$PROGRAM
;
}
else
{
$java
=
$EPONINE_PARAMS
{
'JAVA'
}
unless
defined
$java
;
}
$self
->filename(
$seq
)
if
(
$seq
);
if
(-x
$java
) {
$self
->java(
$java
);
}
$self
->epojar(
$epojar
)
if
(
defined
$epojar
);
if
(
defined
$threshold
&&
$threshold
>=0 ){
$self
->threshold(
$threshold
);
}
else
{
$self
->threshold(
$DEFAULT_THRESHOLD
);
}
return
$self
;
}
Hide Show 9 lines of Pod
sub
executable {
shift
->java(
@_
); }
sub
java {
my
(
$self
,
$exe
,
$warn
) =
@_
;
if
(
defined
$exe
) {
$self
->{
'_pathtojava'
} =
$exe
;
}
unless
(
defined
$self
->{
'_pathtojava'
} ) {
if
(
$PROGRAM
&& -e
$PROGRAM
&& -x
$PROGRAM
) {
$self
->{
'_pathtojava'
} =
$PROGRAM
;
}
else
{
my
$exe
;
if
( (
$exe
=
$self
->io->exists_exe(
$PROGRAMNAME
) ) &&
-x
$exe
) {
$self
->{
'_pathtojava'
} =
$exe
;
}
else
{
$self
->
warn
(
"Cannot find executable for $PROGRAMNAME"
)
if
$warn
;
$self
->{
'_pathtojava'
} =
undef
;
}
}
}
$self
->{
'_pathtojava'
};
}
Hide Show 9 lines of Pod
sub
epojar {
my
(
$self
,
$location
) =
@_
;
if
(
$location
)
{
unless
(
$location
) {
$self
->
warn
(
"eponine-scan.jar not found at $location: $!\n"
);
return
;
}
$self
->{
'_epojar'
} =
$location
;
}
return
$self
->{
'_epojar'
};
}
Hide Show 10 lines of Pod
sub
threshold{
my
(
$self
,
$threshold
) =
@_
;
if
(
defined
$threshold
) {
$self
->{
'_threshold'
} =
$threshold
;
}
return
$self
->{
'_threshold'
};
}
Hide Show 10 lines of Pod
sub
run{
my
(
$self
,
$seq
) =
@_
;
my
$infile
=
$self
->_setinput(
$seq
);
my
@tss
=
$self
->_run_eponine(
$infile
);
return
@tss
;
}
Hide Show 7 lines of Pod
sub
predict_TSS {
return
shift
->run(
@_
);
}
Hide Show 11 lines of Pod
sub
_setinput {
my
(
$self
,
$seq
) =
@_
;
if
(!
ref
$seq
){
return
$seq
;
}
my
(
$tfh1
,
$inputfile
) =
$self
->tempfile(
-dir
=>
$TMPDIR
);
my
$in
= Bio::SeqIO->new(
-fh
=>
$tfh1
,
'-format'
=>
'Fasta'
);
$in
->write_seq(
$seq
);
close
(
$tfh1
);
undef
$tfh1
;
return
(
$inputfile
);
}
Hide Show 10 lines of Pod
sub
_run_eponine {
my
(
$self
,
$infile
) =
@_
;
my
$result
=
$TMPOUTFILE
;
my
@tss
;
$self
->debug(
"Running eponine-scan\n"
);
my
(
$java
,
$epojar
) = (
$self
->java,
$self
->epojar);
unless
(
defined
$java
&& -e
$java
&& -x
$java
) {
$self
->
warn
(
"Cannot find java"
);
return
;
}
if
(!
defined
$epojar
) {
$self
->
warn
(
"Don't know the name of the Eponine jar file"
);
return
; }
if
(! -e
$epojar
) {
$self
->
warn
(
"Cannot find Eponine jar: $epojar - either you specified an incorrect path in\nEPONINEDIR or it was not in the current working directory"
);
return
;
}
my
$cmd
=
$self
->java.
' -jar '
.
$self
->epojar.
' -seq '
.
$infile
.
' -threshold '
.
$self
->threshold.
" > "
.
$result
;
$self
->throw(
"Error running eponine-scan on "
.
$self
->filename.
" \n Check your java version, it has to be version 1.2 or later. Eponine crashed ($cmd) crashed: $? \n"
)
if
(
system
(
$cmd
));
my
$epoParser
= Bio::Tools::Eponine->new(
-file
=>
$result
);
while
(
my
$tss
=
$epoParser
->next_prediction()){
push
(
@tss
,
$tss
);
}
return
@tss
;
}
1;