my ($self, $query, $target, $mapper, @
options) = @_;
my $root_dir = $mapper->core->dir;
my $queryfile = basename($query);
my $targetfile = basename($target);
my $prefix = $root_dir . "/" . basename($query);
$prefix =~ s/\.\w+$
my ($ensembl_type) = $prefix =~ /.*_(dna|peptide)$/; # dna or prot
my $options_str = join(
" ", @
options);
my $unique_name = $self->get_class_name() . "_" . time();
my $disk_space_needed = (stat($query))[7]+(stat($target))[7];
$disk_space_needed /= 1024000; # convert to MB
$disk_space_needed = int($disk_space_needed);
$disk_space_needed += 1;
my $exe = $self->mapper->exonerate || $exonerate_path;
if(defined($mapper->nofarm)){
my $output = $self->get_class_name() . "_" . $ensembl_type. "_1.map";
my $cmd = <<EON;
$exe $query $target --showvulgar false --showalignment FALSE --ryo "xref:%qi:%ti:%ei:%ql:%tl:%qab:%qae:%tab:%tae:%C:%s\n" $options_str | grep '^xref' > $root_dir/$output
EON
print "none farm command is $cmd\n" if($mapper->verbose);
# write details of job to database
my $sth = $mapper->xref->dbc->prepare("insert into process_status (status, date) values('mapping_submitted',now())");
$sth->execute();
$sth->finish;
my $jobid = 1;
if($ensembl_type eq "peptide"){
$jobid = 2;
}
for( my $i=1; $i<=1; $i++){
my $command = "$exe $query $target --showvulgar false --showalignment FALSE --ryo ".
'"xref:%qi:%ti:%ei:%ql:%tl:%qab:%qae:%tab:%tae:%C:%s\\\n"'." $options_str | grep ".'"'."^xref".'"'." > $root_dir/$output";
my $insert = "insert into mapping (job_id, type, command_line, percent_query_cutoff, percent_target_cutoff, method, array_size) values($jobid, '$ensembl_type', '$command',".
$self->query_identity_threshold.", ".$self->target_identity_threshold.", '".$self->get_class_name()."', $i)";
$sth = $mapper->xref->dbc->prepare($insert);
$sth->execute;
$sth->finish;
$sth = $mapper->xref->dbc->prepare("insert into mapping_jobs (root_dir, map_file, status, out_file, err_file, array_number, job_id) values (?,?,?,?,?,?,?)");
my $map_file = $self->get_class_name()."_".$ensembl_type."_".$i.".map";
my $out_file = "xref_0_".$ensembl_type.".".$jobid."-".$i.".out";
my $err_file = "xref_0_".$ensembl_type.".".$jobid."-".$i.".err";
$sth->execute($root_dir, $map_file, 'SUBMITTED', $out_file, $err_file, $i, $jobid);
}
$sth->finish;
system($cmd);
$self->jobcount(1);
return "nofarm";
}
# array features barf if just one job
if($num_jobs == 1){
$num_jobs++;
}
$self->jobcount($self->jobcount()+$num_jobs);
my $output = $self->get_class_name() . "_" . $ensembl_type . "_" . "\$LSB_JOBINDEX.map";
my $queue = $self->mapper->farm_queue || 'production-rh74';
my $usage = '-M 1500 -R"select[mem>1500] rusage[tmp='.$disk_space_needed.', mem=1500]" '.'-J "'.$unique_name.'[1-'.$num_jobs.']%200" -o '.$prefix.'.%J-%I.out -e '.$prefix.'.%J-%I.err';
$queue and $usage = "-q $queue " . $usage;
my $command = $exe." ".$query." ".$target.' --querychunkid $LSB_JOBINDEX --querychunktotal '.$num_jobs.' --showvulgar false --showalignment FALSE --ryo "xref:%qi:%ti:%ei:%ql:%tl:%qab:%qae:%tab:%tae:%C:%s\n" '.$options_str;
$command .= " | grep '^xref' > $root_dir/$output";
my $exe_file = $root_dir."/".$unique_name.".submit";
open(my $rh,">", $exe_file) || die "Could not open file $exe_file";
my $lsf_conf = "/usr/local/lsf/conf/profile.lsf";
if (-e $lsf_conf) {
print $rh ". $lsf_conf\n";
}
print $rh $command."\n";
close $rh;
chmod 0755, $exe_file;
my $com = "bsub $usage $exe_file";
my $line = `$com`;
my $jobid = 0;
if ($line =~ /^Job <(\d+)> is submitted/) {
$jobid = $1;
print "LSF job ID for main mapping job: $jobid, name $unique_name with $num_jobs arrays elements)\n" if($mapper->verbose);
}
if (!$jobid) {
# Something went wrong
warn("Job submission failed:\n$@\n");
print STDERR "bsub command was $com\n";
print STDERR $line."\n";
return 0;
}
else{
# write details of job to database
my $command = "$exe $query $target --querychunkid \$LSB_JOBINDEX --querychunktotal $num_jobs --showvulgar false --showalignment FALSE --ryo ".
'"xref:%qi:%ti:%ei:%ql:%tl:%qab:%qae:%tab:%tae:%C:%s\\\n"'." $options_str | grep ".'"'."^xref".'"'." > $root_dir/$output";
my $sth = $mapper->xref->dbc->prepare("insert into process_status (status, date) values('mapping_submitted',now())");
$sth->execute();
$sth->finish;
my $insert = "insert into mapping (job_id, type, command_line, percent_query_cutoff, percent_target_cutoff, method, array_size) values($jobid, '$ensembl_type', '$command',".
$self->query_identity_threshold.", ".$self->target_identity_threshold.", '".$self->get_class_name()."', $num_jobs)";
$sth = $mapper->xref->dbc->prepare($insert);
$sth->execute;
$sth->finish;
$sth = $mapper->xref->dbc->prepare("insert into mapping_jobs (root_dir, map_file, status, out_file, err_file, array_number, job_id) values (?,?,?,?,?,?,?)");
for( my $i=1; $i<=$num_jobs; $i++){
my $map_file = $self->get_class_name()."_".$ensembl_type."_".$i.".map";
my $out_file = "xref_0_".$ensembl_type.".".$jobid."-".$i.".out";
my $err_file = "xref_0_".$ensembl_type.".".$jobid."-".$i.".err";
$sth->execute($root_dir, $map_file, 'SUBMITTED', $out_file, $err_file, $i, $jobid);
}
$sth->finish;
}
return $unique_name;
}