Debian Codegraph @

hmmer/profmark/pmark-master.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 import sys
4 import os
5 import subprocess
6
7 usage = 'pmark-master.py <top_builddir> <top_srcdir> <resultdir> <ncpu> <benchmark_pfx> <pmark_script>'
8
9 if len(sys.argv) != 7: sys.exit('Incorrect number of cmdline args.\nUsage: {}'.format(usage))
10
11 (top_builddir, top_srcdir, resultdir, ncpu, benchmark_pfx, pmark_script) = sys.argv[1:]
12
13 tblfile = benchmark_pfx + '.tbl'
14 msafile = benchmark_pfx + '.train.msa'
15 fafile = benchmark_pfx + '.test.fa'
16
17 if os.path.exists(resultdir): sys.exit('results directory {} already exists'.format(resultdir))
18 if not os.path.isdir(top_builddir): sys.exit("didn't find top_builddir at {}".format(top_builddir))
19 if not os.path.isdir(top_srcdir): sys.exit("didn't find top_srcdir at {}".format(top_srcdir))
20 if not os.path.isfile(tblfile): sys.exit('pmark tbl file {} not found'.format(tblfile))
21 if not os.path.isfile(msafile): sys.exit('pmark training MSA file {} not found'.format(msafile))
22 if not os.path.isfile(msafile + '.ssi'): sys.exit("msafile {} needs to have an SSI index.\nRun esl-afetch --index on it to create one.".format(msafile))
23 if not os.path.isfile(fafile): sys.exit('pmark test sequence FASTA file {} not found'.format(fafile))
24 if not os.access(pmark_script, os.X_OK): sys.exit('driver script {} not found or not executable'.format(pmark_script))
25
26 os.mkdir(resultdir)
27 ncpu = int(ncpu)
28
29 # Read the master table, for MSAs with successful splits
30 #
31 msaname = []
32 alen = {}
33 n = 0
34 with open(tblfile) as tblfp:
35 for line in tblfp:
36 if line[0] == '#': continue
37 fields = line.split()
38
39 if fields[7] == 'ok':
40 msaname.append(fields[0])
41 alen[fields[0]] = int(fields[2])
42 n += 1
43
44 # Sort the list of MSA names by length of alignment (in columns),
45 # to help with load balancing; spread largest MSAs across the subtbls
46 #
47 msaname.sort(key=lambda s:alen[s], reverse=True)
48
49
50 # Split the list into <ncpu> subtables
51 #
52 subtbl =[ [] for c in range(ncpu) ]
53 for i in range(n):
54 subtbl[i % ncpu].append(msaname[i])
55
56 # Write the <ncpu> subtables
57 #
58 for c in range(ncpu):
59 with open('{0}/tbl.{1}'.format(resultdir, c), 'w') as f:
60 for s in subtbl[c]:
61 f.write(s + '\n')
62
63 # Write a SLURM job array script
64 #
65 with open('{0}/{0}.sh'.format(resultdir), 'w') as f:
66 cmd = '{0} {1} {2} {3} {3}/tbl.${{SLURM_ARRAY_TASK_ID}} {4} {5} {3}/tbl.${{SLURM_ARRAY_TASK_ID}}.out'.format(pmark_script, top_builddir, top_srcdir, resultdir, msafile, fafile)
67
68 f.write('#!/bin/bash\n')
69 f.write('#SBATCH -t 6-00:00\n') # 6 days
70 f.write('#SBATCH --mem 4000\n')
71 f.write('#SBATCH -p eddy\n')
72 f.write('#SBATCH -c 1\n') # 1 core
73 f.write('#SBATCH -N 1\n') # 1 node
74 f.write('#SBATCH -o {}/tbl.%a.slurm\n'.format(resultdir))
75 f.write(cmd + '\n')
76
77 # Submit the job array
78 #
79 cmd = 'sbatch --array=0-{0} {1}/{1}.sh'.format(ncpu-1, resultdir)
80 subprocess.run(cmd.split())
81
82