| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
# Do a piece of a rmark benchmark, for blastn (NCBI blast). |
| 4 |
# |
| 5 |
# This script is normally called by rmark-master.pl; its command line |
| 6 |
# syntax is tied to rmark-master.pl. |
| 7 |
# x-blastn doesn't use <modeldir>, but it's passed in so that |
| 8 |
# rmark-master.pl can use a consistent command line structure for |
| 9 |
# all search programs (cmsearch uses it, for example). |
| 10 |
# |
| 11 |
# Usage: x-blastn <execdir> <scriptdir> <modeldir> <resultdir> <optsfile> <tblfile> <msafile> <posfile> <fafile> <outfile> |
| 12 |
# Example: ./x-blastn /usr/local/blast/bin/ ../rmark/ models testdir blastn-w7.opts test.tbl rmark3.msa rmark3.pos test.fa test.out |
| 13 |
# |
| 14 |
# Command-line options: |
| 15 |
# -P : run a positive-only benchmark, only each family's positive sequences will be searched |
| 16 |
# |
| 17 |
# SRE, Tue Apr 20 10:32:49 2010 [Janelia] |
| 18 |
# SVN $Id$ |
| 19 |
# |
| 20 |
use Getopt::Std; |
| 21 |
getopts('P'); |
| 22 |
$do_posonly = 0; |
| 23 |
if (defined $opt_P) { $do_posonly = 1; } |
| 24 |
|
| 25 |
$usage = "Usage: x-blastn [options]\n\t<blastn executable>\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"; |
| 26 |
$options_usage = "Options:\n\t"; |
| 27 |
$options_usage .= " -P : run a positive-only benchmark, only each family's positive sequences will be searched\n\t"; |
| 28 |
if(scalar(@ARGV) != 10) { printf("$usage\n$options_usage"); exit(1); } |
| 29 |
|
| 30 |
($execdir, $scriptdir, $modeldir, $resultdir, $optsfile, $tblfile, $msafile, $posfile, $fafile, $outfile) = @ARGV; |
| 31 |
$tmpoutfile = $outfile . ".tmp"; |
| 32 |
$sorttmpoutfile = $outfile . ".tmp.sort"; |
| 33 |
|
| 34 |
$idscript = "$scriptdir/rmark-idpositives.pl"; |
| 35 |
$blastn = "$execdir/blastn"; |
| 36 |
$afetch = "$execdir/esl-afetch"; |
| 37 |
$sfetch = "$execdir/esl-sfetch"; |
| 38 |
$reformat = "$execdir/esl-reformat"; |
| 39 |
if(! -e $afetch) { |
| 40 |
$afetch = "$execdir/../easel/miniapps/esl-afetch"; |
| 41 |
if(! -e $afetch) { die "$afetch does not exist, nor $execdir/$afetch"; } |
| 42 |
} |
| 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 |
if(! -e $reformat) { |
| 48 |
$reformat = "$execdir/../easel/miniapps/esl-reformat"; |
| 49 |
if(! -e $reformat) { die "$reformat does not exist"; } |
| 50 |
} |
| 51 |
if(! -e $blastn) { |
| 52 |
$blastn = "/groups/eddy/home/nawrockie/bin/blastn"; |
| 53 |
if(! -e $blastn) { die "$blastn does not exist"; } |
| 54 |
} |
| 55 |
|
| 56 |
if (! -d $execdir) { die "didn't find executable directory $execdir"; } |
| 57 |
if (! -d $scriptdir) { die "didn't find script directory $scriptdir"; } |
| 58 |
if (! -e $resultdir) { die "$resultdir doesn't exist"; } |
| 59 |
if (! -e $posfile) { die "$posfile doesn't exist"; } |
| 60 |
if (! -e $idscript) { die "positive identification script $idscript doesn't exist"; } |
| 61 |
if (! -e $optsfile) { die "options file $optsfile doesn't exist"; } |
| 62 |
|
| 63 |
# read options file |
| 64 |
open(OPTS, $optsfile) || die "couldn't open options file $optsfile"; |
| 65 |
$searchopts = <OPTS>; |
| 66 |
close(OPTS); |
| 67 |
chomp $searchopts; |
| 68 |
|
| 69 |
open(OUTFILE,">$outfile") || die "failed to open $outfile"; |
| 70 |
open(TMPOUTFILE,">$tmpoutfile") || die "failed to open $tmpoutfile"; |
| 71 |
open(TABLE, "$tblfile") || die "failed to open $tblfile"; |
| 72 |
$orig_fafile = $fafile; |
| 73 |
while (<TABLE>) |
| 74 |
{ |
| 75 |
$runtime = -1 * time(); |
| 76 |
|
| 77 |
($msaname) = split; |
| 78 |
|
| 79 |
# fetch the msa |
| 80 |
$command = "$afetch -o $resultdir/$msaname.sto $msafile $msaname > /dev/null"; |
| 81 |
$status = system("$command"); |
| 82 |
if ($status != 0) { die "FAILED: $command"; } |
| 83 |
|
| 84 |
# generate the query fasta file |
| 85 |
$command = "$reformat fasta $resultdir/$msaname.sto > $resultdir/$msaname.query"; |
| 86 |
$status = system("$command"); |
| 87 |
if ($status != 0) { die "FAILED: $command"; } |
| 88 |
|
| 89 |
# run blast |
| 90 |
$command = "$blastn -task blastn $searchopts -db $fafile -query $resultdir/$msaname.query -outfmt 7 -num_threads 1 -out $resultdir/$msaname.tmp"; |
| 91 |
$status = system("$command"); |
| 92 |
if ($status != 0) { die "FAILED: $command"; } |
| 93 |
|
| 94 |
open(OUTPUT, "$resultdir/$msaname.tmp") || die "FAILED: to open $resultdir/$msaname.tmp tabular output file"; |
| 95 |
|
| 96 |
while (<OUTPUT>) |
| 97 |
{ |
| 98 |
if (/^\#/) { next; } |
| 99 |
@fields = split(' ', $_, 12); |
| 100 |
$target = $fields[1]; |
| 101 |
$target_from = $fields[8]; |
| 102 |
$target_to = $fields[9]; |
| 103 |
$bitscore = $fields[11]; |
| 104 |
$evalue = $fields[10]; |
| 105 |
printf TMPOUTFILE "%10g %10.1f %10d %10d %20s %35s\n", $evalue, $bitscore, $target_from, $target_to, $target, $msaname; |
| 106 |
} |
| 107 |
|
| 108 |
#unlink "$resultdir/$msaname.tmp"; |
| 109 |
unlink "$resultdir/$msaname.sto"; |
| 110 |
unlink "$resultdir/$msaname.query"; |
| 111 |
|
| 112 |
$runtime += time(); |
| 113 |
open(TIME, ">" . "$resultdir/$msaname.time"); |
| 114 |
printf TIME "$msaname $runtime seconds\n"; |
| 115 |
close(TIME); |
| 116 |
} |
| 117 |
close TABLE; |
| 118 |
close OUTFILE; |
| 119 |
close TMPOUTFILE; |
| 120 |
|
| 121 |
# Use 'rmark-idpositives.pl' to identify positives in the temporary output file to |
| 122 |
# create the permanent output file. First, we need to sort by score. |
| 123 |
|
| 124 |
$command = "sort -g $tmpoutfile > $sorttmpoutfile"; |
| 125 |
$status = system("$command"); |
| 126 |
if ($status != 0) { die "FAILED: $command"; } |
| 127 |
|
| 128 |
$command = "perl $idscript $posfile $sorttmpoutfile > $outfile"; |
| 129 |
$status = system("$command"); |
| 130 |
if ($status != 0) { die "FAILED: $command"; } |
| 131 |
|