-
Notifications
You must be signed in to change notification settings - Fork 10
/
pdbseq.py
143 lines (115 loc) · 4.45 KB
/
pdbseq.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#! /usr/local/bin/python
"""Script for extracting sequences from a PDB file.
******************************************************************
Copyright (C) 2005 Allan Drummond, California Institute of Technology
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************
SCHEMA was developed in the laboratory of Frances H. Arnold at the California Institute of Technology.
References:
Voigt, C. et al., "Protein building blocks preserved by recombination," Nature Structural Biology 9(7):553-558 (2002).
Meyer, M. et al., "Library analysis of SCHEMA-guided recombination," Protein Science 12:1686-1693 (2003).
Otey, C. et al., "Functional evolution and structural conservation in chimeric cytochromes P450: Calibrating a structure-guided approach," Chemistry & Biology 11:1-20 (2004)
Silberg, J. et al., "SCHEMA-guided protein recombination," Methods in Enzymology 388:35-42 (2004).
Endelman, J. et al., "Site-directed protein recombination as a shortest-path problem," Protein Engineering, Design & Selection 17(7):589-594 (2005).
"""
import sys, string, os
import pdb, schema
ARG_PDB_FILE = 'pdb'
ARG_OUTPUT_FILE = 'o'
ARG_HELP = 'help'
ARG_CHAINS = 'chains'
def parse_arguments(args):
# Turn linear arguments into a dictionary of (option, [values,...]) pairs
arg_dict = {}
key = None
for arg in args[1:]:
if arg[0] == '-':
key = arg[1:]
arg_dict[key] = None
else:
if arg_dict.has_key(key):
if arg_dict[key]:
if type(arg_dict[key]) is list:
arg_dict[key] = arg_dict[key]+[arg]
else:
arg_dict[key] = [arg_dict[key],arg]
else:
arg_dict[key] = arg
else:
arg_dict[key] = arg
return arg_dict
def print_usage(args):
print 'Usage: python', args[0].split(os.path.sep)[-1], " [options]"
print 'Options:\n',\
"\t-%s <PDB file>\n" % ARG_PDB_FILE, \
"\t[-%s <PDB chain list, e.g. A B C>]\n" % ARG_CHAINS,\
"\t[-%s <contacts output file>]" % ARG_OUTPUT_FILE
def confirm_arguments(arg_dict):
# Are arguments okay?
res = True
arg_keys = arg_dict.keys()
try:
if len(arg_keys) == 0:
res = False
return
if not ARG_PDB_FILE in arg_keys:
print " You must provide a PDB file (-%s <file>)" % ARG_PDB_FILE
res = False
elif not os.path.isfile(arg_dict[ARG_PDB_FILE]):
print " Can't find PDB file %s" % arg_dict[ARG_PDB_FILE]
res = False
except:
res = False
return res
def main(args):
arg_dict = parse_arguments(args)
if not confirm_arguments(arg_dict):
if args[0].split(os.path.sep)[-1] == "pdbseq.py":
print_usage(args)
return
# Flags and values
# Inputs:
# The PDB file name.
pdb_file = arg_dict[ARG_PDB_FILE]
# The PDB chains
# Many PDB files include multiple chains. The chain_identifier list includes those
# chains which correspond to the protein whose contacts are being evaluated.
# Most often, chain 'A' (in the case of multiple chains) or chain ' ' (only one chain)
# will be the appropriate choice.
if arg_dict.has_key(ARG_CHAINS):
chains = arg_dict[ARG_CHAINS]
if type(chains) is list:
chain_identifiers = chains + [' ']
else:
chain_identifiers = [chains, ' ']
else:
chain_identifiers = ['A',' ']
# The file name for output.
if arg_dict.has_key(ARG_OUTPUT_FILE):
output_file = file(arg_dict[ARG_OUTPUT_FILE], 'w')
else:
output_file = sys.stdout
# Read in the PDB file to create a list of residues.
residues = pdb.File().read(file(pdb_file, 'r'))
# Filter residues not in selected chains
residue_seq = pdb.sequence(residues, chain_identifiers)
if residue_seq == '':
print "No residues found for chain(s) %s. Aborting..." % chain_identifiers
return
# Print it
output_file.write('# Residue sequence for chain(s) %s from PDB file %s\n%s' % \
(chain_identifiers, pdb_file, residue_seq))
if arg_dict.has_key(ARG_OUTPUT_FILE):
output_file.close()
def main_wrapper():
main(sys.argv)
main_wrapper()