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()
41 def _Cleanup(temp_dssp_path, pdb_path):
42 if os.path.exists(temp_dssp_path):
43 os.remove(temp_dssp_path)
44 if os.path.exists(pdb_path):
47 def _CalcRelativeSA(residue_type, absolute_sa):
48 solvent_max_list=[118,317,238,243,183,262,286,154,258,228,
49 243,278,260,271,204,234,206,300,303,216]
50 residue_indices =
"ARNDCQEGHILKMFPSTWYV"
54 if residue_type.islower():
56 if residue_indices.find(residue_type)==-1:
57 raise RuntimeError(
'residue %s is a non-standard residue' %(residue_type))
59 rel=float(absolute_sa)/(solvent_max_list[residue_indices.find(residue_type)])
142 def AssignDSSP(ent, pdb_path="", extract_burial_status=False, tmp_dir=None,
145 Assign secondary structure states to peptide residues in the structure. This
146 function replaces the "old" AssignDSSP which relies on the DSSP command line
147 program and uses OpenStructure internal functionality only. The sole purpose
148 is to retain the "old" interface and you're adviced to directly use
149 :func:`ost.mol.alg.AssignSecStruct` and :func:`ost.mol.alg.Accessibility`.
151 If you already have a DSSP output file and would like to assign the secondary
152 structure states to an entity, use :func:`LoadDSSP`.
154 :param ent: The entity for which the secondary structure should be calculated
155 :type ent: :class:`~ost.mol.EntityHandle` or :class:`~ost.mol.EntityView`
156 :param extract_burial_status: If true, also extract burial status and store
158 ``relative_solvent_accessibility`` at residue
160 :param tmp_dir: If set, overrides the default tmp directory of the
161 operating system - deprecated, has no effect
162 :param dssp_bin: The path to the DSSP executable - deprecated, has no effect
165 if not ent.IsValid():
166 raise ValueError(
'model entity is not valid')
167 if ent.atom_count==0:
168 raise ValueError(
'model entity does not contain any atoms')
170 mol.alg.AssignSecStruct(ent)
171 if extract_burial_status:
172 mol.alg.Accessibility(ent, algorithm=mol.alg.DSSP)
175 for r
in ent.residues:
176 if r.HasProp(
"asaAbs"):
177 asa = round(r.GetFloatProp(
"asaAbs"))
178 asa_rel = _CalcRelativeSA(r.one_letter_code, asa)
182 r.SetFloatProp(
"solvent_accessibility", asa)
183 r.SetFloatProp(
"relative_solvent_accessibility", asa_rel)
185 r.SetStringProp(
"burial_status",
'b')
187 r.SetStringProp(
"burial_status",
'e')
190 def LoadDSSP(file_name, model, extract_burial_status=False,
191 entity_saved=False, calculate_relative_sa=True):
193 Loads DSSP output and assigns secondary structure states to the peptidic
196 If you would like to run dssp *and* assign the secondary structure,
197 use :func:`AssignDSSP` instead.
199 :param file_name: The filename of the DSSP output file
200 :param model: The entity to which the secondary structure states should be
202 :param extract_burial_status: If true also calculates burial status of
203 residues and assigns it to the burial_status string property.
204 :param calculate_relative_sa: If true also relative solvent accessibility and
205 and assigns it to the relative_solvent_accessibility float property of
207 :param entity_save: Whether the entity was saved.
209 if not model.IsValid():
210 raise ValueError(
'model entity is not valid')
211 if model.atom_count==0:
212 raise ValueError(
'model entity does not contain any atoms')
213 stream=open(file_name)
214 if not _SkipHeader(stream):
216 raise RuntimeError(
'Ill-formatted DSSP file')
219 num=line[6:10].strip()
220 ins_code=line[10].strip()
222 solvent_accessibility=float(line[34:39].strip())
231 chain=model.FindChain(chain_name)
233 if not chain.IsValid():
240 residue=chain.FindResidue(
mol.ResNum(int(num)))
242 residue=chain.FindResidue(
mol.ResNum(int(num),ins_code))
245 if extract_burial_status:
247 residue.SetStringProp(
"burial_status",
'X')
250 if residue.name==
"MSE" and amino_acid==
'X':
253 residue.SetFloatProp(
"solvent_accessibility",
254 solvent_accessibility)
255 if calculate_relative_sa:
256 relative_sa=_CalcRelativeSA(amino_acid,solvent_accessibility)
257 residue.SetFloatProp(
"relative_solvent_accessibility",
259 if relative_sa < 0.25:
260 residue.SetStringProp(
"burial_status",
'b')
262 residue.SetStringProp(
"burial_status",
'e')
263 except Exception
as e:
268 rt=mol.SecStructure.COIL
270 rt=mol.SecStructure.ALPHA_HELIX
272 rt=mol.SecStructure.EXTENDED
274 rt=mol.SecStructure.BETA_BRIDGE
276 rt=mol.SecStructure.BEND
278 rt=mol.SecStructure.TURN
280 rt=mol.SecStructure.PI_HELIX
282 rt=mol.SecStructure.THREE_TEN_HELIX
284 if not residue.IsValid():
289 raise RuntimeError(
'Ill-formatted DSSP file: invalid residue')
def AssignDSSP(ent, pdb_path="", extract_burial_status=False, tmp_dir=None, dssp_bin=None)
def LoadDSSP(file_name, model, extract_burial_status=False, entity_saved=False, calculate_relative_sa=True)
Secondary structure types as defined by DSSP. For convenience, the enum values match the characters u...