Commit 7875183b authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[cmd] Refactor parser:

- default group for I/O options
- increase text width
parent c796c596
......@@ -349,25 +349,35 @@ class CustomFormatter(
def main():
"""Argument parser"""
# parser configuration
# Global parser configuration
global parser
parser = argparse.ArgumentParser(
description="Cadbiom - Command Line Interface",
formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(prog, width=90),
epilog="""Examples:
$ cadbiom_cmd solutions_search -h""",
$ cadbiom_cmd solutions_search -h""",
)
# Default log level: debug
parser.add_argument("-vv", "--verbose", nargs="?", default="info")
# Subparsers
# Subparsers and ability to get the current subcommand name
subparsers = parser.add_subparsers(title="subcommands", dest="subcommand")
# Common parser: I/O group with model file requirement
parent_parser = argparse.ArgumentParser(add_help=False)
input_output_group = parent_parser.add_argument_group(title="I/O")
input_output_group.add_argument("model_file", help="Cadbiom model (.bcx file).")
# Increase the width of help text
custom_formatter = lambda prog: CustomFormatter(prog, width=90)
# PS:
# nargs='?': optional
# Default actions: https://docs.python.org/dev/library/argparse.html#action
############################################################################
## Solutions-search commands ###############################################
############################################################################
# subparser: Compute macs
# steps = 7
# final_prop = "P"
......@@ -376,16 +386,15 @@ $ cadbiom_cmd solutions_search -h""",
parser_search = subparsers.add_parser(
"solutions_search",
help=solutions_search.__doc__,
formatter_class=lambda prog: CustomFormatter(prog, width=90),
parents=[parent_parser],
formatter_class=custom_formatter,
epilog="""Examples:
$ cadbiom_cmd solutions_search model_pid.bcx SRP9 --steps 10 --output ./SRP9_solutions/
$ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --output""",
$ cadbiom_cmd solutions_search model_pid.bcx SRP9 --steps 10 --output ./SRP9_solutions/
$ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --output""",
)
## I/O
input_output_group = parser_search.add_argument_group(title="I/O")
input_output_group.add_argument("model_file", help="Cadbiom model (.bcx file).")
input_output_group.add_argument(
parser_search._action_groups[2].add_argument(
"--output",
action=ReadableDir,
nargs="?",
......@@ -460,9 +469,11 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
parser_search.set_defaults(func=solutions_search)
############################################################################
## Solutions-related commands ##############################################
############################################################################
# subparser: Sort solutions in alphabetical order in place
## subparser: Sort solutions in alphabetical order in place
# Solution file (complete or not)
parser_solutions_sort = subparsers.add_parser(
"solutions_sort", help=solutions_sort.__doc__
......@@ -474,21 +485,21 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_solutions_sort.set_defaults(func=solutions_sort)
# subparser: Representation of the trajectories of MACs in a complete file.
## subparser: Representation of the trajectories of MACs in a complete file.
# Model file (xml : cadbiom language)
# Solution file (mac_complete)
parser_trajectories = subparsers.add_parser(
"solutions_2_graphs",
help=solutions_2_graphs.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parents=[parent_parser],
formatter_class=custom_formatter,
)
parser_trajectories.add_argument("model_file", help="Cadbiom model (.bcx file).")
parser_trajectories.add_argument(
parser_trajectories._action_groups[2].add_argument(
"path",
help="Complete solution file or directory with MAC solutions files "
"(*mac_complete.txt files) generated with the 'compute_macs' command.",
)
parser_trajectories.add_argument(
parser_trajectories._action_groups[2].add_argument(
"--output",
action=ReadableDir,
nargs="?",
......@@ -497,21 +508,21 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_trajectories.set_defaults(func=solutions_2_graphs)
# subparser: Decompilation of trajectories of MACs in a complete file/dir.
## subparser: Decompilation of trajectories of MACs in a complete file/dir.
# Model file (xml : cadbiom language)
# Solution file (mac_complete)
parser_queries_2_json = subparsers.add_parser(
"queries_2_json",
help=queries_2_json.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parents=[parent_parser],
formatter_class=custom_formatter,
)
parser_queries_2_json.add_argument("model_file", help="Cadbiom model (.bcx file).")
parser_queries_2_json.add_argument(
parser_queries_2_json._action_groups[2].add_argument(
"path",
help="Complete solution file or directory with MAC solutions files "
"(*mac_complete.txt files) generated with the 'compute_macs' command.",
)
parser_queries_2_json.add_argument(
parser_queries_2_json._action_groups[2].add_argument(
"--output",
action=ReadableDir,
nargs="?",
......@@ -527,13 +538,13 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_queries_2_json.set_defaults(func=queries_2_json)
# subparser: Make an interaction weighted graph based on the searched
## subparser: Make an interaction weighted graph based on the searched #####
# molecule of interest
# Require JSON decompilated solutions files
parser_json_2_interaction_graph = subparsers.add_parser(
"json_2_interaction_graph",
help=json_2_interaction_graph.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=custom_formatter,
)
parser_json_2_interaction_graph.add_argument(
"molecules_of_interest",
......@@ -557,37 +568,37 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_json_2_interaction_graph.set_defaults(func=json_2_interaction_graph)
# subparser: Common representation of the trajectories of MACs in a complete file.
## subparser: Common representation of the trajectories of MACs in a complete file.
# Model file (xml : cadbiom language)
# Solution file (mac_complete)
parser_trajectories = subparsers.add_parser(
"queries_2_common_graph",
help=queries_2_common_graph.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parents=[parent_parser],
formatter_class=custom_formatter,
)
parser_trajectories.add_argument("model_file", help="Cadbiom model (.bcx file).")
parser_trajectories.add_argument(
parser_trajectories._action_groups[2].add_argument(
"path",
help="Complete solution file or directory with MAC solutions files "
"(*mac_complete.txt files) generated with the 'compute_macs' command.",
)
# Outputs
parser_trajectories.add_argument(
parser_trajectories._action_groups[2].add_argument(
"--graphs", action="store_true", help="Create a GraphML file for each MAC file."
)
parser_trajectories.add_argument(
parser_trajectories._action_groups[2].add_argument(
"--csv",
action="store_true",
help="Create a CSV file containing a summary about places/entities "
"of the solutions.",
)
parser_trajectories.add_argument(
parser_trajectories._action_groups[2].add_argument(
"--json",
action="store_true",
help="Create a JSON formated file containing a summary about "
"places/entities of the solutions.",
)
parser_trajectories.add_argument(
parser_trajectories._action_groups[2].add_argument(
"--output",
action=ReadableDir,
nargs="?",
......@@ -596,23 +607,21 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_trajectories.set_defaults(func=queries_2_common_graph)
# subparser: Create a matrix of occurrences counting entities in the solutions.
## subparser: Create a matrix of occurrences counting entities in the solutions.
# Model file (xml : cadbiom language)
# Solution file (mac.txt)
parser_occurrences_matrix = subparsers.add_parser(
"queries_2_occcurrence_matrix",
help=queries_2_occcurrence_matrix.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser_occurrences_matrix.add_argument(
"model_file", help="Cadbiom model (.bcx file)."
parents=[parent_parser],
formatter_class=custom_formatter,
)
parser_occurrences_matrix.add_argument(
parser_occurrences_matrix._action_groups[2].add_argument(
"path",
help="Directory with MAC solutions files "
"(*mac.txt files) generated with the 'compute_macs' command.",
)
parser_occurrences_matrix.add_argument(
parser_occurrences_matrix._action_groups[2].add_argument(
"--output",
action=ReadableDir,
nargs="?",
......@@ -626,13 +635,13 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_occurrences_matrix.set_defaults(func=queries_2_occcurrence_matrix)
# subparser: Merge solutions to a csv file
## subparser: Merge solutions to a csv file ################################
# Solution file (mac)
# Output (csv)
parser_merge_macs = subparsers.add_parser(
"merge_macs",
help=merge_macs.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=custom_formatter,
)
parser_merge_macs.add_argument("solutions_directory", nargs="?", default="result/")
parser_merge_macs.add_argument(
......@@ -644,19 +653,19 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_merge_macs.set_defaults(func=merge_macs)
############################################################################
## Model-related commands ##################################################
############################################################################
# subparser: Mapping of identifiers
# output: CSV file
parser_model_identifier_mapping = subparsers.add_parser(
"model_identifier_mapping",
help=model_identifier_mapping.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parents=[parent_parser],
formatter_class=custom_formatter,
)
parser_model_identifier_mapping.add_argument(
"model_file", help="Cadbiom model (.bcx file)."
)
group = parser_model_identifier_mapping.add_mutually_exclusive_group(required=True)
group = parser_model_identifier_mapping._action_groups[2].add_mutually_exclusive_group(required=True)
group.add_argument(
"--external_file",
help="File with 1 external identifiers to be mapped per line.",
......@@ -668,12 +677,12 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_model_identifier_mapping.set_defaults(func=model_identifier_mapping)
# subparser: Model comparison
## subparser: Model comparison #############################################
# 2 models
parser_model_comparison = subparsers.add_parser(
"model_comparison",
help=model_comparison.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=custom_formatter,
)
parser_model_comparison.add_argument(
"model_file_1", help="Cadbiom model (.bcx file)."
......@@ -699,16 +708,17 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_model_comparison.set_defaults(func=model_comparison)
# subparser: Model info
## subparser: Model info ###################################################
# 1 model
parser_model_info = subparsers.add_parser(
"model_info",
help=model_info.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parents=[parent_parser],
formatter_class=custom_formatter,
)
parser_model_info.add_argument("model_file", help="Cadbiom model (.bcx file).")
# Filters
group = parser_model_info.add_mutually_exclusive_group(required=True)
filters_group = parser_model_info.add_argument_group(title="Filters")
group = filters_group.add_mutually_exclusive_group(required=True)
# PS: Argparse doesn't allow to select a default value here
group.add_argument(
"--default",
......@@ -737,13 +747,13 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
help="Retrieve data only for the smallmolecules in the model.",
)
# Outputs
parser_model_info.add_argument(
parser_model_info._action_groups[2].add_argument(
"--csv",
action="store_true",
help="Create a CSV file containing data about previously filtered "
"places/entities of the model.",
)
parser_model_info.add_argument(
parser_model_info._action_groups[2].add_argument(
"--json",
action="store_true",
help="Create a JSON formated file containing data about previously "
......@@ -751,7 +761,7 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
"model itself (boundaries, transitions, events, entities locations,"
" entities types).",
)
parser_model_info.add_argument(
parser_model_info._action_groups[2].add_argument(
"--output",
action=ReadableDir,
nargs="?",
......@@ -760,13 +770,13 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
)
parser_model_info.set_defaults(func=model_info)
# subparser: Model graph
## subparser: Model graph ##################################################
parser_model_graph = subparsers.add_parser(
"model_graph",
help=model_graph.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parents=[parent_parser],
formatter_class=custom_formatter,
)
parser_model_graph.add_argument("model_file", help="Cadbiom model (.bcx file).")
# Additional data
parser_model_graph.add_argument(
"--centralities",
......@@ -776,25 +786,25 @@ $ cadbiom_cmd solutions_search model_pid.bcx --input_file my_queries.txt --outpu
"Works in conjunction with the ``--json`` option.",
)
# Outputs
parser_model_graph.add_argument(
parser_model_graph._action_groups[2].add_argument(
"--graph",
action="store_true",
help="Translate the model into a GraphML formated file which can "
"be opened in Cytoscape.",
)
parser_model_graph.add_argument(
parser_model_graph._action_groups[2].add_argument(
"--json",
action="store_true",
help="Create a JSON formated file containing a summary of the graph "
"based on the model.",
)
parser_model_graph.add_argument(
parser_model_graph._action_groups[2].add_argument(
"--json_graph",
action="store_true",
help="Create a JSON formated file containing the graph based on the "
"model, which can be opened by Web applications.",
)
parser_model_graph.add_argument(
parser_model_graph._action_groups[2].add_argument(
"--output",
action=ReadableDir,
nargs="?",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment