Bio::EnsEMBL::Analysis::Runnable::Funcgen Splitter
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
Bio::EnsEMBL::Analysis::Runnable::Funcgen::Splitter
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::Analysis::Runnable
Bio::EnsEMBL::Analysis::Runnable::Funcgen
Bio::EnsEMBL::Utils::Argument qw ( rearrange )
Bio::EnsEMBL::Utils::Exception qw ( throw warning )
Data::Dumper
Inherit
Bio::EnsEMBL::Analysis::Runnable::Funcgen
Synopsis
  my $runnable = Bio::EnsEMBL::Analysis::Runnable::Funcgen::Splitter->new
(
-analysis => $analysis,
-query => 'slice',
-program => 'program.pl',
);
$runnable->run;
my @features = @{$runnable->output};
Description
Splitter expects to run the command line version of the Splitter program
(http://zlab.bu.edu/splitter) and predicts features which can be stored in
the annotated_feature table in the eFG database
Methods
infileDescriptionCode
parse_resultsDescriptionCode
run_analysisDescriptionCode
write_infileDescriptionCode
Methods description
infilecode    nextTop
  Arg [1]     : Bio::EnsEMBL::Analysis::Runnable::Splitter
Arg [2] : filename (string)
Description : will hold a given filename or if one is requested but none
defined it will use the create_filename method to create a filename
Returntype : string, filename
Exceptions : none
Example :
parse_resultscodeprevnextTop
  Arg [1]     : Bio::EnsEMBL::Analysis::Runnable::Chipotle
Arg [2] : filename (string)
Decription : open and parse resultsfile
Returntype : none
Exceptions : throws
Example :
run_analysiscodeprevnextTop
  Arg [1]     : Bio::EnsEMBL::Analysis::Runnable::Splitter
Arg [2] : string, program name
Usage :
Description :
Returns :
Exceptions :
write_infilecodeprevnextTop
    Arg [1]     : Bio::EnsEMBL::Analysis::Runnable::Splitter
Arg [2] : filename
Description :
Returntype :
Exceptions :
Example :
Methods code
infiledescriptionprevnextTop
sub infile {
  my ($self, $filename) = @_;

  if($filename){
    $self->{'infile'} = $filename;
  }
  if(!$self->{'infile'}){
    $self->{'infile'} = $self->create_filename($self->analysis->logic_name, 'dat');
  }

  return $self->{'infile'};
}
parse_resultsdescriptionprevnextTop
sub parse_results {
  my ($self, $resultsfile) = @_;

  if (! defined $resultsfile) {
      $resultsfile = $self->resultsfile;
  }
  throw ('No resultsfile defined in instance!')
      if(! defined $resultsfile);

  throw("parse_results: results file ".$resultsfile." does not exist.")
      if (! -e $resultsfile);
  
  throw("parse_results: can't open file ".$resultsfile.": ". $!)
      unless (open(F, $resultsfile));

  my @output = ();

  while (<F>) {

	  next unless (s/^chr//);
	  
      chomp;
      my @ft = split;
	  my $coord = shift(@ft);
	  my @coord = split(/[:-]/, $coord);
      push(@output, [ @coord, $ft[0] ]);

  }

  throw("No features to annotate  on slice ".$self->query->seq_region_name."!") if (scalar(@output) == 0);

  $self->output(\@output);
  #print Dumper $self->output();
throw("parse_results: can't close file ".$resultsfile.".") unless (close(F)); } 1;
}
run_analysisdescriptionprevnextTop
sub run_analysis {
        
    my ($self, $program) = @_;
    
    if(!$program){
        $program = $self->program;
    }
    throw($program." is not executable Splitter::run_analysis ") 
        unless($program && -x $program);

	(my $id = $self->workdir) =~ s,^.+/,,;

    my $command = $self->program."\' id=$id\'\' submit=One shot\'\' signalfile=".$self->infile."\' " .
		$self->analysis->parameters;
    
    warn("Running analysis " . $command . "\n");
    
    eval { system( $command ) };
    throw("FAILED to run $command: ", $@) if ($@);

	opendir(DIR, $self->workdir())
		or throw("Can't open workdir ".$self->workdir());
	my @resultfiles = grep { /\.scored\.txt$/ } readdir DIR;
	closedir(DIR);

	throw("More than one resultfile in ".$self->workdir()) 
		if (scalar(@resultfiles) > 1);

	# set resultsfile
$self->resultsfile($self->workdir.'/'.$resultfiles[0]);
}
write_infiledescriptionprevnextTop
sub write_infile {
	
	my ($self, $filename) = @_;

	if (! $filename) {
		$filename = $self->infile();
	}

	# everything needs to happen in a particular subdirectory of the workdir,
# filenames are set by the Splitter program
(my $workdir = $filename) =~ s/\.dat$//; eval { system("mkdir -p $workdir") }; throw ("Couldn't create directory $workdir: $@") if ($@); $self->workdir($workdir); $filename =~ s,.+/,,; # determine both number of result sets (replicates) and features
my $noa = scalar(keys %{$self->result_features}); warn('no. of result sets: ', $noa); my $nof = scalar(@{(values %{$self->result_features})[0]}); warn('no. of result fts: ', $nof); # dump features
open(F, "> $workdir/$filename") or throw("Can't open file $workdir/$filename."); #print Dumper $self->result_features;
for (my $i=0; $i<$nof; $i++) { my $coord=0; foreach my $rset (values %{$self->result_features}) { printf F "chr%s\t%d\t%d\t", ${$rset}[$i][0], ${$rset}[$i][1], ${$rset}[$i][2] unless ($coord); $coord=1; print F "\t".${$rset}[$i][3]; } print F "\n"; } close F; $self->infile($workdir.'/'.$filename); return "$workdir/$filename";
}
General documentation
LICENCETop
This code is distributed under an Apache style licence. Please see
/info/about/code_licence.html for details.
AUTHORTop
Stefan Graf, Ensembl Functional Genomics -
CONTACTTop
Post questions to the Ensembl development list: ensembl-dev@ebi.ac.uk