| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
# Do a piece of a rmark benchmark, for nhmmer. |
| 4 |
# |
| 5 |
# This script is normally called by rmark-master.pl; its command line |
| 6 |
# syntax is tied to rmark-master.pl. |
| 7 |
# x-nhmmer 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-nhmmer <execdir> <scriptdir> <modeldir> <resultdir> <optsfile> <tblfile> <msafile> <posfile> <fafile> <outfile> |
| 12 |
# Example: ./x-nhmmer ../hmmer/src/ ../rmark h3-models testdir h3-df.opts test.tbl rmark3.msa rmark3.pos test.fa test.out |
| 13 |
# |
| 14 |
# Command-line options: |
| 15 |
# -C <f> : fetch models from existing file <f> |
| 16 |
# -P : run a positive-only benchmark, only each family's positive sequences will be searched |
| 17 |
# |
| 18 |
# SRE, Tue Apr 20 10:32:49 2010 [Janelia] |
| 19 |
# SVN $Id$ |
| 20 |
# |
| 21 |
use Getopt::Std; |
| 22 |
getopts('PC:D'); |
| 23 |
$do_fetch_models = 0; |
| 24 |
$do_debug = 0; |
| 25 |
$do_posonly = 0; |
| 26 |
if (defined $opt_C) { $do_fetch_models = 1; $master_model = $opt_C; } |
| 27 |
if (defined $opt_D) { $do_debug = 1; } |
| 28 |
if (defined $opt_P) { $do_posonly = 1; } |
| 29 |
|
| 30 |
$usage = "Usages: x-nhmmer [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"; |
| 31 |
|
| 32 |
if(scalar(@ARGV) != 10) { printf("$usage\n"); exit(1); } |
| 33 |
|
| 34 |
($execdir, $scriptdir, $modeldir, $resultdir, $optsfile, $tblfile, $msafile, $posfile, $fafile, $outfile) = @ARGV; |
| 35 |
$tmpoutfile = $outfile . ".tmp"; |
| 36 |
$sorttmpoutfile = $outfile . ".tmp.sort"; |
| 37 |
|
| 38 |
$idscript = "$scriptdir/rmark-idpositives.pl"; |
| 39 |
$nhmmer = "$execdir/nhmmer"; |
| 40 |
$hmmfetch = "$execdir/hmmfetch"; |
| 41 |
$sfetch = "$execdir/esl-sfetch"; |
| 42 |
if($do_posonly) { |
| 43 |
if(! -e $sfetch) { |
| 44 |
$sfetch = "$execdir/../easel/miniapps/esl-sfetch"; |
| 45 |
if(! -e $sfetch) { die "$sfetch does not exist, nor $execdir/$sfetch"; } |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
if($do_fetch_models) { |
| 50 |
if(! -e $hmmfetch) { die "$hmmfetch does not exist"; } |
| 51 |
} |
| 52 |
|
| 53 |
if (! -d $execdir) { die "didn't find executable directory $execdir"; } |
| 54 |
if (! -d $scriptdir) { die "didn't find script directory $scriptdir"; } |
| 55 |
if (! -d $modeldir) { die "didn't find model directory $modeldir"; } |
| 56 |
if (! -x $nhmmer) { die "didn't find executable $nhmmer"; } |
| 57 |
if (! -e $resultdir) { die "$resultdir doesn't exist"; } |
| 58 |
if (! -e $posfile) { die "$posfile doesn't exist"; } |
| 59 |
if (! -e $idscript) { die "positive identification script $idscript doesn't exist"; } |
| 60 |
if (! -e $optsfile) { die "options file $optsfile doesn't exist"; } |
| 61 |
|
| 62 |
# read options file |
| 63 |
|
| 64 |
open(OPTS, $optsfile) || die "couldn't open options file $optsfile"; |
| 65 |
$searchopts = <OPTS>; |
| 66 |
close(OPTS); |
| 67 |
chomp $searchopts; |
| 68 |
|
| 69 |
# check all models exist before we fire off searches |
| 70 |
if(! $do_fetch_models) { |
| 71 |
open(TABLE, "$tblfile") || die "failed to open $tblfile"; |
| 72 |
while (<TABLE>) { |
| 73 |
($msaname) = split; |
| 74 |
if(! -e "$modeldir/$msaname.hmm") { die "didn't find model file $modeldir/$msaname.hmm"; } |
| 75 |
} |
| 76 |
close(TABLE); |
| 77 |
} |
| 78 |
elsif($do_fetch_models) { |
| 79 |
$modeldir = $resultdir; # we'll fetch the models and read them from the $resultdir/ |
| 80 |
} |
| 81 |
|
| 82 |
open(OUTFILE,">$outfile") || die "failed to open $outfile"; |
| 83 |
open(TMPOUTFILE,">$tmpoutfile") || die "failed to open $tmpoutfile"; |
| 84 |
open(TABLE, "$tblfile") || die "failed to open $tblfile"; |
| 85 |
$orig_fafile = $fafile; |
| 86 |
while (<TABLE>) |
| 87 |
{ |
| 88 |
$runtime = -1 * time(); |
| 89 |
|
| 90 |
($msaname) = split; |
| 91 |
|
| 92 |
if($do_fetch_models) { |
| 93 |
$status = system("$hmmfetch -o $resultdir/$msaname.hmm $master_model $msaname > /dev/null"); |
| 94 |
if ($status != 0) { die "FAILED: $hmmfetch -o $resultdir/$msaname.hmm $master_model > /dev/null"; } |
| 95 |
} |
| 96 |
|
| 97 |
if($do_posonly) { #fetch this family's sequences |
| 98 |
$command = "grep \"^$msaname\/\" rmark3.ppos | awk \'{ print \$3 }\' > $resultdir/$msaname.sfetch"; |
| 99 |
$status = system($command); |
| 100 |
if ($status != 0) { die "FAILED: $command failed"; } |
| 101 |
|
| 102 |
$command = "$sfetch -o $resultdir/$msaname.pfa -f $orig_fafile $resultdir/$msaname.sfetch > /dev/null"; |
| 103 |
$status = system($command); |
| 104 |
if ($status != 0) { die "FAILED: $command failed"; } |
| 105 |
|
| 106 |
$fafile = "$resultdir/$msaname.pfa"; |
| 107 |
} |
| 108 |
|
| 109 |
$status = system("$nhmmer $searchopts --tblout $resultdir/$msaname.tmp $modeldir/$msaname.hmm $fafile > $resultdir/$msaname.search"); |
| 110 |
if ($status != 0) { die "FAILED: $nhmmer $searchopts --tblout $resultdir/$msaname.tmp $resultdir/$msaname.hmm $fafile > $resultdir/$msaname.nhmmer"; } |
| 111 |
|
| 112 |
open(OUTPUT, "$resultdir/$msaname.tmp") || die "FAILED: to open $resultdir/$msaname.tmp tabular output file"; |
| 113 |
while (<OUTPUT>) |
| 114 |
{ |
| 115 |
if (/^\#/) { next; } |
| 116 |
# example: rmark5 - tRNA RF00005 24 70 911231 911278 911214 911279 911237 911273 1017549 + 0.0029 20.6 0.0 - |
| 117 |
|
| 118 |
@fields = split(' ', $_, 16); |
| 119 |
$target = $fields[0]; |
| 120 |
$target_from = $fields[6]; |
| 121 |
$target_to = $fields[7]; |
| 122 |
$pval = $fields[14]; |
| 123 |
$bitscore = $fields[15]; |
| 124 |
printf TMPOUTFILE "%10g %10.1f %10d %10d %20s %35s\n", $pval, $bitscore, $target_from, $target_to, $target, $msaname; |
| 125 |
} |
| 126 |
|
| 127 |
if($do_debug == 0) { |
| 128 |
unlink "$resultdir/$msaname.tmp"; |
| 129 |
unlink "$resultdir/$msaname.search"; |
| 130 |
if($do_fetch_models) { unlink "$resultdir/$msaname.hmm"; } |
| 131 |
if($do_posonly) { |
| 132 |
unlink "$resultdir/$msaname.pfa"; |
| 133 |
unlink "$resultdir/$msaname.sfetch"; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
$runtime += time(); |
| 138 |
open(TIME, ">" . "$resultdir/$msaname.time"); |
| 139 |
printf TIME "$msaname $runtime seconds\n"; |
| 140 |
close(TIME); |
| 141 |
} |
| 142 |
close TABLE; |
| 143 |
close OUTFILE; |
| 144 |
close TMPOUTFILE; |
| 145 |
|
| 146 |
# Use 'rmark-idpositives.pl' to identify positives in the temporary output file to |
| 147 |
# create the permanent output file. First, we need to sort by score. |
| 148 |
$command = "sort -g $tmpoutfile > $sorttmpoutfile"; |
| 149 |
$status = system("$command"); |
| 150 |
if ($status != 0) { die "FAILED: $command"; } |
| 151 |
|
| 152 |
$command = "perl $idscript $posfile $sorttmpoutfile > $outfile"; |
| 153 |
$status = system("$command"); |
| 154 |
if ($status != 0) { die "FAILED: $command"; } |
| 155 |
|