Skip to content

Commit

Permalink
Added KeyError to purge check and changed exit calls to raises
Browse files Browse the repository at this point in the history
  • Loading branch information
linucks committed Jun 26, 2018
1 parent 2102128 commit bb63e73
Showing 1 changed file with 31 additions and 64 deletions.
95 changes: 31 additions & 64 deletions ample/util/options_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def check_mandatory_options(optd):
"""

def _exit(msg, wdir):
exit_util.exit_error(msg)
raise RuntimeError(msg)

if not (optd['fasta'] or optd['restart_pkl']):
msg = "One of -fasta or -restart_pkl option is required."
Expand Down Expand Up @@ -74,8 +74,7 @@ def process_benchmark_options(optd):
# Benchmark Mode
if optd['native_pdb'] or optd['benchmark_mode']:
if optd['native_pdb'] and not os.path.isfile(optd['native_pdb']):
msg = "Cannot find crystal structure PDB: {0}".format(optd['native_pdb'])
exit_util.exit_error(msg)
raise RuntimeError("Cannot find crystal structure PDB: {0}".format(optd['native_pdb']))
optd['benchmark_mode'] = True
optd['benchmark_dir'] = os.path.join(optd['work_dir'], "benchmark")
logger.info("*** AMPLE running in benchmark mode ***")
Expand Down Expand Up @@ -106,25 +105,22 @@ def process_options(optd):
# Check to see if mr_sequence was given and if not mr_sequence defaults to fasta
if optd['mr_sequence'] != None:
if not (os.path.exists(str(optd['mr_sequence']))):
msg = 'Cannot find mr sequence file: {0}'.format(optd['mr_sequence'])
exit_util.exit_error(msg)
raise RuntimeError('Cannot find mr sequence file: {0}'.format(optd['mr_sequence']))
else:
optd['mr_sequence'] = optd['fasta']
# Process the fasta file and run all the checks on the sequence
sequence_util.process_fasta(optd, canonicalise=True)

# Not sure if name actually required - see make_fragments.pl
if optd['name'] and len(optd['name']) != 4:
msg = '-name argument is the wrong length, use 4 chars eg ABCD'
exit_util.exit_error(msg)
raise RuntimeError('-name argument is the wrong length, use 4 chars eg ABCD')
# Underscore required by rosetta make_fragments.pl
optd['name'] += '_'
# MTZ file processing
try:
mtz_util.processReflectionFile(optd)
except Exception, e:
msg = "Error processing reflection file: {0}".format(e)
exit_util.exit_error(msg, sys.exc_info()[2])
raise RuntimeError("Error processing reflection file: {0}".format(e))
# Contact file processing
if optd['contact_file'] or optd['bbcontacts_file'] or not optd["no_contact_prediction"]:
contact_util.ContactUtil.check_options(optd)
Expand All @@ -134,8 +130,7 @@ def process_options(optd):
if optd['missing_domain']:
logger.info('Processing missing domain\n')
if not os.path.exists(optd['domain_all_chains_pdb']):
msg = 'Cannot find file domain_all_chains_pdb: {0}'.format(optd['domain_all_chains_pdb'])
exit_util.exit_error(msg)
raise RuntimeError('Cannot find file domain_all_chains_pdb: {0}'.format(optd['domain_all_chains_pdb']))
process_mr_options(optd)
process_benchmark_options(optd)

Expand All @@ -144,13 +139,11 @@ def process_options(optd):
if optd['submit_qtype']:
optd['submit_qtype'] = optd['submit_qtype'].upper()
if optd['submit_cluster'] and not optd['submit_qtype']:
msg = 'Must use -submit_qtype argument to specify queueing system (e.g. QSUB, LSF ) if submitting to a cluster.'
exit_util.exit_error(msg)
raise RuntimeError('Must use -submit_qtype argument to specify queueing system (e.g. QSUB, LSF ) if submitting to a cluster.')
try:
optd['purge'] = int(optd['purge'])
except ValueError:
msg = 'Purge must be specified as an integer, got: {}'.format(optd['purge'])
exit_util.exit_error(msg)
except (ValueError, KeyError):
raise RuntimeError('Purge must be specified as an integer, got: {}'.format(optd['purge']))
logger.info('*** Purge mode level %d specified - intermediate files will be deleted ***', optd['purge'])
return

Expand All @@ -166,11 +159,9 @@ def process_modelling_options(optd):
optd['make_models'] = False
elif optd['cluster_dir']:
if not os.path.isdir(optd['cluster_dir']):
msg = "Import cluster cannot find directory: {0}".format(optd['cluster_dir'])
exit_util.exit_error(msg)
raise RuntimeError("Import cluster cannot find directory: {0}".format(optd['cluster_dir']))
if not glob.glob(os.path.join(optd['cluster_dir'], "*.pdb")):
msg = "Import cluster cannot find pdbs in directory: {0}".format(optd['cluster_dir'])
exit_util.exit_error(msg)
raise RuntimeError("Import cluster cannot find pdbs in directory: {0}".format(optd['cluster_dir']))
logger.info("Importing pre-clustered models from directory: {0}\n".format(optd['cluster_dir']))
optd['cluster_method'] = 'import'
optd['make_frags'] = False
Expand All @@ -187,21 +178,17 @@ def process_modelling_options(optd):
if not ample_util.is_exe(str(optd['gesamt_exe'])):
optd['gesamt_exe'] = os.path.join(os.environ['CCP4'], 'bin', 'gesamt' + ample_util.EXE_EXT)
if not ample_util.is_exe(str(optd['gesamt_exe'])):
msg = 'Using homologs without an alignment file and cannot find gesamt_exe: {0}'.format(
optd['gesamt_exe'])
exit_util.exit_error(msg)
raise RuntimeError('Using homologs without an alignment file and cannot find gesamt_exe: {0}'.format(
optd['gesamt_exe']))
elif optd['homolog_aligner'] == 'mustang':
if not ample_util.is_exe(str(optd['mustang_exe'])):
msg = 'Using homologs without an alignment file and cannot find mustang_exe: {0}'.format(
optd['mustang_exe'])
exit_util.exit_error(msg)
raise RuntimeError('Using homologs without an alignment file and cannot find mustang_exe: {0}'.format(
optd['mustang_exe']))
else:
msg = 'Unknown homolog_aligner: {0}'.format(optd['homolog_aligner'])
exit_util.exit_error(msg)
raise RuntimeError('Unknown homolog_aligner: {0}'.format(optd['homolog_aligner']))
if not os.path.isdir(str(optd['models'])):
msg = "Homologs option requires a directory of pdb models to be supplied\n" + \
"Please supply the models with the -models flag"
exit_util.exit_error(msg)
raise RuntimeError("Homologs option requires a directory of pdb models to be supplied\n" + \
"Please supply the models with the -models flag")
optd['import_models'] = True
elif optd['models']:
optd['import_models'] = True
Expand All @@ -216,8 +203,7 @@ def process_modelling_options(optd):
optd['truncation_method'] = "scores"
# Check import flags
if optd['import_ensembles'] and (optd['import_models']):
msg = "Cannot import both models and ensembles/clusters!"
exit_util.exit_error(msg)
raise RuntimeError("Cannot import both models and ensembles/clusters!")
# NMR Checks
if optd['nmr_model_in']:
logger.info("Using nmr_model_in file: {0}".format(optd['nmr_model_in']))
Expand All @@ -228,8 +214,7 @@ def process_modelling_options(optd):
optd['make_models'] = True
if optd['nmr_remodel_fasta']:
if not os.path.isfile(optd['nmr_remodel_fasta']):
msg = "Cannot find nmr_remodel_fasta file: {0}".format(optd['nmr_remodel_fasta'])
exit_util.exit_error(msg)
raise RuntimeError("Cannot find nmr_remodel_fasta file: {0}".format(optd['nmr_remodel_fasta']))
else:
optd['nmr_remodel_fasta'] = optd['fasta']
msg = "NMR model will be remodelled with ROSETTA using the sequence from: {0}".format(
Expand All @@ -241,9 +226,8 @@ def process_modelling_options(optd):
logger.info(msg)
else:
if not (os.path.isfile(optd['frags_3mers']) and os.path.isfile(optd['frags_9mers'])):
msg = "frags_3mers and frag_9mers files given, but cannot locate them:\n{0}\n{1}\n".format(
optd['frags_3mers'], optd['frags_9mers'])
exit_util.exit_error(msg)
raise RuntimeError("frags_3mers and frag_9mers files given, but cannot locate them:\n{0}\n{1}\n".format(
optd['frags_3mers'], optd['frags_9mers']))
optd['make_frags'] = False
else:
optd['make_frags'] = False
Expand All @@ -256,20 +240,17 @@ def process_modelling_options(optd):
# If the user has given both fragment files we check they are ok and unset make_frags
if optd['frags_3mers'] and optd['frags_9mers']:
if not os.path.isfile(optd['frags_3mers']) or not os.path.isfile(optd['frags_9mers']):
msg = "frags_3mers and frag_9mers files given, but cannot locate them:\n{0}\n{1}\n".format(
optd['frags_3mers'], optd['frags_9mers'])
exit_util.exit_error(msg)
raise RuntimeError("frags_3mers and frag_9mers files given, but cannot locate them:\n{0}\n{1}\n".format(
optd['frags_3mers'], optd['frags_9mers']))
optd['make_frags'] = False
if optd['make_frags'] and (optd['frags_3mers'] or optd['frags_9mers']):
msg = "make_frags set to true, but you have given the path to the frags_3mers or frags_9mers"
exit_util.exit_error(msg)

raise RuntimeError("make_frags set to true, but you have given the path to the frags_3mers or frags_9mers")
if not optd['make_frags'] and not (optd['frags_3mers'] and optd['frags_9mers']):
msg = """*** Missing fragment files! ***
Please supply the paths to the fragment files using the -frags_3mers and -frags_9mers flags.
These can be generated using the Robetta server: http://robetta.bakerlab.org
Please see the AMPLE documentation for further information."""
exit_util.exit_error(msg)
raise RuntimeError(msg)

# Check we can find all the required programs
# Maxcluster handled differently as we may need to download the binary
Expand All @@ -281,8 +262,7 @@ def process_modelling_options(optd):
try:
optd['gesamt_exe'] = ample_util.find_exe(optd['gesamt_exe'])
except ample_util.FileNotFoundError as e:
logger.info("Cannot find Gesamt executable: {0}".format(optd['gesamt_exe']))
raise (e)
raise RuntimeError("Cannot find Gesamt executable: {0}".format(optd['gesamt_exe']))
# Ensemble options
if optd['cluster_method'] in [SPICKER_RMSD, SPICKER_TM]:
if not optd['spicker_exe']:
Expand All @@ -307,18 +287,13 @@ def process_modelling_options(optd):
elif optd['cluster_method'] in ['import', 'random', 'skip']:
pass
else:
msg = "Unrecognised cluster_method: {0}".format(optd['cluster_method'])
exit_util.exit_error(msg)

raise RuntimeError("Unrecognised cluster_method: {0}".format(optd['cluster_method']))
if not optd['theseus_exe']:
optd['theseus_exe'] = os.path.join(os.environ['CCP4'], 'bin', 'theseus' + ample_util.EXE_EXT)

try:
optd['theseus_exe'] = ample_util.find_exe(optd['theseus_exe'])
except ample_util.FileNotFoundError:
msg = "Cannot find theseus executable: {0}".format(optd['theseus_exe'])
exit_util.exit_error(msg)

raise RuntimeError("Cannot find theseus executable: {0}".format(optd['theseus_exe']))
# SCRWL - we always check for SCRWL as if we are processing QUARK models we want to add sidechains to them
if not optd['scwrl_exe']:
optd['scwrl_exe'] = os.path.join(os.environ['CCP4'], 'bin', 'Scwrl4' + ample_util.EXE_EXT)
Expand All @@ -328,10 +303,8 @@ def process_modelling_options(optd):
logger.info("Cannot find Scwrl executable: {0}".format(optd['scwrl_exe']))
if optd['use_scwrl']:
raise (e)

if "subcluster_radius_thresholds" in optd and not optd["subcluster_radius_thresholds"]:
optd["subcluster_radius_thresholds"] = SUBCLUSTER_RADIUS_THRESHOLDS

# REM: This should really be disentangled and moved up to definition of all homologs options
# REM: but could cause confusion with defaults down here.
if "side_chain_treatments" in optd and not optd["side_chain_treatments"]:
Expand All @@ -343,18 +316,14 @@ def process_modelling_options(optd):
optd["side_chain_treatments"] = map(str.lower, optd["side_chain_treatments"])
unrecognised_sidechains = set(optd["side_chain_treatments"]) - set(ALLOWED_SIDE_CHAIN_TREATMENTS)
if unrecognised_sidechains:
msg = "Unrecognised side_chain_treatments: {0}".format(unrecognised_sidechains)
logger.critical(msg)
exit_util.exit_error(msg)

raise("Unrecognised side_chain_treatments: {0}".format(unrecognised_sidechains))
if optd['make_frags']:
if optd['use_homs']:
logger.info('Making fragments (including homologues)')
else:
logger.info('Making fragments EXCLUDING HOMOLOGUES')
else:
logger.info('NOT making Fragments')

if optd['make_models']:
logger.info('\nMaking Rosetta Models')
else:
Expand Down Expand Up @@ -412,7 +381,6 @@ def process_mr_options(optd):
optd['shelxe_rebuild_arpwarp'] = False
else:
logger.info('Using arpwarp script: %s', os.path.join(os.environ['warpbin'], "auto_tracing.sh"))

# Print out what is being done
if optd['refine_rebuild_arpwarp'] or optd['shelxe_rebuild_arpwarp']:
logger.info('Rebuilding in Bucaneer')
Expand All @@ -425,8 +393,7 @@ def process_mr_options(optd):
logger.info('Not rebuilding in ARP/wARP')
# If shelxe_rebuild is set we need use_shelxe to be set
if optd['shelxe_rebuild'] and not optd['use_shelxe']:
msg = 'shelxe_rebuild is set but use_shelxe is False. Please make sure you have shelxe installed.'
exit_util.exit_error(msg)
raise RuntimeError('shelxe_rebuild is set but use_shelxe is False. Please make sure you have shelxe installed.')


def process_restart_options(optd):
Expand Down

0 comments on commit bb63e73

Please sign in to comment.