Skip to content
Snippets Groups Projects
Commit 7f54d59c authored by Gerardo Tauriello's avatar Gerardo Tauriello
Browse files

Reorder compare-structures arguments and fix default handling.

parent be69cfb5
No related branches found
No related tags found
No related merge requests found
...@@ -50,17 +50,19 @@ compare-structures as follows: ...@@ -50,17 +50,19 @@ compare-structures as follows:
# lDDT parameters # lDDT parameters
################# #################
--lddt \\ --lddt \\
--structural-checks \\
--consistency-checks \\
--inclusion-radius 15.0 \\ --inclusion-radius 15.0 \\
--bond-tolerance 15.0 \\ # Molecular check parameters
--angle-tolerance 15.0 \\ ############################
# Molck parameters
##################
--molck \\ --molck \\
--remove oxt hyd unk \\ --remove oxt hyd unk \\
--clean-element-column \\ --clean-element-column \\
--map-nonstandard-residues --map-nonstandard-residues \\
# Additional checks
###################
--structural-checks \\
--bond-tolerance 15.0 \\
--angle-tolerance 15.0 \\
--consistency-checks
""" """
import os import os
...@@ -78,77 +80,51 @@ from ost.conop import CompoundLib ...@@ -78,77 +80,51 @@ from ost.conop import CompoundLib
from ost.seq.alg.renumber import Renumber from ost.seq.alg.renumber import Renumber
class _DefaultStereochemicalParamAction(argparse.Action): def _GetDefaultShareFilePath(filename):
def __init__(self, default=None, required=False, **kwargs): """Look for filename in working directory and OST shared data path.
# Try to set default :return: Path to valid file or None if not found.
cwd = os.path.abspath(os.getcwd()) """
parameter_file_path = os.path.join(cwd, "stereo_chemical_props.txt") # Try current directory
if not os.path.exists(parameter_file_path): cwd = os.path.abspath(os.getcwd())
try: file_path = os.path.join(cwd, filename)
parameter_file_path = os.path.join( if not os.path.isfile(file_path):
ost.GetSharedDataPath(), try:
"stereo_chemical_props.txt") file_path = os.path.join(ost.GetSharedDataPath(), filename)
default = parameter_file_path except RuntimeError:
msg = "" # Ignore errors here (caught later together with non-existing file)
except RuntimeError: pass
msg = ( if not os.path.isfile(file_path):
"Could not set default stereochemical parameter file. In " file_path = None
"order to use the default one please set $OST_ROOT " # Either file_path is valid file path or None
"environmental variable, run the script with OST binary or" return file_path
" provide a local copy of 'stereo_chemical_props.txt' in "
"CWD. Alternatively provide the path to the local copy") def _GetDefaultParameterFilePath():
else: # Try to get in default locations
default = parameter_file_path parameter_file_path = _GetDefaultShareFilePath("stereo_chemical_props.txt")
msg = "" if parameter_file_path is None:
super(_DefaultStereochemicalParamAction, self).__init__( msg = (
default=default, "Could not set default stereochemical parameter file. In "
required=required, "order to use the default one please set $OST_ROOT "
**kwargs) "environmental variable, run the script with OST binary or"
if msg: " provide a local copy of 'stereo_chemical_props.txt' in "
self.help += " (WARNING: %s)" % (msg,) "CWD. Alternatively provide the path to the local copy.")
else:
def __call__(self, parser, namespace, values, option_string=None): msg = ""
if not os.path.exists(values): return parameter_file_path, msg
parser.error(
"Parameter file %s does not exist." % values) def _GetDefaultCompoundLibraryPath():
setattr(namespace, self.dest, values) # Try to get in default locations
compound_library_path = _GetDefaultShareFilePath("compounds.chemlib")
if compound_library_path is None:
class _DefaultCompoundLibraryAction(argparse.Action): msg = (
def __init__(self, default=None, required=False, **kwargs): "Could not set default compounds library path. In "
# Try to set default "order to use the default one please set $OST_ROOT "
cwd = os.path.abspath(os.getcwd()) "environmental variable, run the script with OST binary or"
compound_library_path = os.path.join(cwd, "compounds.chemlib") " provide a local copy of 'compounds.chemlib' in CWD"
if not os.path.exists(compound_library_path): ". Alternatively provide the path to the local copy.")
try: else:
compound_library_path = os.path.join( msg = ""
ost.GetSharedDataPath(), return compound_library_path, msg
"compounds.chemlib")
default = compound_library_path
msg = ""
except RuntimeError:
msg = (
"Could not set default compounds library path. In "
"order to use the default one please set $OST_ROOT "
"environmental variable, run the script with OST binary or"
" provide a local copy of 'compounds.chemlib' in CWD"
". Alternatively provide the path to the local copy")
else:
default = compound_library_path
msg = ""
super(_DefaultCompoundLibraryAction, self).__init__(
default=default,
required=required,
**kwargs)
if msg:
self.help += " (WARNING: %s)" % (msg,)
def __call__(self, parser, namespace, values, option_string=None):
if not os.path.exists(values):
parser.error(
"Compounds library file %s does not exist." % values)
setattr(namespace, self.dest, values)
def _ParseArgs(): def _ParseArgs():
"""Parse command-line arguments.""" """Parse command-line arguments."""
...@@ -227,6 +203,15 @@ def _ParseArgs(): ...@@ -227,6 +203,15 @@ def _ParseArgs():
default=False, default=False,
action="store_true", action="store_true",
help=("Fault tolerant parsing.")) help=("Fault tolerant parsing."))
parser.add_argument(
"-cl",
"--compound-library",
dest="compound_library",
default=None,
help=("Location of the compound library file (compounds.chemlib).\n"
"If not provided, the following locations are searched in this\n"
"order: 1. Working directory, 2. OpenStructure standard library"
"\nlocation."))
# #
# QS-scorer options # QS-scorer options
# #
...@@ -265,37 +250,6 @@ def _ParseArgs(): ...@@ -265,37 +250,6 @@ def _ParseArgs():
default=False, default=False,
action="store_true", action="store_true",
help=("Calculate lDDT.")) help=("Calculate lDDT."))
parser.add_argument(
"-sc",
"--structural-checks",
dest="structural_checks",
default=False,
action="store_true",
help=("Perform structural checks and filter input data."))
parser.add_argument(
"-p",
"--parameter-file",
dest="parameter_file",
action=_DefaultStereochemicalParamAction,
help=("Location of the stereochemical parameter file\n"
"(stereo_chemical_props.txt).\n"
"If not provided, the following locations are searched in this\n"
"order: 1. Working directory, 2. OpenStructure standard library"
"\nlocation."))
parser.add_argument(
"-bt",
"--bond-tolerance",
dest="bond_tolerance",
type=float,
default=12.0,
help=("Tolerance in STD for bonds."))
parser.add_argument(
"-at",
"--angle-tolerance",
dest="angle_tolerance",
type=float,
default=12.0,
help=("Tolerance in STD for angles."))
parser.add_argument( parser.add_argument(
"-ir", "-ir",
"--inclusion-radius", "--inclusion-radius",
...@@ -312,18 +266,6 @@ def _ParseArgs(): ...@@ -312,18 +266,6 @@ def _ParseArgs():
help=("Sequence separation. Only distances between residues whose\n" help=("Sequence separation. Only distances between residues whose\n"
"separation is higher than the provided parameter are\n" "separation is higher than the provided parameter are\n"
"considered when computing the score")) "considered when computing the score"))
parser.add_argument(
"-cc",
"--consistency-checks",
dest="consistency_checks",
default=False,
action="store_true",
help=("Take consistency checks into account. By default residue name\n"
"consistency between a model-reference pair would be checked\n"
"but only a warning message will be displayed and the script\n"
"will continue to calculate scores. If this flag is ON, checks\n"
"will not be ignored and if the pair does not pass the test\n"
"all the scores for that pair will be marked as a FAILURE."))
parser.add_argument( parser.add_argument(
"-spr", "-spr",
"--save-per-residue-scores", "--save-per-residue-scores",
...@@ -332,7 +274,7 @@ def _ParseArgs(): ...@@ -332,7 +274,7 @@ def _ParseArgs():
action="store_true", action="store_true",
help=("")) help=(""))
# #
# Molck parameters # Molecular check parameters
# #
parser.add_argument( parser.add_argument(
"-ml", "-ml",
...@@ -341,15 +283,6 @@ def _ParseArgs(): ...@@ -341,15 +283,6 @@ def _ParseArgs():
default=False, default=False,
action="store_true", action="store_true",
help=("Run molecular checker to clean up input.")) help=("Run molecular checker to clean up input."))
parser.add_argument(
"-cl",
"--compound-library",
dest="compound_library",
action=_DefaultCompoundLibraryAction,
help=("Location of the compound library file (compounds.chemlib).\n"
"If not provided, the following locations are searched in this\n"
"order: 1. Working directory, 2. OpenStructure standard library"
"\nlocation."))
parser.add_argument( parser.add_argument(
"-rm", "-rm",
"--remove", "--remove",
...@@ -380,6 +313,52 @@ def _ParseArgs(): ...@@ -380,6 +313,52 @@ def _ParseArgs():
action="store_true", action="store_true",
help=("Map modified residues back to the parent amino acid, for\n" help=("Map modified residues back to the parent amino acid, for\n"
"example MSE -> MET, SEP -> SER.")) "example MSE -> MET, SEP -> SER."))
#
# Options for various checks
#
parser.add_argument(
"-sc",
"--structural-checks",
dest="structural_checks",
default=False,
action="store_true",
help=("Perform structural checks and filter input data."))
parser.add_argument(
"-p",
"--parameter-file",
dest="parameter_file",
default=None,
help=("Location of the stereochemical parameter file\n"
"(stereo_chemical_props.txt).\n"
"If not provided, the following locations are searched in this\n"
"order: 1. Working directory, 2. OpenStructure standard library"
"\nlocation."))
parser.add_argument(
"-bt",
"--bond-tolerance",
dest="bond_tolerance",
type=float,
default=12.0,
help=("Tolerance in STD for bonds."))
parser.add_argument(
"-at",
"--angle-tolerance",
dest="angle_tolerance",
type=float,
default=12.0,
help=("Tolerance in STD for angles."))
parser.add_argument(
"-cc",
"--consistency-checks",
dest="consistency_checks",
default=False,
action="store_true",
help=("Take consistency checks into account. By default residue name\n"
"consistency between a model-reference pair would be checked\n"
"but only a warning message will be displayed and the script\n"
"will continue to calculate scores. If this flag is ON, checks\n"
"will not be ignored and if the pair does not pass the test\n"
"all the scores for that pair will be marked as a FAILURE."))
# Print full help is no arguments provided # Print full help is no arguments provided
if len(sys.argv) == 1: if len(sys.argv) == 1:
...@@ -395,17 +374,37 @@ def _ParseArgs(): ...@@ -395,17 +374,37 @@ def _ParseArgs():
parser.error( parser.error(
"Cannot parse chain mapping into dictionary. The " "Cannot parse chain mapping into dictionary. The "
"correct format is: key:value [key2:value2 ...].") "correct format is: key:value [key2:value2 ...].")
# Check parameter file if lddt is on
if opts.lddt and opts.parameter_file is None: # Check parameter file if structural checks are on
parser.error( if opts.structural_checks:
"argument -p/--parameter-file is required when --lddt " if opts.parameter_file is None:
"option is selected.") # try to get default if none provided
opts.parameter_file, msg = _GetDefaultParameterFilePath()
# Check parameter file if lddt is on if msg:
if opts.molck and opts.compound_library is None: parser.error(msg)
parser.error( else:
"argument -cl/--compound-library is required when --molck " # if provided it must exist
"option is selected.") if not os.path.isfile(opts.parameter_file):
parser.error("Parameter file %s does not exist." \
% opts.parameter_file)
# Check compound library path (always required!)
if opts.compound_library is None:
# try to get default if none provided
opts.compound_library, msg = _GetDefaultCompoundLibraryPath()
if msg:
parser.error(msg)
else:
# if provided it must exist
if not os.path.isfile(opts.compound_library):
parser.error("Compounds library file %s does not exist." \
% opts.compound_library)
# Check model and reference paths
if not os.path.isfile(opts.model):
parser.error("Model file %s does not exist." % opts.model)
if not os.path.isfile(opts.reference):
parser.error("Reference file %s does not exist." % opts.reference)
return opts return opts
......
...@@ -22,13 +22,13 @@ lDDT scores between two complexes from the command line with: ...@@ -22,13 +22,13 @@ lDDT scores between two complexes from the command line with:
$ ost compare-structures [-h] [-v VERBOSITY] -m MODEL -r REFERENCE $ ost compare-structures [-h] [-v VERBOSITY] -m MODEL -r REFERENCE
[-o OUTPUT] [-d] [-ds DUMP_SUFFIX] [-o OUTPUT] [-d] [-ds DUMP_SUFFIX]
[-rs REFERENCE_SELECTION] [-ms MODEL_SELECTION] [-rs REFERENCE_SELECTION] [-ms MODEL_SELECTION]
[-ca] [-ft] [-qs] [-ca] [-ft] [-cl COMPOUND_LIBRARY] [-qs]
[-c CHAIN_MAPPING [CHAIN_MAPPING ...]] [-rna] [-c CHAIN_MAPPING [CHAIN_MAPPING ...]] [-rna]
[-l] [-sc] [-p PARAMETER_FILE] [-l] [-ir INCLUSION_RADIUS]
[-bt BOND_TOLERANCE] [-at ANGLE_TOLERANCE] [-ss SEQUENCE_SEPARATION] [-spr] [-ml]
[-ir INCLUSION_RADIUS] [-ss SEQUENCE_SEPARATION] [-rm REMOVE [REMOVE ...]] [-ce] [-mn] [-sc]
[-cc] [-spr] [-ml] [-cl COMPOUND_LIBRARY] [-p PARAMETER_FILE] [-bt BOND_TOLERANCE]
[-rm REMOVE [REMOVE ...]] [-ce] [-mn] [-at ANGLE_TOLERANCE] [-cc]
By default the verbosity is set to 3 which will result in the informations By default the verbosity is set to 3 which will result in the informations
being shown in the console. The result can be (optionally) saved as JSON file being shown in the console. The result can be (optionally) saved as JSON file
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment