Debian Codegraph @

hmmer/profmark/x-hmmsearch

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # Do a chunk of a profmark benchmark, for hmmsearch.
4 #
5 # Usage: x-hmmsearch <top_builddir> <top_srcdir> <resultdir> <tblfile> <msafile> <fafile> <outfile>
6 # Example: ./x-hmmsearch ~/releases/hmmer-3.0/build-icc-mpi ~/releases/hmmer-3.0 testdir test.tbl pmark.train.msa pmark.test.fa test.out
7 #
8 # This script is normally called by pmark_master.py, and its command
9 # line syntax is tied to pmark_master.py. It can also be run by itself
10 # (for testing, for example).
11 #
12 # Inputs:
13 # <top_builddir> : top level directory for the executables to be benchmarked.
14 # program(s) will be run as ${top_builddir}/${program_name}
15 # (Easel miniapps are assumed to be in your $PATH.)
16 # <top_srcdir> : top level directory for finding scripts or data files. (Unused here.)
17 # <resultdir> : name of a tmp directory to put tmpfiles in
18 # <tblfile> : file with list of MSA names to use as queries - fetched from <msafile>
19 # <msafile> : query MSAs are fetched from this file
20 # <fafile> : each query MSA is searched against these synthetic positives and negatives
21 #
22 # Outputs:
23 # <outfile> : output data for this chunk; one line per reasonably-significant hit at permissive E-value
24 # threshold (we want to be able to see performance at up to 10-100 fp/query or so)
25 # Each line has: <pval> <bitscore> <target_name> <msa_name>
26 #
27 # Normally, pmark-master creates <resultdir>, using an input arg from
28 # the user; creates <tblfile> as "<resultdir>/tbl.<n>", one
29 # parallelized chunk of the MSAs in the benchmark; and creates
30 # <outfile> as "<resultdir>/tbl.{n}.out". The <msafile> and <fafile>
31 # were created by create-profmark with a shared benchmark_prefix name,
32 # e.g. "pmark.{train.msa,test.fa}".
33 #
34 # For testing, you can make any list of MSA names you want (in
35 # "test.tbl" for example), make a tmp dir ("testdir", for example),
36 # and direct the output to any file you want ("test.out" for example).
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