20 Utility functions to load secondary structure information from DSSP files
21 and assign them to entities.
23 Authors: Pascal Benkert, Marco Biasini
27 import tempfile,subprocess
29 from ost
import io,mol
30 from ost
import settings
33 def _SkipHeader(stream):
34 line=stream.readline()
36 if line.strip().find(
'#')==0:
38 line=stream.readline()
42 def _ExecuteDSSP(path, dssp_bin, temp_dir=None):
45 temp_dssp_path=tempfile.mktemp(suffix=
".out",prefix=
"dssp", dir=temp_dir)
46 dssp_abs_path=settings.Locate([
'dsspcmbi',
'dssp'], env_name=
'DSSP_EXECUTABLE',
47 explicit_file_name=dssp_bin)
48 if os.path.isdir(dssp_abs_path):
49 raise RuntimeError(
'"%s" is a directory. Specify path to DSSP binary' % dssp_abs_path)
50 if not os.access(dssp_abs_path, os.X_OK):
51 raise RuntimeError(
'"%s" is not executable' % dssp_abs_path)
53 ps=subprocess.Popen([dssp_abs_path, path, temp_dssp_path],
54 stderr=subprocess.PIPE)
55 err_lines=ps.stderr.readlines()
60 def _CalcRelativeSA(residue_type, absolute_sa):
61 solvent_max_list=[118,317,238,243,183,262,286,154,258,228,
62 243,278,260,271,204,234,206,300,303,216]
63 residue_indices =
"ARNDCQEGHILKMFPSTWYV"
64 if residue_type.islower()==
True:
66 if residue_indices.find(residue_type)==-1:
67 raise RuntimeError(
'residue %s is a non-standard residue' %(residue_type))
69 rel=float(absolute_sa)/(solvent_max_list[residue_indices.find(residue_type)])
73 def AssignDSSP(ent, pdb_path="", extract_burial_status=False, tmp_dir=None,
76 Assign secondary structure states to peptide residues in the structure. This
77 function uses the DSSP command line program.
79 If you already have a DSSP output file and would like to assign the secondary
80 structure states to an entity, use :func:`LoadDSSP`.
82 :param ent: The entity for which the secondary structure should be calculated
83 :type ent: :class:`~ost.mol.EntityHandle` or :class:`~ost.mol.EntityView`
84 :param extract_burial_status: If true, also extract burial status
85 :param tmp_dir: If set, overrides the default tmp directory of the
87 :param dssp_bin: The path to the DSSP executable
88 :raises: :class:`~ost.settings.FileNotFound` if the dssp executable is not
90 :raises: :class:`RuntimeError` when dssp is executed with errors
96 pdb_path=tempfile.mktemp(suffix=
".pdb",prefix=
"temp_entity",
98 io.SaveEntity(ent, pdb_path)
103 temp_dssp_path=_ExecuteDSSP(pdb_path, dssp_bin)
104 if not os.path.exists(temp_dssp_path):
105 raise RuntimeEror(
'DSSP output file does not exist.')
108 LoadDSSP(temp_dssp_path, ent, extract_burial_status,
112 print "Exception in DSSP:", e
113 if entity_saved_flag == 1:
115 os.remove(temp_dssp_path)
116 raise RuntimeError(e)
120 if entity_saved_flag == 1:
122 os.remove(temp_dssp_path)
128 def LoadDSSP(file_name, model, extract_burial_status=0,
129 entity_saved_flag=0, calculate_relative_sa=
True):
130 if model.IsValid() == 0:
131 print "DSSP: model is not valid"
132 stream=open(file_name)
133 if not _SkipHeader(stream):
135 raise RuntimeError(
'Ill-formatted DSSP file')
138 num=line[6:10].strip()
139 ins_code=line[10].strip()
141 solvent_accessibility=float(line[34:39].strip())
150 chain=model.FindChain(chain_name)
152 if not chain.IsValid():
159 residue=chain.FindResidue(
mol.ResNum(int(num)))
161 residue=chain.FindResidue(
mol.ResNum(int(num),ins_code))
164 if extract_burial_status == 1:
166 residue.SetStringProp(
"burial_status",
'X')
169 if residue.name==
"MSE" and amino_acid==
'X':
172 residue.SetFloatProp(
"solvent_accessibility",
173 solvent_accessibility)
174 if calculate_relative_sa:
175 relative_sa=_CalcRelativeSA(amino_acid,solvent_accessibility)
176 residue.SetFloatProp(
"relative_solvent_accessibility",
178 if relative_sa < 0.25:
179 residue.SetStringProp(
"burial_status",
'b')
181 residue.SetStringProp(
"burial_status",
'e')
187 rt=mol.SecStructure.COIL
189 rt=mol.SecStructure.ALPHA_HELIX
191 rt=mol.SecStructure.EXTENDED
193 rt=mol.SecStructure.BETA_BRIDGE
195 rt=mol.SecStructure.BEND
197 rt=mol.SecStructure.TURN
199 rt=mol.SecStructure.PI_HELIX
201 rt=mol.SecStructure.THREE_TEN_HELIX
203 if residue.IsValid() == 0:
208 raise RuntimeError(
'Ill-formatted DSSP file: invalid residue')