my $runnable = Bio::EnsEMBL::Analysis::Runnable::Funcgen::ACME->new
(
-analysis => $analysis,
-query => 'slice',
-program => 'program.pl',
);
$runnable->run;
my @features = @{$runnable->output};
ACME expects to run the R program ACME (Scacherie et al. (2006), PMID:
16939795) and predicts features which can be stored in the annotated_feature
table in the eFG database
sub run_analysis
{
my ($self, $program) = @_;
if(!$program){
$program = $self->program;
}
throw($program." is not executable ACME::run_analysis ")
unless($program && -x $program);
my $command = $self->program . ' --no-save --slave < ' . $self->infile;
warn("Running analysis " . $command . "\n");
eval { system($command) };
throw("FAILED to run $command: ", $@) if ($@);
}
} |
sub write_infile
{
my ($self, $filename) = @_;
if (! $filename) {
$filename = $self->infile();
}
warn("filename: ", $filename);
my $noa = scalar(keys %{$self->result_features});
warn ("Processing $noa replicates. Resulting annotated features will be\n ".
"linked all together to the same features set". $noa) if ($noa > 1) ;
my $workdir = $self->workdir.'/'.$self->analysis->module();
warn($workdir);
my @fnames=();
foreach my $rset_name (keys %{$self->result_features}) {
(my $fname = $filename) =~ s,^.+/(.+)\.dat,$1_${rset_name}.dat,;
warn("fname: ", $fname);
push (@fnames, $fname);
open(F, ">$workdir/$fname")
or throw("Can't open file $filename.");
foreach my $ft (@{${$self->result_features}{$rset_name}}) {
printf F "%s\t%s\t%s\t%d\t%d\t%f\t.\t.\t.\n",
$ft->[0], $ENV{NORM_METHOD}, $rset_name, $ft->[1], $ft->[2], $ft->[3];
}
close F;
}
warn("fnames: ", @fnames);
(my $Rfile = $filename) =~ s/\.dat/.R/;
$self->infile($Rfile);
(my $resultsfile = $filename) =~ s/\.dat/.regions/;
$self->resultsfile($resultsfile);
(my $PDFfile = $filename) =~ s/\.dat/.pdf/;
my $fnames = join('", "', @fnames);
my $param = $self->get_parameters();
my $window = $param->{WINDOW};
my $threshold = $param->{THRESHOLD};
my $pvalue = $param->{PVALUE};
open(R, ">".$Rfile)
or throw("Can't open file $Rfile.");
print R <<EOR;
library("ACME") setwd("$workdir") fnames <- c("$fnames") a <- read.resultsGFF(fnames) colnames(a\@data) <- fnames #str(a) aGFFCalc <- do.aGFF.calc(a, window = $window, thresh = $threshold) regions <- findRegions(aGFFCalc,thresh=$pvalue) write.table(regions[regions\$TF,c('Chromosome', 'Start', 'End', 'Mean', 'Median')], file="$resultsfile", sep="\\t", row.names = FALSE, col.names = FALSE)
EOR
close R;
my @fields = (0..3); $self->output_fields(\@fields); } |