-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsilentoopsscoreslice
More file actions
executable file
·81 lines (56 loc) · 1.94 KB
/
Copy pathsilentoopsscoreslice
File metadata and controls
executable file
·81 lines (56 loc) · 1.94 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
#!/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
# 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('silentoopsscoreslice by bcov - an oops tool that slices by score')
eprint(' oops tool -- reads file once, because, "oops that\'s a lot of data"')
eprint("Usage:")
eprint(" silentoopsscoreslice myfile.silent \"s[1] < -30 and len(s) == 50\"")
eprint(" Where s = score_line.split()")
sys.exit(1)
silent_file = sys.argv[1]
expression = sys.argv[2]
expression_func = eval("lambda s: " + expression)
scoreline, f = silent_tools.assert_is_silent_and_get_scoreline(silent_file, True)
sys.stdout.write( silent_tools.silent_header_slim( "A", scoreline, "BINARY" ) )
sys.stdout.flush()
have_line = False
while (True):
if ( not have_line ):
try:
line = next(f)
except:
break
have_line = False
# we should never be mid-structure
# but silent files can be corrupt so don't freak out
if ( line[0] != "S" ):
continue
if ( line.startswith("SEQUENCE") ):
continue
if ( not line.startswith("SCORE") ):
continue
if ( "description" in line ):
continue
# ok, we have the first line of a structure
s = line.split()
# eprint(len(s), s[45])
# eprint(float(s[45]))
keep_structure = expression_func( s )
structure, line = silent_tools.rip_structure_by_lines(f, line, keep_structure)
have_line = True
if ( keep_structure ):
sys.stdout.write("".join(structure))
sys.stdout.flush()
if ( line is None ):
break