-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqvextractspecific
executable file
·52 lines (39 loc) · 1.07 KB
/
qvextractspecific
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
#!/usr/bin/env python3
'''
This is a command-line tool to extract a specific set of PDB files from a Quiver file.
Usage:
qvextract <quiver_file> <tag1> <tag2> ...
'''
import sys
import os
from quiver import Quiver
# Thanks to bcov for this code
import stat
quiver_file = sys.argv[1]
tag_buffers = []
if ( stat.S_ISFIFO(os.stat("/dev/stdin").st_mode) ):
tag_buffers += sys.stdin.readlines()
tag_buffers += sys.argv[2:]
tags = []
for line in tag_buffers:
line = line.strip()
if (len(line) == 0):
continue
sp = line.split(" ")
for tag in sp:
tags.append(tag)
qv = Quiver(quiver_file, 'r')
for tag in tags:
outfn = f'{tag}.pdb'
if os.path.exists(outfn):
print(f'File {outfn} already exists, skipping')
continue
try:
lines = qv.get_pdblines(tag)
except:
print(f'Could not find tag {tag} in Quiver file, skipping')
continue
with open(outfn, 'w') as f:
for line in lines:
f.write(line)
print(f'Successfully extracted {len(tags)} PDB files from {quiver_file}')