-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsilentdropcorruptmodels
More file actions
executable file
·98 lines (78 loc) · 3.11 KB
/
Copy pathsilentdropcorruptmodels
File metadata and controls
executable file
·98 lines (78 loc) · 3.11 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
import os
import sys
# if you pip installed this is wrong but you have silent_tools installed anyways
silent_tools_dir = os.path.dirname(os.path.realpath(__file__))
if silent_tools_dir not in sys.path:
sys.path.append(silent_tools_dir)
import silent_tools
from silent_tools import eprint
import re
# Don't throw an error when someone uses head
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
if (len(sys.argv) == 1):
eprint("")
eprint('silentdropcorruptmodels by bcov - drop models with wrong number of residues')
eprint("Usage:")
eprint(" silentdropcorruptmodels myfile.silent > fixed.silent")
sys.exit(1)
silent_file = sys.argv[1]
silent_index = silent_tools.get_silent_index( silent_file, accept_garbage=True)
is_binary = silent_index['silent_type'] == "BINARY"
is_protein = silent_index['silent_type'] == "PROTEIN"
if ( not is_binary and not is_protein ):
eprint("silentdropcorruptmodels: Unknown silent type. Trying BINARY")
is_binary = True
sys.stdout.write( silent_tools.silent_header_fix_corrupt( silent_index ) )
sys.stdout.flush()
with open(silent_file, errors='ignore') as sf:
for tag in silent_index['tags']:
structure = silent_tools.get_silent_structure_file_open( sf, silent_index, tag )
try:
sequence_chunks = silent_tools.get_sequence_chunks( structure, tag )
except:
eprint("silentdropcorruptmodels: Error reading sequence: %s"%(tag))
continue
if ( sequence_chunks is None ):
continue
sequence = "".join(sequence_chunks)
seqlen = len(sequence)
assert( is_binary ^ is_protein )
num_res_lines = 0
corrupt_lines = []
entered_structure = False
for line in structure:
if ( is_binary ):
if ( len(line) == 0 ):
continue
sp = line.split()
if ( line[0] in "HEL" and len(sp) == 2 and (len(sp[0]) - 1) % 16 == 0):
num_res_lines += 1
entered_structure = True
continue
if entered_structure:
corrupt_lines.append(line)
continue
continue
if ( is_protein ):
if ( len(line) < 6 ):
continue
if ( line[5] in "HEL" ):
num_res_lines += 1
entered_structure += True
continue
if entered_structure:
corrupt_lines.append(line)
continue
continue
if ( seqlen != num_res_lines ):
eprint("silentdropcorruptmodels: Found %5i res expected %5i res: %s"%
(num_res_lines, seqlen, tag))
elif len(corrupt_lines) > 0:
eprint('silentdropcorruptmodels: %i corrupt lines found in: %s'%(len(corrupt_lines), tag))
for line in corrupt_lines:
eprint('silentdropcorruptmodels:', line)
else:
sys.stdout.write("".join(structure))
sys.stdout.flush()