| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
# Do a piece of a rmark benchmark, for cmsearch. |
| 4 |
# |
| 5 |
# This script is normally called by rmark-master.pl; its command line |
| 6 |
# syntax is tied to rmark-master.pl. |
| 7 |
# x-cmsearch doesn't use the <msafile>, but it's passed in so that |
| 8 |
# rmark-master.pl can use a consistent command line structure for |
| 9 |
# all search programs (BLAST uses it, for example). |
| 10 |
# |
| 11 |
# Usage: x-cmsearch <execdir> <scriptdir> <modeldir> <resultdir> <optsfile> <tblfile> <msafile> <posfile> <fafile> <outfile> |
| 12 |
# Example: ./x-cmsearch ../infernal/src/ ../rmark/ i1-models testdir i1-df.opts test.tbl rmark3.msa rmark3.pos test.fa test.out |
| 13 |
# |
| 14 |
# For command-line options, see definition of $options_usage below. |
| 15 |
# |
| 16 |
# SRE, Tue Apr 20 10:32:49 2010 [Janelia] |
| 17 |
# SVN $Id$ |
| 18 |
# |
| 19 |
use Getopt::Std; |
| 20 |
getopts('DTBPWG:M:C:ZYH:K:'); |
| 21 |
$mpi_nprocs = 8; |
| 22 |
$do_build_models = 0; |
| 23 |
$do_debug = 0; |
| 24 |
$build_optsfile = ""; |
| 25 |
$do_posonly = 0; |
| 26 |
$do_poswindowonly = 0; |
| 27 |
$do_old_cmsearch = 0; |
| 28 |
$do_p7file = 0; |
| 29 |
$master_p7file = ""; |
| 30 |
$do_partial = 0; |
| 31 |
$do_toponly = 0; |
| 32 |
$do_bottomonly = 0; |
| 33 |
$key = ""; |
| 34 |
if (defined $opt_D) { $do_debug = 1; } |
| 35 |
if (defined $opt_X) { $do_partial = 1; $partial_seqname = $opt_X; } |
| 36 |
if (defined $opt_T) { $do_toponly = 1; } |
| 37 |
if (defined $opt_B) { $do_bottomonly = 1; } |
| 38 |
if (defined $opt_W) { $do_poswindowonly = 1; } |
| 39 |
if (defined $opt_Y) { $do_nopos = 1; } |
| 40 |
if (defined $opt_G) { $do_build_models = 1; $build_optsfile = $opt_B; } |
| 41 |
if (defined $opt_C) { $do_fetch_models = 1; $master_model = $opt_C; if($do_build_models) { die "-G and -C are incompatible"; } } |
| 42 |
if (defined $opt_Z) { $do_old_cmsearch = 1; } |
| 43 |
if (defined $opt_K) { $key = $opt_K; } |
| 44 |
if (defined $opt_M) { |
| 45 |
$mpi_nprocs = $opt_M; |
| 46 |
if($mpi_nprocs < 2 || $mpi_nprocs > 8) { die "ERROR, with -M <n>, <n> must be between 2 and 8"; } |
| 47 |
} |
| 48 |
if($do_posonly && $do_poswindowonly) { die "ERROR, only one of -P or -W may be enabled."; } |
| 49 |
if($do_posonly && $do_nopos) { die "ERROR, only one of -P or -Y may be enabled."; } |
| 50 |
if($do_poswindowonly && $do_nopos) { die "ERROR, only one of -Y or -W may be enabled."; } |
| 51 |
$usage = "Usage: x-cmsearch [options]\n\t<execdir>\n\t<scriptdir>\n\t<modeldir>\n\t<resultdir>\n\t<optsfile>\n\t<tblfile>\n\t<msafile>\n\t<posfile>\n\t<fafile>\n\t<outfile>\n"; |
| 52 |
$options_usage = "Options:\n\t"; |
| 53 |
$options_usage .= " -D : debugging; don't unlink intermediate files, save them all\n\t"; |
| 54 |
$options_usage .= " -T : use --toponly in cmsearch\n\t"; |
| 55 |
$options_usage .= " -B : use --bottomonly in cmsearch\n\t"; |
| 56 |
$options_usage .= " -P : run a positive-only benchmark, only each family's positive sequences will be searched\n\t"; |
| 57 |
$options_usage .= " -W : run a positive-window-only benchmark\n\t"; |
| 58 |
$options_usage .= " -M <n> : run MPI with <n> <= 8 processors, only valid if --mpi exists in the <optsfile>\n\t"; |
| 59 |
$options_usage .= " -G <f> : build models as needed, using options in file <f>\n\t"; |
| 60 |
$options_usage .= " -C <f> : fetch models from existing file <f>\n\t"; |
| 61 |
$options_usage .= " -Z : run v1.0 cmsearch\n\t"; |
| 62 |
$options_usage .= " -Y : run a no-positive benchmark; for timings only\n\t"; |
| 63 |
$options_usage .= " -K <s> : use key <s> when naming output files\n\n"; |
| 64 |
if(scalar(@ARGV) != 10) { printf("$usage\n$options_usage"); exit(1); } |
| 65 |
|
| 66 |
($execdir, $scriptdir, $modeldir, $resultdir, $optsfile, $tblfile, $msafile, $posfile, $fafile, $outfile) = @ARGV; |
| 67 |
$tmpoutfile = $outfile . ".tmp"; |
| 68 |
$sorttmpoutfile = $outfile . ".tmp.sort"; |
| 69 |
|
| 70 |
$idscript = "$scriptdir/rmark-idpositives.pl"; |
| 71 |
$cmsearch = "$execdir/cmsearch"; |
| 72 |
$cmbuild = "$execdir/cmbuild"; |
| 73 |
$afetch = "$execdir/esl-afetch"; |
| 74 |
$sfetch = "$execdir/esl-sfetch"; |
| 75 |
$cmfetch = "$execdir/cmfetch"; |
| 76 |
$hmmfetch = "$execdir/hmmfetch"; |
| 77 |
|
| 78 |
if(! -e $afetch) { |
| 79 |
$afetch = "$execdir/../easel/miniapps/esl-afetch"; |
| 80 |
if(! -e $afetch) { die "$afetch does not exist, nor $execdir/$afetch"; } |
| 81 |
} |
| 82 |
if($do_posonly || $do_poswindowonly) { |
| 83 |
if(! -e $sfetch) { |
| 84 |
$sfetch = "$execdir/../easel/miniapps/esl-sfetch"; |
| 85 |
if(! -e $sfetch) { die "$sfetch does not exist, nor $execdir/$sfetch"; } |
| 86 |
} |
| 87 |
} |
| 88 |
if($do_fetch_models) { |
| 89 |
if(! -e $cmfetch) { die "$cmfetch does not exist"; } |
| 90 |
} |
| 91 |
$bo_opt = ""; |
| 92 |
$to_opt = ""; |
| 93 |
if($do_toponly) { $to_opt = "--toponly"; } |
| 94 |
if($do_bottomonly) { $bo_opt = "--bottomonly"; } |
| 95 |
|
| 96 |
if (! -d $execdir) { die "didn't find executable directory $execdir"; } |
| 97 |
if (! -d $scriptdir) { die "didn't find script directory $scriptdir"; } |
| 98 |
if (! -x $cmsearch) { die "didn't find executable $cmsearch"; } |
| 99 |
if (! -e $resultdir) { die "$resultdir doesn't exist"; } |
| 100 |
if (! -e $posfile) { die "$posfile doesn't exist"; } |
| 101 |
if (! -e $idscript) { die "positive identification script $idscript doesn't exist"; } |
| 102 |
if (! -e $optsfile) { die "options file $optsfile doesn't exist"; } |
| 103 |
if ($do_build_models) { |
| 104 |
if (! -e $build_optsfile) { die "options file $build_optsfile doesn't exist"; } |
| 105 |
} |
| 106 |
|
| 107 |
# read options file, determine if we're using mpi or not |
| 108 |
# first options line is general options to use for all searches |
| 109 |
# all remaining lines are <fam> <fam-specific-options> |
| 110 |
$do_mpi = 0; |
| 111 |
open(OPTS, $optsfile) || die "couldn't open options file $optsfile"; |
| 112 |
$searchopts = <OPTS>; |
| 113 |
if($searchopts =~ m/\-\-mpi/) { $do_mpi = 1; } |
| 114 |
while($line = <OPTS>) { |
| 115 |
chomp $line; |
| 116 |
$fam = $line; |
| 117 |
$fam =~ s/\s+.+$//; |
| 118 |
$opts = $line; |
| 119 |
$opts =~ s/^\S+\s+//; |
| 120 |
$fam_searchopts_H{$fam} = $opts; |
| 121 |
} |
| 122 |
close(OPTS); |
| 123 |
chomp $searchopts; |
| 124 |
|
| 125 |
# check all models exist before we fire off searches |
| 126 |
if((! $do_build_models) && (! $do_fetch_models)) { |
| 127 |
open(TABLE, "$tblfile") || die "failed to open $tblfile"; |
| 128 |
while (<TABLE>) { |
| 129 |
($msaname) = split; |
| 130 |
if(! -e "$modeldir/$msaname.cm") { die "didn't find model file $modeldir/$msaname.cm"; } |
| 131 |
} |
| 132 |
close(TABLE); |
| 133 |
} |
| 134 |
elsif($do_build_models) { # -G <f> enabled, read the options file <f> |
| 135 |
open(OPTS, $build_optsfile) || die "couldn't open options file $build_optsfile"; |
| 136 |
$buildopts = <OPTS>; |
| 137 |
close(OPTS); |
| 138 |
chomp($buildopts); |
| 139 |
|
| 140 |
$modeldir = $resultdir; # we'll build the models and read them from the $resultdir/ |
| 141 |
} |
| 142 |
elsif($do_fetch_models) { |
| 143 |
$modeldir = $resultdir; # we'll fetch the models and read them from the $resultdir/ |
| 144 |
} |
| 145 |
|
| 146 |
open(OUTFILE,">$outfile") || die "failed to open $outfile"; |
| 147 |
open(TMPOUTFILE,">$tmpoutfile") || die "failed to open $tmpoutfile"; |
| 148 |
open(TABLE, "$tblfile") || die "failed to open $tblfile"; |
| 149 |
$orig_fafile = $fafile; |
| 150 |
while (<TABLE>) |
| 151 |
{ |
| 152 |
($msaname) = split; |
| 153 |
|
| 154 |
if($do_build_models) { |
| 155 |
$status = system("$afetch -o $resultdir/$msaname" . $key . ".sto $msafile $msaname > /dev/null"); |
| 156 |
if ($status != 0) { die "UH FAILED: $afetch -o $resultdir/$msaname" . $key . ".sto $msafile $msaname > /dev/null"; } |
| 157 |
|
| 158 |
$status = system("$cmbuild $buildopts $resultdir/$msaname" . $key . ".cm $resultdir/$msaname" . $key . ".sto > /dev/null"); |
| 159 |
if ($status != 0) { die "FAILED: $cmbuild $buildopts $resultdir/$msaname" . $key . ".cm $resultdir/$msaname" . $key . ".sto > /dev/null"; } |
| 160 |
$cmfile = "$resultdir/$msaname" . $key . ".cm"; |
| 161 |
} |
| 162 |
elsif($do_fetch_models) { |
| 163 |
$status = system("$cmfetch -o $resultdir/$msaname" . $key . ".cm $master_model $msaname > /dev/null"); |
| 164 |
if ($status != 0) { die "FAILED: $cmfetch -o $resultdir/$msaname" . $key . ".cm $master_model > /dev/null"; } |
| 165 |
$cmfile = "$resultdir/$msaname" . $key . ".cm"; |
| 166 |
} |
| 167 |
else { |
| 168 |
$cmfile = "$modeldir/$msaname.cm"; |
| 169 |
} |
| 170 |
|
| 171 |
$p7file_opt = ""; |
| 172 |
$p7file = ""; |
| 173 |
|
| 174 |
if($do_posonly) { #fetch this family's sequences |
| 175 |
$command = "grep \"^$msaname\/\" rmark3.ppos | awk \'{ print \$3 }\' > $resultdir/$msaname" . $key . ".sfetch"; |
| 176 |
$status = system($command); |
| 177 |
if ($status != 0) { die "FAILED: $command failed"; } |
| 178 |
|
| 179 |
$command = "$sfetch -o $resultdir/$msaname" . $key . ".pfa -f $orig_fafile $resultdir/$msaname" . $key . ".sfetch > /dev/null"; |
| 180 |
$status = system($command); |
| 181 |
if ($status != 0) { die "FAILED: $command failed"; } |
| 182 |
|
| 183 |
$fafile = "$resultdir/$msaname" . $key . ".pfa"; |
| 184 |
} |
| 185 |
if($do_poswindowonly) { #fetch this family's sequences |
| 186 |
$command = "grep \"^$msaname\/\" rmark3.wppos | awk \'{ print \$2 }\' > $resultdir/$msaname" . $key . ".sfetch"; |
| 187 |
$status = system($command); |
| 188 |
if ($status != 0) { die "FAILED: $command failed"; } |
| 189 |
|
| 190 |
$nl = `wc -l $resultdir/$msaname" . $key . ".sfetch`; |
| 191 |
if($nl =~ m/^0\s+/) { |
| 192 |
printf("WHOA!!!\n"); |
| 193 |
unlink "$resultdir/$msaname" . $key . ".sfetch"; |
| 194 |
next; |
| 195 |
} |
| 196 |
$command = "$sfetch -o $resultdir/$msaname" . $key . ".wpfa -f $orig_fafile $resultdir/$msaname" . $key . ".sfetch > /dev/null"; |
| 197 |
$status = system($command); |
| 198 |
if ($status != 0) { die "FAILED: $command failed"; } |
| 199 |
|
| 200 |
$fafile = "$resultdir/$msaname" . $key . ".wpfa"; |
| 201 |
} |
| 202 |
$extra_opt = ""; |
| 203 |
if($do_old_cmsearch) { |
| 204 |
$tab_opt = "--tabfile $resultdir/$msaname" . $key . ".tmp"; |
| 205 |
} |
| 206 |
else { |
| 207 |
$tab_opt = "--tblout $resultdir/$msaname" . $key . ".tmp"; |
| 208 |
$extra_opt = "--seed 181"; |
| 209 |
} |
| 210 |
|
| 211 |
if($do_mpi) { |
| 212 |
$command = "mpirun -np $mpi_nprocs $cmsearch $bo_opt $to_opt $searchopts $fam_searchopts_H{$msaname} $p7file_opt $tab_opt $extra_opt $cmfile $fafile > $resultdir/$msaname" . $key . ".search"; |
| 213 |
$status = system($command); |
| 214 |
if ($status != 0) { die "FAILED: $command"; } |
| 215 |
} |
| 216 |
else { |
| 217 |
$command = "$cmsearch $bo_opt $to_opt $searchopts $fam_searchopts_H{$msaname} $p7file_opt $tab_opt $extra_opt $cmfile $fafile > $resultdir/$msaname" . $key . ".search"; |
| 218 |
$status = system($command); |
| 219 |
if ($status != 0) { die "FAILED: $command"; } |
| 220 |
} |
| 221 |
|
| 222 |
if(! $do_nopos) { |
| 223 |
open(OUTPUT, "$resultdir/$msaname" . $key . ".tmp") || die "FAILED: to open $resultdir/$msaname" . $key . ".tmp tabular output file"; |
| 224 |
if($do_old_cmsearch) { |
| 225 |
while (<OUTPUT>) |
| 226 |
{ |
| 227 |
if (/^\#/) { next; } |
| 228 |
@fields = split(' ', $_, 9); |
| 229 |
$target = $fields[1]; |
| 230 |
$target_from = $fields[2]; |
| 231 |
$target_to = $fields[3]; |
| 232 |
$bitscore = $fields[6]; |
| 233 |
$evalue = $fields[7]; |
| 234 |
printf TMPOUTFILE "%10g %10.1f %10d %10d %20s %35s\n", $evalue, $bitscore, $target_from, $target_to, $target, $msaname; |
| 235 |
} |
| 236 |
} |
| 237 |
else { |
| 238 |
while (<OUTPUT>) |
| 239 |
{ |
| 240 |
if (/^\#/) { next; } |
| 241 |
@fields = split(' ', $_, 16); |
| 242 |
$target = $fields[0]; |
| 243 |
$target_from = $fields[7]; |
| 244 |
$target_to = $fields[8]; |
| 245 |
$bitscore = $fields[14]; |
| 246 |
$evalue = $fields[15]; |
| 247 |
printf TMPOUTFILE "%10g %10.1f %10d %10d %20s %35s\n", $evalue, $bitscore, $target_from, $target_to, $target, $msaname; |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
if($do_debug == 0) { |
| 252 |
unlink "$resultdir/$msaname" . $key . ".tmp"; |
| 253 |
if($do_build_models) { |
| 254 |
unlink "$resultdir/$msaname" . $key . ".cm"; |
| 255 |
unlink "$resultdir/$msaname" . $key . ".sto"; |
| 256 |
} |
| 257 |
elsif($do_fetch_models) { |
| 258 |
unlink "$resultdir/$msaname" . $key . ".cm"; |
| 259 |
} |
| 260 |
if($do_posonly) { |
| 261 |
unlink "$resultdir/$msaname" . $key . ".pfa"; |
| 262 |
unlink "$resultdir/$msaname" . $key . ".sfetch"; |
| 263 |
} |
| 264 |
if($do_poswindowonly) { |
| 265 |
unlink "$resultdir/$msaname" . $key . ".wpfa"; |
| 266 |
unlink "$resultdir/$msaname" . $key . ".sfetch"; |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
system("grep \"CPU time\" $resultdir/$msaname" . $key . ".search > $resultdir/$msaname" . $key . ".time"); |
| 271 |
sleep(0.1); |
| 272 |
if($do_debug == 0) { |
| 273 |
unlink "$resultdir/$msaname" . $key . ".search"; |
| 274 |
} |
| 275 |
} |
| 276 |
close TABLE; |
| 277 |
close OUTFILE; |
| 278 |
close TMPOUTFILE; |
| 279 |
|
| 280 |
# Use 'rmark-idpositives.pl' to identify positives in the temporary output file to |
| 281 |
# create the permanent output file. First, we need to sort by score. |
| 282 |
|
| 283 |
if(! $do_nopos) { |
| 284 |
$command = "sort -g $tmpoutfile > $sorttmpoutfile"; |
| 285 |
$status = system("$command"); |
| 286 |
if ($status != 0) { die "FAILED: $command"; } |
| 287 |
|
| 288 |
$command = "perl $idscript $posfile $sorttmpoutfile > $outfile"; |
| 289 |
$status = system("$command"); |
| 290 |
if ($status != 0) { die "FAILED: $command"; } |
| 291 |
|
| 292 |
sleep(0.1); |
| 293 |
if($do_debug == 0) { |
| 294 |
unlink $tmpoutfile; |
| 295 |
unlink $sorttmpoutfile; |
| 296 |
} |
| 297 |
} |
| 298 |
else { |
| 299 |
unlink $tmpoutfile; |
| 300 |
} |