From d89c97f7ba233999acbb2e8b1442631d685b5b22 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:38:21 +0200 Subject: [PATCH] Add argument parsing for bundle script Allows for non-interaction use (e.g. scripting) --- bundle.py | 81 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/bundle.py b/bundle.py index 2e6aeeb..76f2d18 100644 --- a/bundle.py +++ b/bundle.py @@ -14,6 +14,26 @@ import json import random +import argparse + +format_choices = ["bnet", "aeon", "sbml"] +input_choices = ["true", "false", "identity", "free", "random"] +filter_help_text = """Enter filter expression satisfied by the desired models [default: no filter]. +The filter expression is a Python expression that evaluates to True/False. +You can assume `variables` and `inputs` are lists of entity names (strings). +Variable `regulations` is a list of pairs of entity names. +Variable `metadata` is a dictionary representing the `metadata.json` file. +Finally, variable `model` is an AEON.py Boolean network. +""" + +parser = argparse.ArgumentParser( + description="This script is responsible for generating bundles of models with specific properties.", +) +parser.add_argument("-f", "--format", choices=format_choices) +parser.add_argument("-i", "--inputs", choices=input_choices) +parser.add_argument("--filter", help=filter_help_text) +parser.add_argument("-o", "--output-dir") +args = parser.parse_args() ENDC = '\033[0m' BOLD = '\033[1m' @@ -22,13 +42,17 @@ FORMAT = "aeon" while True: - print("Choose model format [bnet/aeon/sbml; default: aeon]") - print(BOLD, end="") - user_format = input().lower() - print(ENDC, end="") + if args.format is not None: + user_format = args.format + else: + print("Choose model format [bnet/aeon/sbml; default: aeon]") + print(BOLD, end="") + user_format = input().lower() + print(ENDC, end="") + if user_format == "": user_format = "aeon" - if user_format in ["bnet", "aeon", "sbml"]: + if user_format in format_choices: FORMAT = user_format print(f"Selected output format: {BOLD}{user_format}{ENDC}") break @@ -38,13 +62,17 @@ INPUTS = "free" while True: - print("Choose the representation of model inputs (i.e. source nodes) [true/false/identity/free/random; default: free]") - print(BOLD, end="") - user_inputs = input().lower() - print(ENDC, end="") + if args.inputs is not None: + user_inputs = args.inputs + else: + print("Choose the representation of model inputs (i.e. source nodes) [true/false/identity/free/random; default: free]") + print(BOLD, end="") + user_inputs = input().lower() + print(ENDC, end="") + if user_inputs == "": user_inputs = "free" - if user_inputs in ["true", "false", "identity", "free", "random"]: + if user_inputs in input_choices: INPUTS = user_inputs print(f"Selected input representation: {BOLD}{user_inputs}{ENDC}") break @@ -123,15 +151,18 @@ def check_filter(filter, model_dir): FILTER = "True" while True: - print("Enter filter expression satisfied by the desired models [default: no filter].") - print(" > The filter expression is a Python expression that evaluates to True/False.") - print(" > You can assume `variables` and `inputs` are lists of entity names (strings).") - print(" > Variable `regulations` is a list of pairs of entity names.") - print(" > Variable `metadata` is a dictionary representing the `metadata.json` file.") - print(" > Finally, variable `model` is an AEON.py Boolean network.") - print(BOLD, end="") - user_filter = input().lower() - print(ENDC, end="") + if args.filter is not None: + user_filter = args.filter + else: + print("Enter filter expression satisfied by the desired models [default: no filter].") + print(" > The filter expression is a Python expression that evaluates to True/False.") + print(" > You can assume `variables` and `inputs` are lists of entity names (strings).") + print(" > Variable `regulations` is a list of pairs of entity names.") + print(" > Variable `metadata` is a dictionary representing the `metadata.json` file.") + print(" > Finally, variable `model` is an AEON.py Boolean network.") + print(BOLD, end="") + user_filter = input().lower() + print(ENDC, end="") if user_filter == "": print("No filter given. All models will be included.") break @@ -157,10 +188,14 @@ def check_filter(filter, model_dir): OUT_DIR = "bbm-edition" while True: - print("Choose output directory: [default: bbm-edition]") - print(BOLD, end="") - user_dir = input().lower() - print(ENDC, end="") + if args.output_dir is not None: + user_dir = args.output_dir + else: + print("Choose output directory: [default: bbm-edition]") + print(BOLD, end="") + user_dir = input().lower() + print(ENDC, end="") + if user_dir != "": OUT_DIR = user_dir if isfile(OUT_DIR) or isdir(OUT_DIR):