my $runnable = Bio::EnsEMBL::Analysis::Runnable::Funcgen::Chipotle->new
(
-analysis => $analysis,
-query => 'slice',
-program => 'program.pl',
);
$runnable->run;
my @annotated_features = @{$runnable->output};
sub run_analysis
{
print "Analysis::Runnable::Funcgen::Chipotle::run_analysis\n";
my ($self, $program) = @_;
if(!$program){
$program = $self->program;
}
throw($program." is not executable Chipotle::run_analysis ")
unless($program && -x $program);
my $param = $self->get_parameters();
(my $resultsfile = $self->infile) =~ s/\.dat$/.peaks/;
$self->resultsfile($resultsfile);
$self->files_to_delete($resultsfile);
my @fields = (0..3);
$self->output_fields(\@fields);
my $command = join(' ', $self->program, 'get_peaks', '0', '0',
$self->infile(), $self->resultsfile(),
$param->{alpha}, $param->{stepSize},
$param->{windowSize}, $param->{adjustPvalue}, 'NORM');
warn("Running analysis " . $command . "\n");
eval { system($command) };
throw("FAILED to run $command: ", $@) if ($@);
} |
sub write_infile
{
my ($self, $filename) = @_;
print "Analysis::Runnable::Funcgen::Chipotle::write_infile\n";
if (! $filename) {
$filename = $self->infile();
}
my $replicates = scalar(keys %{$self->result_features});
if ($replicates > 1) {
my @tmpfiles = ();
foreach my $rset (sort keys %{$self->result_features}) {
my $i = 1;
(my $tmpfile = $self->infile) =~ s/\.dat$/.$rset.dat/;
print Dumper $tmpfile;
open(DAT, ">$tmpfile")
or throw ("Can't open file $tmpfile");
map {
printf DAT "%d\t%s\t%d\t%d\t%f\n",
$i++, (@$_)[0..3];
} @{$self->result_features->{$rset}};
close DAT
or throw ("Can't close file $tmpfile");
push(@tmpfiles, $tmpfile);
}
my $command = join(' ', $self->program, 'merge_files', '0',
$replicates, @tmpfiles, $filename);
warn("Merging infiles " . $command . "\n");
eval { system($command) };
throw("FAILED to run $command: ", $@) if ($@);
map {$self->files_to_delete($_)} @tmpfiles;
} else {
open(F, ">".$filename)
or throw("Can't open file $filename.");
foreach (values %{$self->result_features}) {
foreach my $ft (@$_) {
print F join("\t", (@$ft)[4,0..3]), "\n";
}
}
close F;
}
return $filename;
}
1; } |