| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
import sys |
| 40 |
import os |
| 41 |
import subprocess |
| 42 |
|
| 43 |
usage = "x-hmmsearch <top_builddir> <top_srcdir> <resultdir> <tblfile> <msafile> <fafile> <outfile>" |
| 44 |
|
| 45 |
if len(sys.argv) != 8: sys.exit('Incorrect number of cmdline args.\nUsage: {}'.format(usage)) |
| 46 |
|
| 47 |
(top_builddir, top_srcdir, resultdir, tblfile, msafile, fafile, outfile) = sys.argv[1:] |
| 48 |
|
| 49 |
|
| 50 |
hmmbuild = '{}/src/hmmbuild'.format(top_builddir); |
| 51 |
hmmsearch = '{}/src/hmmsearch'.format(top_builddir); |
| 52 |
buildopts = ''; |
| 53 |
searchopts = '-E 200 --cpu 1'; |
| 54 |
|
| 55 |
if not os.path.isdir(top_builddir): sys.exit("didn't find top_builddir at {}".format(top_builddir)) |
| 56 |
if not os.path.isdir(top_srcdir): sys.exit("didn't find top_srcdir at {}".format(top_srcdir)) |
| 57 |
if not os.path.isdir(resultdir): sys.exit("didn't find resultdir at {}".format(resultdir)) |
| 58 |
if not os.path.isfile(tblfile): sys.exit("didn't find tblfile at {}".format(tblfile)) |
| 59 |
if not os.path.isfile(msafile): sys.exit("didn't find msafile at {}".format(msafile)) |
| 60 |
if not os.path.isfile(fafile): sys.exit("didn't find fafile at {}".format(fafile)) |
| 61 |
if not os.access(hmmbuild, os.X_OK): sys.exit("didn't find executable hmmbuild at {}".format(hmmbuild)) |
| 62 |
if not os.access(hmmsearch,os.X_OK): sys.exit("didn't find executable hmmsearch at {}".format(hmmsearch)) |
| 63 |
|
| 64 |
if not os.path.isfile('{}.ssi'.format(msafile)): sys.exit("msafile {} needs to have an SSI index.\nRun esl-afetch --index on it to create one.".format(msafile)) |
| 65 |
|
| 66 |
tblfp = open(tblfile) |
| 67 |
outfp = open(outfile, "w"); |
| 68 |
if not tblfp: sys.exit("failed to open tblfile {} for reading".format(tblfile)) |
| 69 |
if not outfp: sys.exit("failed to open outfile {} for writing".format(outfile)) |
| 70 |
|
| 71 |
for line in tblfp: |
| 72 |
msaname = line.split(None, 1)[0] |
| 73 |
|
| 74 |
cmd = 'esl-afetch -o {0}/{1}.sto {2} {1}'.format(resultdir, msaname, msafile) |
| 75 |
r = subprocess.run(cmd.split(), capture_output=True, encoding='utf-8') |
| 76 |
if r.returncode: sys.exit('FAILED: {}\n{}'.format(cmd, r.stderr)) |
| 77 |
|
| 78 |
cmd = '{0} {1} {2}/{3}.hmm {2}/{3}.sto'.format(hmmbuild, buildopts, resultdir, msaname) |
| 79 |
r = subprocess.run(cmd.split(), capture_output=True, encoding='utf-8') |
| 80 |
if r.returncode: sys.exit('FAILED: {}\n{}'.format(cmd, r.stderr)) |
| 81 |
|
| 82 |
cmd = '{0} {1} --tblout {2}/{3}.tmp {2}/{3}.hmm {4}'.format(hmmsearch, searchopts, resultdir, msaname, fafile) |
| 83 |
r = subprocess.run(cmd.split(), stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, encoding='utf-8') |
| 84 |
if r.returncode: sys.exit('FAILED: {}\n{}'.format(cmd, r.stderr)) |
| 85 |
|
| 86 |
resfp = open('{0}/{1}.tmp'.format(resultdir, msaname)) |
| 87 |
if not resfp: sys.exit('failed to open hmmsearch .tblout file {0}/{1}.tmp for reading'.format(resultdir, msaname)) |
| 88 |
for line in resfp: |
| 89 |
if line[0] == '#': continue |
| 90 |
fields = line.split() |
| 91 |
|
| 92 |
target = fields[0] |
| 93 |
pval = fields[4] |
| 94 |
bitscore = fields[5] |
| 95 |
|
| 96 |
outfp.write('{0} {1} {2} {3}\n'.format(pval, bitscore, target, msaname)) |
| 97 |
resfp.close() |
| 98 |
|
| 99 |
os.remove('{0}/{1}.hmm'.format(resultdir, msaname)) |
| 100 |
os.remove('{0}/{1}.sto'.format(resultdir, msaname)) |
| 101 |
os.remove('{0}/{1}.tmp'.format(resultdir, msaname)) |
| 102 |
|
| 103 |
tblfp.close() |
| 104 |
outfp.close() |
| 105 |
|
| 106 |
|