From 22717880ad136636ec63123b02ada31400c9e64a Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Mon, 21 Aug 2023 10:40:43 +0200 Subject: [PATCH] Argument parsing (early version) --- convert_to_modelcif.py | 90 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 convert_to_modelcif.py diff --git a/convert_to_modelcif.py b/convert_to_modelcif.py new file mode 100755 index 0000000..129f0d4 --- /dev/null +++ b/convert_to_modelcif.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 + +"""Take the output of the AlphaPulldown pipeline and turn it into a ModelCIF +file with a lot of metadata in place.""" + +from absl import app +from absl import flags + + +FLAGS = flags.FLAGS +flags.DEFINE_list( + "metadata", + None, + "JSON files with information about experiment setup, one file per feature", +) +flags.DEFINE_string("af2_output", None, "Results of AlphaFold2 modelling") +flags.DEFINE_integer( + "model_selected", + None, + "Model to be converted into ModelCIF, use '--select_all' to convert all " + + "models found in '--af2_output'", +) +flags.DEFINE_bool( + "select_all", + False, + "Convert all models found in '--af2_output' into ModelCIF, excludes " + + "'--model_selected'", +) + + +def _mark_model_selection_as_mutual_exclusive(): + """Create & register a validator for model selection. + + Enforce only one option is set, either '--select_all' or '--model_selected'. + Enforce that at least one of '--select_all' or '--model_selected' is set + (so this options will not pop up in `flags.mark_flags_as_required`). + """ + + def _validate_mutual_exclusion_model_selection(flags_dict): + not_set_count = 0 + if flags_dict["model_selected"] is None: + not_set_count += 1 + if flags_dict["select_all"] is False: + not_set_count += 1 + + if not_set_count == 1: + return True + return False + + flags.register_multi_flags_validator( + ["model_selected", "select_all"], + _validate_mutual_exclusion_model_selection, + "Exactly one (and only one) argument needs to be set.", + ) + + +_mark_model_selection_as_mutual_exclusive() +flags.mark_flags_as_required(["metadata", "af2_output"]) +# ToDo: implement a flags.register_validator() for 'metadata', checking that +# the file exists and is readable. +# ToDo: implement a flags.register_validator() for 'af2_output', checking that +# the file directory exists and is readable (overkill: check directory +# structure). + + +def main(argv): + """Run as script.""" + """ + Here, the metadata json files for each feature are in features_monomers/ + directory. The models are in models/ directory, and usually there are many + complexes modelled using different permutations of the monomeric features. + For the sake of size, I send you the models of only one dimer + cage_B_and_cage_C/ that was generated using features_monomers/cage_B.pkl + and features_monomers/cage_C.pkl accordingly. + Please note that typically all the cage_?_feature_metadata.json files are + identical in terms of used databases and software versions and generated + in one go. + However, theoretically they could be generated using different binaries/DBs + versions, so maybe it makes sense to compare them and store both/all + versions if they are different. This merging can be done on our + AlphaPulldown side and may be added now or later on. Let me know if it is + critical for you now. + """ + del argv # Unused. + + +if __name__ == "__main__": + app.run(main) + +# LocalWords: ToDo -- GitLab