-
Notifications
You must be signed in to change notification settings - Fork 0
/
trim_nonprotein.py
38 lines (28 loc) · 1023 Bytes
/
trim_nonprotein.py
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
import argparse as ap
import warnings
import Bio.PDB as bp
from Bio import BiopythonWarning
# All the argument parsing logic
parser = ap.ArgumentParser()
parser.add_argument("input", help="path to the input structure file", type=str)
parser.add_argument("output", help="name of the output structure file", type=str)
parser.add_argument("-w", "--warn", help="print warning messages",
action='store_true')
args = parser.parse_args()
# Silent BioPython warnings
if not args.warn:
warnings.simplefilter('ignore', BiopythonWarning)
# Parse the PDB file into a structure object
parser = bp.PDBParser()
structure = parser.get_structure("input", args.input)
# Only select amino acid residues (protein) to be written in the output
class ProteinSelect(bp.Select):
def accept_residue(self, residue):
if residue.has_id('CA') :
return 1
else:
return 0
# Write the output file
io = bp.PDBIO()
io.set_structure(structure)
io.save(args.output, ProteinSelect())