| 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 |
import sys |
| 37 |
import os |
| 38 |
import shutil |
| 39 |
import subprocess |
| 40 |
import re |
| 41 |
import argparse |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
parser = argparse.ArgumentParser(description='generate .tex inclusions for user guide') |
| 46 |
parser.add_argument('-t', '--tutupdate', action='store_true') |
| 47 |
parser.add_argument( '--noclean', action='store_true') |
| 48 |
parser.add_argument('top_builddir', nargs='?', default='../../..') |
| 49 |
parser.add_argument('top_srcdir', nargs='?', default='../../..') |
| 50 |
args = parser.parse_args() |
| 51 |
top_builddir = os.path.abspath(args.top_builddir) |
| 52 |
top_srcdir = args.top_srcdir |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
if (not os.path.exists('{0}/src/hmmscan'.format(top_builddir))) or (not os.path.exists('{0}/src/hmmsearch'.format(top_builddir))): |
| 57 |
sys.exit('no programs found? ./configure; make first') |
| 58 |
|
| 59 |
|
| 60 |
print('gen-inclusions.py : a fiddly script to generate .tex inclusions for user guide') |
| 61 |
print('cross your fingers...') |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
if args.tutupdate: |
| 67 |
subprocess.run('wget -O fn3.sto https://pfam.xfam.org/family/fn3/alignment/seed', shell=True, cwd='{0}/tutorial'.format(top_srcdir)) |
| 68 |
subprocess.run('wget -O Pkinase.sto https://pfam.xfam.org/family/Pkinase/alignment/seed', shell=True, cwd='{0}/tutorial'.format(top_srcdir)) |
| 69 |
subprocess.run('wget -O 7LESS_DROME http://www.uniprot.org/uniprot/P13368.txt', shell=True, cwd='{0}/tutorial'.format(top_srcdir)) |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
tutorial_files = [ '7LESS_DROME', 'HBB_HUMAN', 'MADE1.sto', 'Pkinase.sto', 'dna_target.fa', 'fn3.sto', 'globins45.fa' ] |
| 77 |
for file in tutorial_files: |
| 78 |
if not os.path.exists(file): os.symlink('{0}/tutorial/{1}'.format(top_srcdir, file), file) |
| 79 |
for file in ['globins4.sto']: |
| 80 |
if not os.path.exists(file): shutil.copyfile('{0}/tutorial/{1}'.format(top_srcdir, file), file) |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
swissprot_dir = os.path.expanduser('~/data/Uniprot') |
| 88 |
if os.path.exists(swissprot_dir): |
| 89 |
if not os.path.exists('uniprot_sprot.fasta'): os.symlink('{0}/uniprot_sprot.fasta'.format(swissprot_dir), 'uniprot_sprot.fasta') |
| 90 |
if not os.path.exists('relnotes.txt'): os.symlink('{0}/relnotes.txt'.format(swissprot_dir), 'relnotes.txt') |
| 91 |
else: |
| 92 |
subprocess.run('wget ftp://ftp.uniprot.org/pub/databases/uniprot/current_release/knowledgebase/complete/uniprot_sprot.fasta.gz', shell=True) |
| 93 |
subprocess.run('wget ftp://ftp.uniprot.org/pub/databases/uniprot/current_release/relnotes.txt', shell=True) |
| 94 |
subprocess.run('gunzip -f uniprot_sprot.fasta.gz', shell=True) |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
def uniprot_relnotes(deffp): |
| 102 |
print('parsing uniprot release info...') |
| 103 |
|
| 104 |
with open('relnotes.txt', 'r') as f: |
| 105 |
content = f.read() |
| 106 |
m = re.search(r'UniProt Release (\S+)', content) |
| 107 |
if not m: sys.exit('failed to identify UniProt release code') |
| 108 |
uniprot_release = m.group(1) |
| 109 |
|
| 110 |
m = re.search(r'UniProtKB/Swiss-Prot:\s*(\S+) entries', content) |
| 111 |
if not m: sys.exit('failed to identify UniProt/Swiss-Prot nseq') |
| 112 |
uniprot_nseq = m.group(1) |
| 113 |
|
| 114 |
print(r'\newcommand{{\UNIrelease}}{{{0}}}'.format(re.sub('_', r'\_', uniprot_release)), file=deffp) |
| 115 |
print(r'\newcommand{{\UNInseq}}{{{0}}}'.format(uniprot_nseq), file=deffp) |
| 116 |
print('', file=deffp) |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
def hmmscan_noargs(deffp): |
| 124 |
print('running hmmscan (with no args)...') |
| 125 |
r = subprocess.run('hmmscan -h', |
| 126 |
shell=True, stdout=subprocess.PIPE, encoding='utf-8', |
| 127 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 128 |
|
| 129 |
m = re.match(r'((?:#.*\n)+)', r.stdout) |
| 130 |
with open('hmmscan-noargs.out', 'w') as f: |
| 131 |
print(m.group(1), file=f, end='') |
| 132 |
|
| 133 |
m = re.search('# HMMER\s+(\S+)\s+\((.+?)\);', r.stdout) |
| 134 |
print(r'\newcommand{{\HMMERversion}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 135 |
print(r'\newcommand{{\HMMERdate}}{{{0}}}'.format(m.group(2)), file=deffp) |
| 136 |
print('', file=deffp) |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
def hmmbuild_noargs(): |
| 146 |
print('running hmmbuild (with no args)...') |
| 147 |
r = subprocess.run('hmmbuild > hmmbuild-noargs.out', |
| 148 |
shell=True, stdout=subprocess.PIPE, encoding='utf-8', |
| 149 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
def hmmbuild_globins(deffp): |
| 157 |
print('running hmmbuild globins4.hmm globins4.sto...') |
| 158 |
r = subprocess.run('hmmbuild globins4.hmm globins4.sto', |
| 159 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 160 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 161 |
|
| 162 |
with open("hmmbuild-globins.out", "w") as f: |
| 163 |
print(r.stdout, file=f, end='') |
| 164 |
|
| 165 |
m = re.search(r'^\d+\s+\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\S+)', r.stdout, flags=re.MULTILINE) |
| 166 |
if not m: sys.exit("bad pattern match to hmmbuild output") |
| 167 |
print(r"\newcommand{{\BGLnseq}}{{{0}}}".format(m.group(1)), file=deffp) |
| 168 |
print(r"\newcommand{{\BGLalen}}{{{0}}}".format(m.group(2)), file=deffp) |
| 169 |
print(r"\newcommand{{\BGLmlen}}{{{0}}}".format(m.group(3)), file=deffp) |
| 170 |
print(r"\newcommand{{\BGLgaps}}{{{0}}}".format(int(m.group(2))-int(m.group(3))), file=deffp) |
| 171 |
print(r"\newcommand{{\BGLeffn}}{{{0}}}".format(m.group(4)), file=deffp) |
| 172 |
print(r"\newcommand{{\BGLre}}{{{0}}}".format(m.group(5)), file=deffp) |
| 173 |
print('', file=deffp) |
| 174 |
|
| 175 |
with open('globins4.hmm', 'r') as f: |
| 176 |
content = f.read() |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
content = re.sub('(\nHMM\\s+A\\s+C.+\n(?:.+\n){7})(?s:.+)\n((?:.+\n){3}//)', '\\1...\n\\2', content) |
| 181 |
content = re.sub(r'(HMM(?:\s+\S\s{3}){7})(?:\s+\S\s{3}){11}(.+)', r'\1 ... \2', content) |
| 182 |
content = re.sub(r'^(\s+COMPO(?:\s+\S+){7})(?:\s+\S+){11}(.+)$', r'\1 ... \2', content, flags=re.MULTILINE) |
| 183 |
content = re.sub(r'^(\s+\d+(?:\s+\S+){7})(?:\s+\S+){11}(.+)$', r'\1 ... \2', content, flags=re.MULTILINE) |
| 184 |
content = re.sub(r'^((?:\s+[\d\.*]+){7})(?:\s+\S+){11}((?:\s+[\d\.*]+){2})$', r'\1 ... \2', content, flags=re.MULTILINE) |
| 185 |
with open('hmmbuild-globins.out2', 'w') as f: |
| 186 |
print(content, file=f, end='') |
| 187 |
|
| 188 |
|
| 189 |
with open('globins4.hmm', 'r') as f: |
| 190 |
content = f.read() |
| 191 |
m = re.match(r'HMMER3/(\S)\s+(\[.+\])', content) |
| 192 |
print(r'\newcommand{{\HMMERfmtversion}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 193 |
print(r'\newcommand{{\HMMERsavestamp}}{{{0}}}'.format(m.group(2)), file=deffp) |
| 194 |
print('', file=deffp) |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
def hmmsearch_globins(deffp): |
| 200 |
print('running hmmsearch globins4.hmm uniprot_sprot.fasta...') |
| 201 |
r = subprocess.run('hmmsearch globins4.hmm uniprot_sprot.fasta', |
| 202 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 203 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 204 |
|
| 205 |
m = re.match('(.+Scores for complete sequences.+?)\n', r.stdout, flags=re.DOTALL) |
| 206 |
if not m: sys.exit('bad first pattern match to hmmsearch output') |
| 207 |
with open("hmmsearch-globins.out", "w") as f: |
| 208 |
print(m.group(1), file=f) |
| 209 |
|
| 210 |
m = re.search('\n(\\s+--- full sequence ---(.+\n){9})', r.stdout) |
| 211 |
if not m: sys.exit('bad top hits pattern match to hmmsearch output') |
| 212 |
with open("hmmsearch-globins.out2", "w") as f: |
| 213 |
print(m.group(1), file=f, end='') |
| 214 |
|
| 215 |
m = re.search(r'\n(Internal pipeline statistics.+)', r.stdout, flags=re.DOTALL) |
| 216 |
if not m: sys.exit('bad xpipeline stats pattern match to hmmsearch output') |
| 217 |
with open("hmmsearch-globins.out3", "w") as f: |
| 218 |
print(m.group(1), file=f, end='') |
| 219 |
|
| 220 |
|
| 221 |
m = re.search(r'^\s*([0-9\.e-]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+sp\|\S+\|(\S+)', r.stdout, flags=re.MULTILINE) |
| 222 |
if not m: sys.exit('bad third pattern match to hmmsearch output') |
| 223 |
print(r'\newcommand{{\SGUevalue}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 224 |
print(r'\newcommand{{\SGUbitscore}}{{{0}}}'.format(m.group(2)), file=deffp) |
| 225 |
print(r'\newcommand{{\SGUbias}}{{{0}}}'.format(m.group(3)), file=deffp) |
| 226 |
print(r'\newcommand{{\SGUorigscore}}{{{0:.1f}}}'.format(float(m.group(2)) + float(m.group(3))), file=deffp) |
| 227 |
print(r'\newcommand{{\SGUdombitscore}}{{{0}}}'.format(m.group(5)), file=deffp) |
| 228 |
print(r'\newcommand{{\SGUseqname}}{{{0}}}'.format(re.sub('_', r'\_', m.group(9))), file=deffp) |
| 229 |
|
| 230 |
|
| 231 |
assert m.group(2) != m.group(5), "guide assumes that full vs. best 1 domain bit scores for top globin differ slightly" |
| 232 |
|
| 233 |
m = re.search(r'Passed MSV filter:\s+\d+\s+\((\S+?)\)', r.stdout) |
| 234 |
print(r'\newcommand{{\SGUmsvpass}}{{{0:.1f}}}'.format(100 * round(float(m.group(1)), 3)), file=deffp) |
| 235 |
|
| 236 |
m = re.search(r'Passed bias filter:\s+(\d+)', r.stdout) |
| 237 |
print(r'\newcommand{{\SGUbiaspass}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 238 |
|
| 239 |
m = re.search(r'Passed Vit filter:\s+(\d+)', r.stdout) |
| 240 |
print(r'\newcommand{{\SGUvitpass}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 241 |
|
| 242 |
m = re.search(r'Passed Fwd filter:\s+(\d+)', r.stdout) |
| 243 |
print(r'\newcommand{{\SGUfwdpass}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 244 |
|
| 245 |
m = re.search(r'Elapsed: \d+:\d+:(\S+)', r.stdout) |
| 246 |
print(r'\newcommand{{\SGUelapsed}}{{{0:.1f}}}'.format(float(m.group(1))), file=deffp) |
| 247 |
print('', file=deffp) |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
def hmmsearch_fn3_sevenless(deffp): |
| 258 |
print('running hmmbuild, then hmmsearch fn3.hmm 7LESS_DROME...') |
| 259 |
|
| 260 |
r = subprocess.run('hmmbuild fn3.hmm fn3.sto', |
| 261 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 262 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 263 |
|
| 264 |
r = subprocess.run('hmmsearch fn3.hmm 7LESS_DROME', |
| 265 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 266 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 267 |
|
| 268 |
m = re.search('\n(\\s+--- full sequence ---(?:.+\n){4})', r.stdout) |
| 269 |
if not m: sys.exit('bad first pattern match to fn3 hmmsearch output') |
| 270 |
with open('hmmsearch-fn3-sevenless.out', 'w') as f: |
| 271 |
print(m.group(1), file=f, end='') |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
m = re.search(r'^\s*([0-9\.e-]+)\s+([0-9\.]+)\s+([0-9\.]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\S+)', r.stdout, flags=re.MULTILINE) |
| 276 |
if not m: sys.exit('bad second pattern match to fn3 hmmsearch output') |
| 277 |
print(r'\newcommand{{\SFSevalue}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 278 |
print(r'\newcommand{{\SFSbitscore}}{{{0}}}'.format(m.group(2)), file=deffp) |
| 279 |
print(r'\newcommand{{\SFSdomevalue}}{{{0}}}'.format(m.group(4)), file=deffp) |
| 280 |
print(r'\newcommand{{\SFSdombitscore}}{{{0}}}'.format(m.group(5)), file=deffp) |
| 281 |
print(r'\newcommand{{\SFSexpdom}}{{{0}}}'.format(m.group(7)), file=deffp) |
| 282 |
print(r'\newcommand{{\SFSndom}}{{{0}}}'.format(m.group(8)), file=deffp) |
| 283 |
print('', file=deffp) |
| 284 |
|
| 285 |
m = re.search(r'^(Domain annotation.+:\s*)$', r.stdout, flags=re.MULTILINE) |
| 286 |
if not m: sys.exit('bad domain section line pattern match to fn3 hmmsearch output') |
| 287 |
with open('hmmsearch-fn3-sevenless.out2', 'w') as f: |
| 288 |
print(m.group(1), file=f, end='') |
| 289 |
|
| 290 |
m = re.search('\n(>> 7LESS_DROME.+\n.+\n.+\n((?:\\s*\\d+.+\n)+))', r.stdout) |
| 291 |
if not m: sys.exit('bad domain table pattern match to fn3 hmmsearch output') |
| 292 |
with open('hmmsearch-fn3-sevenless.out3', 'w') as f: |
| 293 |
print(m.group(1), file=f, end='') |
| 294 |
tbl = m.group(2) |
| 295 |
|
| 296 |
m = re.search(r'\n( ==\s+domain\s+2.+? PP\s*)\n', r.stdout, flags=re.DOTALL) |
| 297 |
if not m: sys.exit('bad alignment pattern match to fn3 hmmsearch output') |
| 298 |
with open('hmmsearch-fn3-sevenless.out4', 'w') as f: |
| 299 |
print(m.group(1), file=f, end='') |
| 300 |
|
| 301 |
|
| 302 |
domtbl1 = [] |
| 303 |
for line in tbl.splitlines(): |
| 304 |
fields = line.split() |
| 305 |
dom = { 'idx' : int(fields[0]), |
| 306 |
'sigchar' : fields[1], |
| 307 |
'bitscore' : float(fields[2]), |
| 308 |
'c-evalue' : float(fields[4]), |
| 309 |
'i-evalue' : float(fields[5]), |
| 310 |
'hmmfrom' : int(fields[6]), |
| 311 |
'hmmto' : int(fields[7]), |
| 312 |
'envfrom' : int(fields[12]), |
| 313 |
'envto' : int(fields[13]) } |
| 314 |
domtbl1.append(dom) |
| 315 |
|
| 316 |
return domtbl1 |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
def hmmsearch_fn3_uniprot(deffp, domtbl1): |
| 323 |
print('running hmmsearch fn3.hmm uniprot_sprot.fasta...') |
| 324 |
|
| 325 |
r = subprocess.run('hmmsearch fn3.hmm uniprot_sprot.fasta', |
| 326 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 327 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 328 |
|
| 329 |
|
| 330 |
m = re.search('\n(>> \S+\|7LESS_DROME.+\n.+\n.+\n((?:\\s*\\d+.+\n)+))', r.stdout) |
| 331 |
if not m: sys.exit('bad pattern match to fn3 hmmsearch output') |
| 332 |
with open('hmmsearch-fn3-uniprot.out', 'w') as f: |
| 333 |
print(m.group(1), file=f, end='') |
| 334 |
tbl = m.group(2) |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
domtbl2 = [] |
| 340 |
for line in tbl.splitlines(): |
| 341 |
fields = line.split() |
| 342 |
dom = { 'idx' : int(fields[0]), |
| 343 |
'sigchar' : fields[1], |
| 344 |
'bitscore' : float(fields[2]), |
| 345 |
'c-evalue' : float(fields[4]), |
| 346 |
'i-evalue' : float(fields[5]), |
| 347 |
'hmmfrom' : int(fields[6]), |
| 348 |
'hmmto' : int(fields[7]), |
| 349 |
'envfrom' : int(fields[12]), |
| 350 |
'envto' : int(fields[13]) } |
| 351 |
domtbl2.append(dom) |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
m = re.search(r'^Domain search space\s+\(domZ\):\s+(\d+)\s+\[number of targets reported over threshold\]', r.stdout, flags=re.MULTILINE) |
| 356 |
if not m: sys.exit('bad second pattern match to fn3 hmmsearch output') |
| 357 |
fn3_domZ = int(m.group(1)) |
| 358 |
|
| 359 |
|
| 360 |
bestdom1 = sorted(domtbl1, key=lambda k: k['bitscore'], reverse=True)[0] |
| 361 |
bestdom2 = sorted(domtbl2, key=lambda k: k['bitscore'], reverse=True)[0] |
| 362 |
|
| 363 |
|
| 364 |
lostdoms = [] |
| 365 |
insigdoms = [] |
| 366 |
i = 0 |
| 367 |
for d in range(len(domtbl2)): |
| 368 |
while (domtbl1[i]['envfrom'] != domtbl2[d]['envfrom']): |
| 369 |
lostdoms.append(domtbl1[i]) |
| 370 |
i += 1 |
| 371 |
if (domtbl1[i]['sigchar'] == '!' and domtbl2[d]['sigchar'] == '?'): |
| 372 |
insigdoms.append(domtbl1[i]) |
| 373 |
i += 1 |
| 374 |
assert len(lostdoms) == 2, "userguide assumes two domains are lost from single 7LESS_DROME seq vs. UniProt search" |
| 375 |
assert len(insigdoms) == 2, "userguide assumes two domains changed from ! to ? in single seq vs. UniProt search" |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
assert len(domtbl2) == 7 |
| 382 |
assert domtbl2[0]['i-evalue'] < 0.01 |
| 383 |
assert domtbl2[3]['i-evalue'] < 0.01 |
| 384 |
assert domtbl2[4]['i-evalue'] < 0.01 |
| 385 |
assert domtbl2[5]['i-evalue'] < 0.2 |
| 386 |
assert domtbl2[1]['i-evalue'] > 0.1 and domtbl2[1]['c-evalue'] < 0.01 |
| 387 |
assert domtbl2[6]['i-evalue'] > 0.1 and domtbl2[6]['c-evalue'] < 0.1 |
| 388 |
assert domtbl2[2]['c-evalue'] > 0.1 |
| 389 |
|
| 390 |
print(r'\newcommand{{\SFSmaxdom}}{{{0}}}'.format(bestdom1['idx']), file=deffp) |
| 391 |
print(r'\newcommand{{\SFSmaxdomu}}{{{0}}}'.format(bestdom2['idx']), file=deffp) |
| 392 |
print(r'\newcommand{{\SFSmaxsc}}{{{0:.1f}}}'.format(bestdom1['bitscore']), file=deffp) |
| 393 |
print(r'\newcommand{{\SFSievalue}}{{{0}}}'.format(bestdom1['i-evalue']), file=deffp) |
| 394 |
print(r'\newcommand{{\SFSuievalue}}{{{0:.1e}}}'.format(bestdom2['i-evalue']), file=deffp) |
| 395 |
print(r'\newcommand{{\SFSdomZ}}{{{0}}}'.format(fn3_domZ), file=deffp) |
| 396 |
print(r'\newcommand{{\SFSucevalue}}{{{0:.1e}}}'.format(bestdom2['c-evalue']), file=deffp) |
| 397 |
print(r'\newcommand{{\SFSaidx}}{{{0}}}'.format(lostdoms[0]['idx']), file=deffp) |
| 398 |
print(r'\newcommand{{\SFSascore}}{{{0:.1f}}}'.format(lostdoms[0]['bitscore']), file=deffp) |
| 399 |
print(r'\newcommand{{\SFSaevalue}}{{{0:.2g}}}'.format(lostdoms[0]['i-evalue']), file=deffp) |
| 400 |
print(r'\newcommand{{\SFSauevalue}}{{{0:.0f}}}'.format(lostdoms[0]['i-evalue'] * fn3_domZ), file=deffp) |
| 401 |
print(r'\newcommand{{\SFSacoords}}{{{0}-{1}}}'.format(lostdoms[0]['envfrom'], lostdoms[0]['envto']), file=deffp) |
| 402 |
print(r'\newcommand{{\SFSbidx}}{{{0}}}'.format(lostdoms[1]['idx']), file=deffp) |
| 403 |
print(r'\newcommand{{\SFSbscore}}{{{0:.1f}}}'.format(lostdoms[1]['bitscore']), file=deffp) |
| 404 |
print(r'\newcommand{{\SFSbevalue}}{{{0:.2g}}}'.format(lostdoms[1]['i-evalue']), file=deffp) |
| 405 |
print(r'\newcommand{{\SFSbuevalue}}{{{0:.1f}}}'.format(lostdoms[1]['i-evalue'] * fn3_domZ), file=deffp) |
| 406 |
print(r'\newcommand{{\SFSbcoords}}{{{0}-{1}}}'.format(lostdoms[1]['envfrom'], lostdoms[1]['envto']), file=deffp) |
| 407 |
print(r'\newcommand{{\SFSainsig}}{{{0:.1f}}}'.format(insigdoms[0]['bitscore']), file=deffp) |
| 408 |
print(r'\newcommand{{\SFSbinsig}}{{{0:.1f}}}'.format(insigdoms[1]['bitscore']), file=deffp) |
| 409 |
print('', file=deffp) |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
def sevenless_table(): |
| 414 |
print('parsing domain annotation in 7LESS_DROME...') |
| 415 |
with open('7LESS_DROME', 'r') as f: |
| 416 |
content = f.read() |
| 417 |
domtbl = [] |
| 418 |
for m in re.finditer(r'^(FT\s+DOMAIN\s+\d+\s+\d+\s+Fibronectin.+)\nFT\s+(.+)\n', content, flags=re.MULTILINE): |
| 419 |
domtbl.append('{0} {1}'.format(m.group(1), m.group(2))) |
| 420 |
|
| 421 |
assert len(domtbl) == 7, 'guide assumes that uniprot annotates seven domains in 7LESS_DROME' |
| 422 |
|
| 423 |
with open('sevenless_domains.out', 'w') as f: |
| 424 |
for domline in domtbl: |
| 425 |
print(domline, file=f) |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
def jackhmmer_hbb_uniprot(deffp): |
| 431 |
print('running jackhmmer HBB_HUMAN uniprot_sprot.fasta...') |
| 432 |
|
| 433 |
r = subprocess.run('jackhmmer HBB_HUMAN uniprot_sprot.fasta', |
| 434 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 435 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 436 |
|
| 437 |
m = re.match(r'((?s:.+?)Scores for complete sequences(?:.*\n){10})', r.stdout) |
| 438 |
with open('jackhmmer-hbb-uniprot.out', 'w') as f: |
| 439 |
print(m.group(1), file=f, end='') |
| 440 |
print('...', file=f) |
| 441 |
|
| 442 |
m = re.search(r'\n((?:.*\n){2}\s*------ inclusion threshold ------(?:.*\n){3})', r.stdout) |
| 443 |
with open('jackhmmer-hbb-uniprot.out2', 'w') as f: |
| 444 |
print(m.group(1), file=f, end='') |
| 445 |
|
| 446 |
m = re.search(r'\n((?:@@.*\n)+(?:.*\n)(?:@@.*\n)+)', r.stdout) |
| 447 |
with open('jackhmmer-hbb-uniprot.out3', 'w') as f: |
| 448 |
print(m.group(1), file=f, end='') |
| 449 |
|
| 450 |
m = re.search(r'@@ Included in MSA:\s+(\d+)\s+subsequences\s+\(query\s+\+\s+(\d+) subseqs from \d+ targets', r.stdout) |
| 451 |
print(r'\newcommand{{\JHUninc}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 452 |
print(r'\newcommand{{\JHUnsig}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 453 |
|
| 454 |
m = re.search(r'@@\s+Round:\s+2\s*\n(?s:.+?)(Scores for complete sequences(?:.*\n){8})', r.stdout) |
| 455 |
with open('jackhmmer-hbb-uniprot.out4', 'w') as f: |
| 456 |
print(m.group(1), file=f, end='') |
| 457 |
print('...', file=f) |
| 458 |
|
| 459 |
m = re.search(r""" |
| 460 |
@@\s+Round:\s+2.* # anchor on round 2 part of the output |
| 461 |
(?s: .+?) # accept anything until... |
| 462 |
\n |
| 463 |
( # start what we're grabbing... |
| 464 |
(?: .+\n) {2} # match exactly two preceding lines |
| 465 |
\+.+\n # first + line |
| 466 |
(?: [^\+].+\n ) {1,4}? # up to 1-4 intervening lines |
| 467 |
\+.+\n # a second + line |
| 468 |
(?: [^\+].+\n ) {1,7}? # up to 1-7 intervening lines |
| 469 |
\+.+\n # a third + line |
| 470 |
.+\n # and one trailing line |
| 471 |
) # end of our grab |
| 472 |
""", r.stdout, flags=re.VERBOSE) |
| 473 |
with open('jackhmmer-hbb-uniprot.out5', 'w') as f: |
| 474 |
print('...', file=f) |
| 475 |
print(m.group(1), file=f, end='') |
| 476 |
print('...', file=f) |
| 477 |
|
| 478 |
m = re.search(r""" |
| 479 |
@@\s+Round:\s+2 # anchor on round 2 part of the output |
| 480 |
(?s:.+?) # accept anything until... |
| 481 |
\n |
| 482 |
( # start grab: |
| 483 |
(?:@@.*\n)+ # a block of @@ info |
| 484 |
(?:.*\n) # blank line(s) |
| 485 |
(?:@@.*\n)+ # a second block of @@ info |
| 486 |
) # end grab. |
| 487 |
""", r.stdout, flags=re.VERBOSE) |
| 488 |
with open('jackhmmer-hbb-uniprot.out6', 'w') as f: |
| 489 |
print(m.group(1), file=f, end='') |
| 490 |
|
| 491 |
m = re.search(r""" |
| 492 |
@@\s+Round:\s+4 |
| 493 |
(?s:.+?) |
| 494 |
( |
| 495 |
@@\s+New\s+targets\s+included: |
| 496 |
(?s:.+?) |
| 497 |
//\n |
| 498 |
\[ok\] |
| 499 |
) |
| 500 |
$ |
| 501 |
""", r.stdout, flags=re.VERBOSE) |
| 502 |
with open('jackhmmer-hbb-uniprot.out7', 'w') as f: |
| 503 |
print(m.group(1), file=f, end='') |
| 504 |
|
| 505 |
print('', file=deffp) |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
def hmmscan_sevenless(): |
| 510 |
print('building minifam and running hmmscan on 7LESS_DROME...') |
| 511 |
|
| 512 |
subprocess.run('hmmbuild globins4.hmm globins4.sto', shell=True, stdout=subprocess.DEVNULL, check=True, env={"PATH": "{0}/src".format(top_builddir)}) |
| 513 |
subprocess.run('hmmbuild fn3.hmm fn3.sto', shell=True, stdout=subprocess.DEVNULL, check=True, env={"PATH": "{0}/src".format(top_builddir)}) |
| 514 |
subprocess.run('hmmbuild Pkinase.hmm Pkinase.sto', shell=True, stdout=subprocess.DEVNULL, check=True, env={"PATH": "{0}/src".format(top_builddir)}) |
| 515 |
subprocess.run('cat globins4.hmm fn3.hmm Pkinase.hmm > minifam', shell=True, stdout=subprocess.DEVNULL, check=True) |
| 516 |
|
| 517 |
r = subprocess.run('hmmpress -f minifam', |
| 518 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 519 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 520 |
with open('hmmpress-minifam.out', 'w') as f: |
| 521 |
print(r.stdout, file=f, end='') |
| 522 |
|
| 523 |
r = subprocess.run('hmmscan minifam 7LESS_DROME', |
| 524 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 525 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 526 |
|
| 527 |
m = re.match(r'((?s:.+?)Scores for complete sequence.*\n(?:.*\n){5})', r.stdout) |
| 528 |
with open('hmmscan-minifam-sevenless.out', 'w') as f: |
| 529 |
print(m.group(1), file=f, end='') |
| 530 |
|
| 531 |
m = re.search(r'(Domain annotation.+\n>> fn3.+\n.+\n.+\n(?:\s*\d+.+\n)+)', r.stdout) |
| 532 |
with open('hmmscan-minifam-sevenless.out2', 'w') as f: |
| 533 |
print(m.group(1), file=f, end='') |
| 534 |
|
| 535 |
m = re.search(r'\n( ==\s+domain\s+2(?s:.+?) PP\s*)\n', r.stdout) |
| 536 |
with open('hmmscan-minifam-sevenless.out3', 'w') as f: |
| 537 |
print(m.group(1), file=f, end='') |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
def hmmstat_minifam(): |
| 543 |
print('running hmmstat minifam...') |
| 544 |
|
| 545 |
r = subprocess.run('hmmstat minifam', |
| 546 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 547 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 548 |
with open('hmmstat-minifam.out', 'w') as f: |
| 549 |
print(r.stdout, file=f, end='') |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
def hmmalign_globins(): |
| 556 |
print('running hmmalign globins4.hmm globins45.fa...') |
| 557 |
|
| 558 |
r = subprocess.run('hmmalign globins4.hmm globins45.fa', |
| 559 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 560 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 561 |
|
| 562 |
m = re.match(r'(# STOCKHOLM(?:.*\n){13})', r.stdout) |
| 563 |
content = re.sub('^(.{80}).*$', r'\1 ...', m.group(1), flags=re.MULTILINE) |
| 564 |
with open('hmmalign-globins.out', 'w') as f: |
| 565 |
print(content, file=f, end='') |
| 566 |
print('...', file=f) |
| 567 |
|
| 568 |
m = re.search(r'\n((?:.+\n){4}#=GC PP_cons.+\n#=GC RF.+\n)', r.stdout) |
| 569 |
content = re.sub('^(.{80}).*$', r'\1 ...', m.group(1), flags=re.MULTILINE) |
| 570 |
with open('hmmalign-globins.out2', 'w') as f: |
| 571 |
print('...', file=f) |
| 572 |
print(content, file=f, end='') |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
assert re.search(r'^MYG_HORSE\s+g', r.stdout, flags=re.MULTILINE) |
| 577 |
assert re.search(r'^#=GR\s+MYG_HORSE\s+PP\s+8', r.stdout, flags=re.MULTILINE) |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
def hmmbuild_made1(): |
| 582 |
print('running hmmbuild MADE1.hmm MADE1.sto') |
| 583 |
|
| 584 |
r = subprocess.run('hmmbuild MADE1.hmm MADE1.sto', |
| 585 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 586 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 587 |
|
| 588 |
content = re.sub(r'(MADE1 \(MAriner Derived Element 1\), a TcMar-Mariner).+\n', r'\1 ...\n', r.stdout) |
| 589 |
with open('hmmbuild-made1.out', 'w') as f: |
| 590 |
print(content, file=f, end='') |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
def nhmmer_made1(deffp): |
| 595 |
print('running nhmmer MADE1.hmm dna_target.fa') |
| 596 |
|
| 597 |
r = subprocess.run('nhmmer MADE1.hmm dna_target.fa', |
| 598 |
shell=True, stdout=subprocess.PIPE, check=True, encoding='utf-8', |
| 599 |
env={"PATH": "{0}/src".format(top_builddir)}) |
| 600 |
|
| 601 |
m = re.search(r'\n(\s*E-value\s*score.+\n(?:.+\n)+\s*-+\s*inclusion threshold.+\n.+\n)', r.stdout) |
| 602 |
with open('nhmmer-made1.out', 'w') as f: |
| 603 |
print(m.group(1), file=f, end='') |
| 604 |
|
| 605 |
m = re.search(r'humanchr1.+\s+(3\d+)\s+(3\d+)(?s:.+?)humanchr1.+\s+(3\d+)\s+(3\d+)', r.stdout) |
| 606 |
print(r'\newcommand{{\NMHafrom}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 607 |
print(r'\newcommand{{\NMHato}}{{{0}}}'.format(m.group(2)), file=deffp) |
| 608 |
print(r'\newcommand{{\NMHbfrom}}{{{0}}}'.format(m.group(3)), file=deffp) |
| 609 |
print(r'\newcommand{{\NMHbto}}{{{0}}}'.format(m.group(4)), file=deffp) |
| 610 |
|
| 611 |
assert int(m.group(1)) < int(m.group(3)) |
| 612 |
|
| 613 |
m = re.search(r'^(Annotation.+)\n>>', r.stdout, flags=re.MULTILINE) |
| 614 |
with open('nhmmer-made1.out2', 'w') as f: |
| 615 |
print(m.group(1), file=f) |
| 616 |
|
| 617 |
m = re.search(r'\n(>> humanchr1(?:.+\n){4})', r.stdout) |
| 618 |
with open('nhmmer-made1.out3', 'w') as f: |
| 619 |
print(m.group(1), file=f) |
| 620 |
|
| 621 |
m = re.search(r'\n\n(\s+Alignment.+\n\s*score.+\n(?:.*\n)+?)\n>>', r.stdout) |
| 622 |
with open('nhmmer-made1.out4', 'w') as f: |
| 623 |
print(m.group(1), file=f, end='') |
| 624 |
|
| 625 |
m = re.search(r'\n(Internal pipeline statistics.+)', r.stdout, flags=re.DOTALL) |
| 626 |
with open("nhmmer-made1.out5", "w") as f: |
| 627 |
print(m.group(1), file=f, end='') |
| 628 |
|
| 629 |
m = re.search(r'^Target sequences:\s+\d+\s+\((\d+)\s+residues', r.stdout, flags=re.MULTILINE) |
| 630 |
print(r'\newcommand{{\NMHnres}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 631 |
print(r'\newcommand{{\NMHntop}}{{{0}}}'.format(int(m.group(1))//2), file=deffp) |
| 632 |
|
| 633 |
m = re.search(r'^Residues passing SSV filter:\s+(\d+)\s+\((\S+?)\)', r.stdout, flags=re.MULTILINE) |
| 634 |
print(r'\newcommand{{\NMHnssv}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 635 |
print(r'\newcommand{{\NMHfracssv}}{{{0:.1f}}}'.format(float(m.group(2))*100), file=deffp) |
| 636 |
|
| 637 |
m = re.search(r'^Residues passing bias filter:\s+(\d+)\s+\((\S+?)\)', r.stdout, flags=re.MULTILINE) |
| 638 |
print(r'\newcommand{{\NMHnbias}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 639 |
print(r'\newcommand{{\NMHfracbias}}{{{0:.1f}}}'.format(float(m.group(2))*100), file=deffp) |
| 640 |
|
| 641 |
m = re.search(r'^Residues passing Vit filter:\s+(\d+)\s+\((\S+?)\)', r.stdout, flags=re.MULTILINE) |
| 642 |
print(r'\newcommand{{\NMHnvit}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 643 |
print(r'\newcommand{{\NMHfracvit}}{{{0:.1f}}}'.format(float(m.group(2))*100), file=deffp) |
| 644 |
|
| 645 |
m = re.search(r'^Residues passing Fwd filter:\s+(\d+)\s+\((\S+?)\)', r.stdout, flags=re.MULTILINE) |
| 646 |
print(r'\newcommand{{\NMHnfwd}}{{{0}}}'.format(m.group(1)), file=deffp) |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
with open("inclusions.def", "w") as deffp: |
| 651 |
uniprot_relnotes(deffp) |
| 652 |
hmmscan_noargs(deffp) |
| 653 |
hmmbuild_noargs() |
| 654 |
hmmbuild_globins(deffp) |
| 655 |
hmmsearch_globins(deffp) |
| 656 |
domtbl1 = hmmsearch_fn3_sevenless(deffp) |
| 657 |
hmmsearch_fn3_uniprot(deffp, domtbl1) |
| 658 |
sevenless_table() |
| 659 |
jackhmmer_hbb_uniprot(deffp) |
| 660 |
hmmscan_sevenless() |
| 661 |
hmmstat_minifam() |
| 662 |
hmmalign_globins() |
| 663 |
hmmbuild_made1() |
| 664 |
nhmmer_made1(deffp) |
| 665 |
|
| 666 |
if not args.noclean: |
| 667 |
for fname in [ 'relnotes.txt', 'uniprot_sprot.fasta', |
| 668 |
'fn3.hmm', 'globins4.hmm', 'Pkinase.hmm', 'MADE1.hmm', |
| 669 |
'minifam', 'minifam.h3f', 'minifam.h3i', 'minifam.h3m', 'minifam.h3p' ]: |
| 670 |
if os.path.exists(fname): os.remove(fname) |
| 671 |
for fname in tutorial_files: |
| 672 |
if os.path.exists(fname): os.remove(fname) |