Skip to content
Snippets Groups Projects
Commit 6016ac58 authored by Marco Biasini's avatar Marco Biasini
Browse files

Allow to pass dssp binary path to AssignDSSP

While we are in there, also fix BZDNG-235 by checking that
DSSP is executable and not a directory and making sure the
output file exists before continuing.
parent d60de420
No related branches found
No related tags found
No related merge requests found
......@@ -44,12 +44,17 @@ def _Cleanup(pdb_path, temp_path, entity_saved):
if os.path.exists(temp_path):
os.remove(temp_path)
def _ExecuteDSSP(path, temp_dir=None):
def _ExecuteDSSP(path, dssp_bin, temp_dir=None):
# use of mktemp is a safty problem (use mkstemp and provide file handle to
# subsequent process
temp_dssp_path=tempfile.mktemp(suffix=".out",prefix="dssp", dir=temp_dir)
dssp_abs_path=settings.Locate('dssp', env_name='DSSP_EXECUTABLE')
assert os.path.exists(path)
dssp_abs_path=settings.Locate('dssp', env_name='DSSP_EXECUTABLE',
explicit_file_name=dssp_bin)
if os.path.isdir(dssp_abs_path):
raise RuntimeError('"%s" is a directory. Specify path to DSSP binary' % dssp_abs_path)
if not os.access(dssp_abs_path, os.X_OK):
raise RuntimeError('"%s" is not executable' % dssp_abs_path)
ps=subprocess.Popen([dssp_abs_path, path, temp_dssp_path],
stderr=subprocess.PIPE)
err_lines=ps.stderr.readlines()
......@@ -72,7 +77,8 @@ def _CalcRelativeSA(residue_type, absolute_sa):
return rel
def AssignDSSP(ent, pdb_path="", extract_burial_status=False, tmp_dir=None):
def AssignDSSP(ent, pdb_path="", extract_burial_status=False, tmp_dir=None,
dssp_bin=None):
"""
Assign secondary structure states to peptide residues in the structure. This
function uses the DSSP command line program.
......@@ -85,9 +91,10 @@ def AssignDSSP(ent, pdb_path="", extract_burial_status=False, tmp_dir=None):
:param extract_burial_status: If true, also extract burial status
:param tmp_dir: If set, overrides the default tmp directory of the
operating system
:param dssp_bin: The path to the DSSP executable
:raises: :class:`~ost.settings.FileNotFound` if the dssp executable is not
in the path.
:raises: :class:`RuntimeError` when dssp is executed with errors
"""
entity_saved = False
# use of mktemp is a safty problem (use mkstemp and provide file handle to
......@@ -99,8 +106,9 @@ def AssignDSSP(ent, pdb_path="", extract_burial_status=False, tmp_dir=None):
#TODO: exception handling (currently errors occuring here
# are handled in the parser LoadDSSP)
temp_dssp_path=_ExecuteDSSP(pdb_path)
temp_dssp_path=_ExecuteDSSP(pdb_path, dssp_bin)
if not os.path.exists(temp_dssp_path):
raise RuntimeEror('DSSP output file does not exist.')
# assign DSSP to entity
try:
LoadDSSP(temp_dssp_path, ent, extract_burial_status,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment