| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
# The top level script that runs a rmark benchmark. |
| 4 |
# |
| 5 |
# Usage: |
| 6 |
# ./rmark-master.pl <execdir> <scriptdir> <resultdir> <optsfile> <benchmark prefix> <benchmark script> |
| 7 |
# |
| 8 |
# <execdir>: Directory for finding executables to be benchmarked. This |
| 9 |
# is passed on to the <benchmark script> without modification. |
| 10 |
# |
| 11 |
# <scriptdir>: Directory for finding scripts used by the benchmark, namely |
| 12 |
# rmark-idpositives.pl. |
| 13 |
# |
| 14 |
# <modeldir>: Directory for finding model files for the benchmark. This |
| 15 |
# is passed on to the <benchmark script> without modification. |
| 16 |
# Some programs don't require model files (e.g. BLAST), but they're |
| 17 |
# benchmark scripts will still take a <modeldir> argument. |
| 18 |
# |
| 19 |
# <resultdir>: A directory for holding all <ncpu> temporary files |
| 20 |
# created by the benchmark. This name should be short and unique; |
| 21 |
# it will also be used to construct job names on the cluster, as |
| 22 |
# <resultdir.$i>. |
| 23 |
# |
| 24 |
# <optsfile>: File with options for the search program. |
| 25 |
# For example, a non-filtered cmsearch 1.0 run would have a single |
| 26 |
# line in this file: |
| 27 |
# '--fil-no-hmm --fil-no-qdb" |
| 28 |
# |
| 29 |
# <benchmark prefix>: The script will look for files <prefix>.tbl, |
| 30 |
# <prefix>.msa, <prefix>.fa, and <prefix>.pos, defining a RMARK |
| 31 |
# benchmark set. If -P option is used, a positive-only benchmark is |
| 32 |
# being conducted, <prefix>.pfa and <prefix>.ppos will be used |
| 33 |
# instead of <prefix>.fa and <prefix>.pos. |
| 34 |
# |
| 35 |
# <benchmark script>: This script is executed for each process, |
| 36 |
# on an appropriately constructed subset of the benchmark queries. |
| 37 |
# |
| 38 |
# It must take the following arguments: |
| 39 |
# <execdir> <scriptdir> <modeldir> <resultdir> <optsfile> <tblfile> <msafile> <posfile> <fafile> <outfile> |
| 40 |
# |
| 41 |
# See definition of $options_usage string for description of options. |
| 42 |
# |
| 43 |
# Example of rmark benchmark: |
| 44 |
# ./rmark-master.pl -C models/rmark3.cm -F ../src/ rmark models r3-test cmsearch-df.opts rmark3 rmark/x-cmsearch |
| 45 |
|
| 46 |
use Getopt::Std; |
| 47 |
getopts('DPWB:N:T:FAM:O:C:X:ZYH:I:'); |
| 48 |
$do_posonly = 0; |
| 49 |
$do_poswindowonly = 0; |
| 50 |
$do_nopos = 0; |
| 51 |
$do_debug = 0; |
| 52 |
$do_onejob_only = 0; |
| 53 |
$do_build_models = 0; |
| 54 |
$do_indi = 0; |
| 55 |
$onejob = 0; |
| 56 |
$ncpu_set = 0; |
| 57 |
$ncpu = 0; |
| 58 |
$tbl_set = 0; |
| 59 |
$tbl_file = ""; |
| 60 |
$do_force = 0; |
| 61 |
$do_add = 0; |
| 62 |
$x_opt_to_pass = ""; |
| 63 |
$z_opt_to_pass = ""; |
| 64 |
$h_opt_to_pass = ""; |
| 65 |
$mpi_nprocs = 8; #default, we'll only use it if --mpi exists in <optsfile> |
| 66 |
if (defined $opt_D) { $do_debug = 1; } |
| 67 |
if (defined $opt_P) { $do_posonly = 1; } |
| 68 |
if (defined $opt_W) { $do_poswindowonly = 1; } |
| 69 |
if (defined $opt_Y) { $do_nopos = 1; } |
| 70 |
if (defined $opt_B) { $do_build_models = 1; $build_optsfile = $opt_B; } |
| 71 |
if (defined $opt_N) { $ncpu_set = 1; $ncpu = $opt_N; } |
| 72 |
if (defined $opt_T) { $tbl_set = 1; $tbl_file = $opt_T; } |
| 73 |
if (defined $opt_F) { $do_force = 1; } |
| 74 |
if (defined $opt_A) { $do_add = 1; } |
| 75 |
if (defined $opt_O) { $do_onejob_only = 1; $onejob = $opt_O; } |
| 76 |
if (defined $opt_C) { $do_fetch_models = 1; $master_model = $opt_C; if($do_build_models) { die "-B and -C are incompatible"; } } |
| 77 |
if (defined $opt_X) { $x_opt_to_pass = "-X $opt_X"; } |
| 78 |
if (defined $opt_Z) { $z_opt_to_pass = "-Z"; } |
| 79 |
if (defined $opt_H) { $h_opt_to_pass = "-H $opt_H"; } |
| 80 |
if (defined $opt_I) { $do_indi = 1; $nindi = $opt_I; } |
| 81 |
if (defined $opt_M) { |
| 82 |
$mpi_nprocs = $opt_M; |
| 83 |
if($mpi_nprocs < 2 || $mpi_nprocs > 8) { die "ERROR, with -M <n>, <n> must be between 2 and 8"; } |
| 84 |
} |
| 85 |
|
| 86 |
$usage = "Usage: perl rmark-master.pl\n\t<executable dir>\n\t<script dir>\n\t<model dir>\n\t<result dir, for output, must not exist>\n\t"; |
| 87 |
$usage .= "<options file, 1 line>\n\t<benchmark prefix>\n\t<benchmark script>\n\n"; |
| 88 |
$options_usage = "Options:\n\t"; |
| 89 |
$options_usage .= "-D : debugging; don't unlink intermediate files, save them all\n\t"; |
| 90 |
$options_usage .= "-P : run a positive-only benchmark, only positive sequences will be searched\n\t"; |
| 91 |
$options_usage .= "-B <f> : build models as needed, using options in file <f>\n\t"; |
| 92 |
$options_usage .= "-N <n> : use <n> processors, default is to use one per model\n\t"; |
| 93 |
$options_usage .= "-T <f> : read table file in <f> instead of <benchmark_prefix>.tbl\n\t"; |
| 94 |
$options_usage .= "-O <n> : only execute job number <n>, mainly for testing purposes\n\t"; |
| 95 |
$options_usage .= "-F : force; empty and overwrite result dir, if it already exists\n\t"; |
| 96 |
$options_usage .= "-A : add files to <result dir>, don't require it to be empty\n\t"; |
| 97 |
$options_usage .= "-C <f> : fetch models from existing file <f>\n\t"; |
| 98 |
$options_usage .= "-X <s> : pass on -X <s> to the benchmark script\n\t"; |
| 99 |
$options_usage .= "-Z : pass on -Z to the benchmark script\n\t"; |
| 100 |
$options_usage .= "-H <f> : pass on -H <f> to the benchmark script\n\t"; |
| 101 |
$options_usage .= "-I <f> : for x-cmsearch, do <n> searches, on <bmark_pfx>.1.fa through <bmark_pfx>.<n>.fa\n\t"; |
| 102 |
$options_usage .= "-M <n> : pass -M <n> onto search module, telling it to run MPI with <n> <= 8 processors\n\t"; |
| 103 |
$options_usage .= " only valid if --mpi exists in <optsfile>\n\n"; |
| 104 |
|
| 105 |
|
| 106 |
if(@ARGV != 7) |
| 107 |
{ |
| 108 |
print $usage; |
| 109 |
print $options_usage; |
| 110 |
exit(); |
| 111 |
} |
| 112 |
|
| 113 |
($execdir, $scriptdir, $modeldir, $resultdir, $optsfile, $benchmark_pfx, $rmark_script) = @ARGV; |
| 114 |
|
| 115 |
$tbl = "$benchmark_pfx.tbl"; |
| 116 |
if($tbl_set) { $tbl = $tbl_file; } |
| 117 |
$msafile = "$benchmark_pfx.msa"; |
| 118 |
$fafile = "$benchmark_pfx.fa"; |
| 119 |
$npfafile = "$benchmark_pfx-nopos.fa"; |
| 120 |
$pfafile = "$benchmark_pfx.pfa"; |
| 121 |
$wpfafile = "$benchmark_pfx.wpfa"; |
| 122 |
$posfile = "$benchmark_pfx.pos"; |
| 123 |
$pposfile = "$benchmark_pfx.ppos"; |
| 124 |
$wpposfile = "$benchmark_pfx.wppos"; |
| 125 |
$idscript = "$scriptdir/rmark-idpositives.pl"; |
| 126 |
|
| 127 |
# Check that all required files/directories for this script, and for |
| 128 |
# the benchmark driver exist |
| 129 |
if (! -d $execdir) { die "didn't find executable directory $execdir"; } |
| 130 |
if (! -d $scriptdir) { die "didn't find script directory $scriptdir"; } |
| 131 |
if (! -d $modeldir) { die "didn't find model directory $modeldir"; } |
| 132 |
if (! -e $idscript) { die "positive identification script $idscript doesn't exist"; } |
| 133 |
if (! -e $optsfile) { die "options file $optsfile doesn't exist"; } |
| 134 |
if (! -e $rmark_script) { die "options file $rmark_script doesn't exist"; } |
| 135 |
if (! -e $tbl) { die "table file $tbl doesn't exist"; } |
| 136 |
if (! -e $msafile) { die "msa file $tbl doesn't exist"; } |
| 137 |
if($do_posonly && $do_poswindowonly) { die "ERROR, only one of -P or -W may be enabled."; } |
| 138 |
if($do_posonly && $do_nopos) { die "ERROR, only one of -P or -Y may be enabled."; } |
| 139 |
if($do_poswindowonly && $do_nopos) { die "ERROR, only one of -Y or -W may be enabled."; } |
| 140 |
if($do_posonly) { |
| 141 |
if (! -e $pfafile) { die "$pfafile doesn't exist"; } |
| 142 |
if (! -e $pposfile) { die "$pposfile doesn't exist"; } |
| 143 |
} |
| 144 |
elsif($do_poswindowonly) { |
| 145 |
if (! -e $wpfafile) { die "$wpfafile doesn't exist"; } |
| 146 |
if (! -e $wpposfile) { die "$wpposfile doesn't exist"; } |
| 147 |
} |
| 148 |
elsif($do_nopos) { |
| 149 |
if (! -e $npfafile) { die "$npfafile doesn't exist"; } |
| 150 |
} |
| 151 |
else { |
| 152 |
if (! -e $fafile) { die "$fafile doesn't exist"; } |
| 153 |
if (! -e $posfile) { die "$posfile doesn't exist"; } |
| 154 |
} |
| 155 |
|
| 156 |
if ($do_posonly) { |
| 157 |
$fafile = $pfafile; |
| 158 |
$posfile = $pposfile; |
| 159 |
} |
| 160 |
if ($do_poswindowonly) { |
| 161 |
$fafile = $wpfafile; |
| 162 |
$posfile = $wpposfile; |
| 163 |
} |
| 164 |
if(! $do_add) { |
| 165 |
if ($do_force && (-e $resultdir)) { |
| 166 |
system("rm -rf $resultdir"); |
| 167 |
} |
| 168 |
if(-e $resultdir) { |
| 169 |
die("$resultdir exists"); |
| 170 |
} |
| 171 |
system("mkdir $resultdir"); |
| 172 |
} |
| 173 |
else { |
| 174 |
if(! -e $resultdir) { |
| 175 |
die("$resultdir does not exist, but -A used..."); |
| 176 |
} |
| 177 |
} |
| 178 |
if($do_nopos) { |
| 179 |
$fafile = $npfafile; |
| 180 |
$posfile; |
| 181 |
} |
| 182 |
if($do_indi) { |
| 183 |
if($do_onejob_only) { die "-I doesn't work with -O"; } |
| 184 |
if($rmark_script !~ m/x-cmsearch$/) { die "-I only works with x-cmsearch"; } |
| 185 |
for($i = 1; $i <= $nindi; $i++) { |
| 186 |
$tmpfile = "$benchmark_pfx-$i.fa"; |
| 187 |
if (! -e $tmpfile) { die "with -I, $tmpfile doesn't exist"; } |
| 188 |
$fafileA[($i-1)] = $tmpfile; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
# Suck in the master table |
| 193 |
open(BENCHMARK_TBL, $tbl) || die; |
| 194 |
$n = 0; |
| 195 |
while (<BENCHMARK_TBL>) |
| 196 |
{ |
| 197 |
($msaname[$n], $pid, $L, $nseq) = split; |
| 198 |
$alen{$msaname[$n]} = $L; |
| 199 |
$n++; |
| 200 |
} |
| 201 |
close BENCHMARK_TBL; |
| 202 |
|
| 203 |
if(! $ncpu_set) { $ncpu = $n; } |
| 204 |
|
| 205 |
if($do_onejob_only && $ncpu <= $onejob) { die "ERROR, -O $onejob enabled, but only $ncpu jobs exist."; } |
| 206 |
|
| 207 |
sub by_alen { $alen{$b} <=> $alen{$a} } |
| 208 |
|
| 209 |
# If we're doing more than one family per processor, sort by alen - this helps load balance. |
| 210 |
if($ncpu_set) { |
| 211 |
@sorted_msaname = sort by_alen @msaname; |
| 212 |
} |
| 213 |
else { |
| 214 |
@sorted_msaname = @msaname; |
| 215 |
} |
| 216 |
# Create <ncpu> subtables. |
| 217 |
for ($i = 0; $i < $n; $i++) |
| 218 |
{ |
| 219 |
$subtbl[$i % $ncpu] .= $sorted_msaname[$i]; |
| 220 |
$subtbl[$i % $ncpu] .= "\n"; |
| 221 |
} |
| 222 |
|
| 223 |
# Output the <ncpu> subtables |
| 224 |
for ($i = 0; $i < $ncpu; $i++) |
| 225 |
{ |
| 226 |
open(SUBTBL, ">$resultdir/tbl.$i") || die ("Failed to create $resultdir/tbl.$i"); |
| 227 |
print SUBTBL $subtbl[$i]; |
| 228 |
close SUBTBL; |
| 229 |
} |
| 230 |
|
| 231 |
# Determine if we're using MPI or not |
| 232 |
$do_mpi = 0; |
| 233 |
open(OPTS, $optsfile) || die "couldn't open options file $optsfile"; |
| 234 |
$searchopts = <OPTS>; |
| 235 |
if($searchopts =~ m/\-\-mpi/) { $do_mpi = 1; } |
| 236 |
close(OPTS); |
| 237 |
chomp $searchopts; |
| 238 |
|
| 239 |
$build_opt = ""; |
| 240 |
if($do_build_models) { |
| 241 |
$build_opt = "-B $build_optsfile"; |
| 242 |
} |
| 243 |
|
| 244 |
$c_opt = ""; |
| 245 |
if($do_fetch_models) { |
| 246 |
$c_opt = "-C $master_model"; |
| 247 |
} |
| 248 |
|
| 249 |
$posonly_opt = ""; |
| 250 |
if($do_posonly) { |
| 251 |
$posonly_opt = "-P"; |
| 252 |
} |
| 253 |
$poswindowonly_opt = ""; |
| 254 |
if($do_poswindowonly) { |
| 255 |
$poswindowonly_opt = "-W"; |
| 256 |
} |
| 257 |
if($do_debug) { |
| 258 |
$debug_opt = "-D"; |
| 259 |
} |
| 260 |
|
| 261 |
# Submit all the individual rmark jobs |
| 262 |
if(! $do_indi) { |
| 263 |
for ($i = 0; $i < $ncpu; $i++) |
| 264 |
{ |
| 265 |
if((!$do_onejob_only) || ($onejob == $i)) { |
| 266 |
if($do_mpi) { # turn exclusivity on, so we get all processors on our node, to run MPI with |
| 267 |
#printf("qsub -V -cwd -b y -N $resultdir.$i -j y -o $resultdir/tbl$i.sge -R y -l excl=true '$rmark_script $posonly_opt $debug_opt $build_opt $c_opt -M $mpi_nprocs $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.out'\n"); |
| 268 |
system("qsub -V -cwd -b y -N $resultdir.$i -j y -o $resultdir/tbl$i.sge -R y -l excl=true '$rmark_script $posonly_opt $poswindowonly_opt $debug_opt $build_opt $c_opt $x_opt_to_pass $z_opt_to_pass $h_opt_to_pass -M $mpi_nprocs $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.out'"); |
| 269 |
} |
| 270 |
else { |
| 271 |
#print("qsub -V -cwd -b y -N $resultdir.$i -j y -o $resultdir/tbl$i.sge -R y -l excl=true '$rmark_script $posonly_opt $poswindowonly_opt $debug_opt $build_opt $c_opt $x_opt_to_pass $z_opt_to_pass $h_opt_to_pass $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.out'"); |
| 272 |
system("qsub -V -cwd -b y -N $resultdir.$i -j y -o $resultdir/tbl$i.sge -R y -l excl=true '$rmark_script $posonly_opt $poswindowonly_opt $debug_opt $build_opt $c_opt $x_opt_to_pass $z_opt_to_pass $h_opt_to_pass $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.out'"); |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
else { # $do_indi |
| 278 |
for ($i = 0; $i < $ncpu; $i++) |
| 279 |
{ |
| 280 |
for($j = 0; $j < $nindi; $j++) { |
| 281 |
$fafile = $fafileA[$j]; |
| 282 |
if($do_mpi) { # turn exclusivity on, so we get all processors on our node, to run MPI with |
| 283 |
# 2 qsubs, one with -T (--toponly) and one with -B (--bottomonly) |
| 284 |
#printf("qsub -V -cwd -b y -N $resultdir.$i.$j.T -j y -o $resultdir/tbl$i.$j.T.sge -l excl=true '$rmark_script -K $j.T -T $posonly_opt $debug_opt $build_opt $c_opt -M $mpi_nprocs $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.$j.T.out'\n"); |
| 285 |
#printf("qsub -V -cwd -b y -N $resultdir.$i.$j.B -j y -o $resultdir/tbl$i.$j.B.sge -l excl=true '$rmark_script -K $j.B -B $posonly_opt $debug_opt $build_opt $c_opt -M $mpi_nprocs $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.$j.B.out'\n"); |
| 286 |
system("qsub -V -cwd -b y -N $resultdir.$i.$j.T -j y -o $resultdir/tbl$i.$j.T.sge -l excl=true '$rmark_script -K $j.T -T $posonly_opt $poswindowonly_opt $debug_opt $build_opt $c_opt $x_opt_to_pass $z_opt_to_pass $h_opt_to_pass -M $mpi_nprocs $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl$i $msafile $posfile $fafile $resultdir/tbl$i.$j.T.out'"); |
| 287 |
system("qsub -V -cwd -b y -N $resultdir.$i.$j.B -j y -o $resultdir/tbl$i.$j.B.sge -l excl=true '$rmark_script -K $j.B -B $posonly_opt $poswindowonly_opt $debug_opt $build_opt $c_opt $x_opt_to_pass $z_opt_to_pass $h_opt_to_pass -M $mpi_nprocs $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl$i $msafile $posfile $fafile $resultdir/tbl$i.$j.B.out'"); |
| 288 |
} |
| 289 |
else { |
| 290 |
# 2 qsubs, one with -T (--toponly) and one with -B (--bottomonly) |
| 291 |
#printf("qsub -V -cwd -b y -N $resultdir.$i.$j.T -j y -o $resultdir/tbl$i.$j.T.sge '$rmark_script -K $j.T -T $posonly_opt $debug_opt $build_opt $c_opt $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.$j.T.out'\n"); |
| 292 |
#printf("qsub -V -cwd -b y -N $resultdir.$i.$j.B -j y -o $resultdir/tbl$i.$j.B.sge '$rmark_script -K $j.B -B $posonly_opt $debug_opt $build_opt $c_opt $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.$j.B.out'\n"); |
| 293 |
system("qsub -V -cwd -b y -N $resultdir.$i.$j.T -j y -o $resultdir/tbl$i.$j.T.sge -R y -l excl=true '$rmark_script -K $j.T -T $posonly_opt $poswindowonly_opt $debug_opt $build_opt $c_opt $x_opt_to_pass $z_opt_to_pass $h_opt_to_pass $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.$j.T.out'"); |
| 294 |
system("qsub -V -cwd -b y -N $resultdir.$i.$j.B -j y -o $resultdir/tbl$i.$j.B.sge -R y -l excl=true '$rmark_script -K $j.B -B $posonly_opt $poswindowonly_opt $debug_opt $build_opt $c_opt $x_opt_to_pass $z_opt_to_pass $h_opt_to_pass $execdir $scriptdir $modeldir $resultdir $optsfile $resultdir/tbl.$i $msafile $posfile $fafile $resultdir/tbl$i.$j.B.out'"); |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
} |