Skip to content

Commit

Permalink
Merge pull request #365 from widdowquinn/parser_choices
Browse files Browse the repository at this point in the history
Explicitly list parser choices in `help` output
  • Loading branch information
baileythegreen authored Dec 17, 2021
2 parents 0e3d482 + 75852c6 commit 19517df
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 54 deletions.
19 changes: 10 additions & 9 deletions docs/subcmd_plot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ The ``plot`` subcommand will plot the results of an ANI analysis, specified by `

.. code-block:: text
usage: pyani.py plot [-h] [-l LOGFILE] [-v] [--debug] [--disable_tqdm] [--version]
[--citation] -o OUTDIR --run_id RUN_ID [--dbpath DBPATH]
[--formats FORMATS] [--method {seaborn,mpl,plotly}]
usage: pyani plot [-h] [-l LOGFILE] [-v] [--debug] [--disable_tqdm] [--version]
[--citation] -o OUTDIR --run_ids RUN_ID [RUN_ID ...]
[--dbpath DBPATH] [--formats FORMAT [FORMAT ...]]
[--method METHOD] [--workers WORKERS]
.. _SQLite3: https://www.sqlite.org/index.html

Expand All @@ -24,17 +25,17 @@ Flagged arguments
``--disable_tqdm``
Disable the ``tqdm`` progress bar while the plotting process runs. This is useful when testing to avoid aesthetic problems with test output.

``--formats FORMATS``
``--formats FORMAT [FORMAT ...]``
Graphics output format(s); more than one can be specified. Valid options are: (pdf/png/svg/jpg). (default: png)

``-l LOGFILE, --logfile LOGFILE``
Provide the location ``LOGFILE`` to which a logfile of the plotting process will be written.

``--method {seaborn,mpl,plotly}``
Graphics method to use for plotting. (default: seaborn)
``--method METHOD``
Graphics method to use for plotting; options (seaborn, mpl, plotly). (default: seaborn)

``-o OUTDIR, --o outdir OUTDIR``
Path to a directory where comparison plot files will be written.
Path to a directory where comparison plot files will be written.

``--run_id RUN_ID``
Unique database ID of the run to be plotted.
``--run_ids RUN_ID [RUN_ID ...]``
Unique database ID of the runs to be plotted.
26 changes: 16 additions & 10 deletions docs/subcmd_report.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
The ``report`` subcommand reports the contents of a local `SQLite3`_ database, located at ``dbpath``. Output files will be written to the ``outdir`` directory.


usage: pyani.py report [-h] [-l LOGFILE] [-v] [--debug] [--disable_tqdm] [--version]
[--citation] -o OUTDIR [--dbpath DBPATH] [--runs] [--genomes]
[--runs_genomes] [--genomes_runs] [--run_results RUN_RESULTS]
[--run_matrices RUN_MATRICES] [--formats FORMATS]
usage: pyani report [-h] [-l LOGFILE] [-v] [--debug] [--disable_tqdm] [--version]
[--citation] -o OUTDIR [--dbpath DBPATH] [--runs] [--genomes]
[--runs_genomes] [--genomes_runs]
[--run_results RUN_ID [RUN_ID ...]]
[--run_matrices RUN_ID [RUN_ID ...]] [--no_matrix_labels]
[--formats FORMAT [FORMAT ...]]

.. _SQLite3: https://www.sqlite.org/index.html

Expand All @@ -25,15 +27,19 @@ Flagged arguments
``--disable_tqdm``
Disable the ``tqdm`` progress bar while the report process runs. This is useful when testing to avoid aesthetic problems with test output.

``--formats FORMATS``
Output formats (in addition to .tab). (default: None)
``--formats FORMAT [FORMAT ...]``
Space-separated list of output formats (in addition to .tab);
possible values: {html, excel,stdout}. (default: None)

``--genomes``
Report table of genomes in database. (default: False)

``--genomes_runs``
Report table of all runs in which each genome in the database participates. (default: False)

``--no_matrix_labels``
Turn off row/column labels in output matrix files (default: False)

``-o OUTDIR, --outdir OUTDIR``
Directory where output analysis reports will be written.

Expand All @@ -43,11 +49,11 @@ Flagged arguments
``--runs_genomes``
Report table of all genomes for each run in database. (default: False)

``--run_matrices RUN_MATRICES``
Report matrices of results for a pyani run. (default: False)
``--run_matrices RUN_ID [RUN_ID ...]``
Report matrices of results for space-separated list of runs. (default: None)

``--run_results RUN_RESULTS``
Report table of results for a pyani run. (default: False)
``--run_results RUN_ID [RUN_ID ...]``
Report table of results for space-separated list of runs. (default: None)

``-v, --verbose``
Provide verbose output to ``STDOUT``.
19 changes: 13 additions & 6 deletions pyani/scripts/parsers/plot_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ def build(
required=True,
)
parser.add_argument(
"--run_id",
"--run_ids",
action="store",
dest="run_id",
dest="run_ids",
default=None,
help="run ID to plot",
metavar="RUN_ID",
nargs="+",
help="run IDs to plot",
required=True,
)
# Other optional arguments
Expand All @@ -93,16 +95,21 @@ def build(
"--formats",
dest="formats",
action="store",
default="png",
help="graphics output format (pdf/png/svg/jpg)",
default=["png"],
metavar="FORMAT",
nargs="+",
choices=["pdf", "png", "svg", "jpg"],
help="graphics output format; options: (pdf, png, svg, jpg)",
)
parser.add_argument(
"--method",
dest="method",
action="store",
default="seaborn",
help="graphics method to use for plotting",
metavar="METHOD",
nargs=1,
choices=["seaborn", "mpl", "plotly"],
help="graphics method to use for plotting; options (seaborn, mpl, plotly)",
)
parser.add_argument(
"--workers",
Expand Down
16 changes: 10 additions & 6 deletions pyani/scripts/parsers/report_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,19 @@ def build(
"--run_results",
action="store",
dest="run_results",
metavar="RUN_IDS",
metavar="RUN_ID",
nargs="+",
default=None,
help="Report table of results for comma separated list of runs",
help="Report table of results for space-separated list of runs",
)
parser.add_argument(
"--run_matrices",
action="store",
dest="run_matrices",
metavar="RUN_IDS",
metavar="RUN_ID",
nargs="+",
default=None,
help="Report matrices of results for comma separated list of runs",
help="Report matrices of results for space-separated list of runs",
)
parser.add_argument(
"--no_matrix_labels",
Expand All @@ -132,7 +134,9 @@ def build(
dest="formats",
action="store",
default=None,
choices=["html", "excel", "stdout"],
help="Output formats (in addition to .tab)",
metavar="FORMAT",
nargs="+",
choices=("html", "excel", "stdout"),
help="Space-separated list of output formats (in addition to .tab); possible values: {html, excel, stdout}",
)
parser.set_defaults(func=subcommands.subcmd_report)
11 changes: 6 additions & 5 deletions pyani/scripts/subcommands/subcmd_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ def subcmd_plot(args: Namespace) -> int:
session = pyani_orm.get_session(args.dbpath)

# Parse output formats
outfmts = args.formats.split(",")
outfmts = args.formats # .formats.split(",")
logger.debug("Requested output formats: %s", outfmts)
logger.debug("Type of formats variable: %s", type(outfmts))

# Work on each run:
run_ids = [int(run) for run in args.run_id.split(",")]
run_ids = [int(run) for run in args.run_ids]
logger.debug("Generating graphics for runs: %s", run_ids)
for run_id in run_ids:
write_run_plots(run_id, session, outfmts, args)
Expand All @@ -109,10 +110,10 @@ def write_run_plots(run_id: int, session, outfmts: List[str], args: Namespace) -
# Get results matrices for the run
logger.debug("Retrieving results matrices for run %s", run_id)
results = (
session.query(pyani_orm.Run).filter(pyani_orm.Run.run_id == args.run_id).first()
session.query(pyani_orm.Run).filter(pyani_orm.Run.run_id == run_id).first()
)
result_label_dict = pyani_orm.get_matrix_labels_for_run(session, args.run_id)
result_class_dict = pyani_orm.get_matrix_classes_for_run(session, args.run_id)
result_label_dict = pyani_orm.get_matrix_labels_for_run(session, run_id)
result_class_dict = pyani_orm.get_matrix_classes_for_run(session, run_id)
logger.debug(
f"Have {len(result_label_dict)} labels and {len(result_class_dict)} classes"
)
Expand Down
6 changes: 3 additions & 3 deletions pyani/scripts/subcommands/subcmd_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def subcmd_report(args: Namespace) -> int:

# Report table of comparison results for the indicated runs
if args.run_results:
run_ids = [run_id.strip() for run_id in args.run_results.split(",")]
run_ids = [run_id for run_id in args.run_results]
logger.debug("Attempting to write results tables for runs: %s", run_ids)
for run_id in run_ids:
logger.debug("Processing run ID %s", run_id)
Expand Down Expand Up @@ -266,7 +266,7 @@ def subcmd_report(args: Namespace) -> int:
# our matrices directly, here
if args.run_matrices:
show_index = not args.no_matrix_labels
for run_id in [run_id.strip() for run_id in args.run_matrices.split(",")]:
for run_id in [run_id for run_id in args.run_matrices]:
logger.debug("Extracting matrices for run %s", run_id)
run = session.query(Run).filter(Run.run_id == run_id).first()
matlabel_dict = get_matrix_labels_for_run(session, run_id)
Expand Down Expand Up @@ -331,5 +331,5 @@ def process_formats(args: Namespace) -> List[str]:
"""
formats = ["tab"]
if args.formats:
formats += [fmt.strip() for fmt in args.formats.split(",")]
formats += [fmt for fmt in args.formats]
return list(set(formats)) # remove duplicates
14 changes: 7 additions & 7 deletions tests/test_subcmd_05_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def setUp(self):
run_matrices=False,
no_matrix_labels=False,
force=True,
formats="html,excel,stdout",
formats=["html", "excel", "stdout"],
),
"genomes": Namespace(
outdir=self.outdir,
Expand All @@ -96,7 +96,7 @@ def setUp(self):
run_matrices=False,
no_matrix_labels=False,
force=True,
formats="html,excel,stdout",
formats=["html", "excel", "stdout"],
),
"runs_genomes": Namespace(
outdir=self.outdir,
Expand All @@ -109,7 +109,7 @@ def setUp(self):
run_matrices=False,
no_matrix_labels=False,
force=True,
formats="html,excel,stdout",
formats=["html", "excel", "stdout"],
),
"genomes_runs": Namespace(
outdir=self.outdir,
Expand All @@ -122,7 +122,7 @@ def setUp(self):
run_matrices=False,
no_matrix_labels=False,
force=True,
formats="html,excel,stdout",
formats=["html", "excel", "stdout"],
),
"run_results": Namespace(
outdir=self.outdir,
Expand All @@ -135,7 +135,7 @@ def setUp(self):
run_matrices=False,
no_matrix_labels=False,
force=True,
formats="html,excel,stdout",
formats=["html", "excel", "stdout"],
),
"run_matrices": Namespace(
outdir=self.outdir,
Expand All @@ -148,7 +148,7 @@ def setUp(self):
run_matrices="1",
no_matrix_labels=False,
force=True,
formats="html,excel",
formats=["html", "excel"],
),
"no_matrix_labels": Namespace(
outdir=self.outdir,
Expand All @@ -161,7 +161,7 @@ def setUp(self):
run_matrices="1",
no_matrix_labels=True,
force=True,
formats="html,excel",
formats=["html", "excel"],
),
}

Expand Down
16 changes: 8 additions & 8 deletions tests/test_subcmd_06_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,63 +76,63 @@ def setUp(self):
self.argsdict = {
"mpl_pdf": Namespace(
outdir=self.outdir / "mpl",
run_id=self.run_id,
run_ids=self.run_id,
dbpath=self.dbpath,
formats="pdf",
method="mpl",
workers=None,
),
"mpl_png": Namespace(
outdir=self.outdir / "mpl",
run_id=self.run_id,
run_ids=self.run_id,
dbpath=self.dbpath,
formats="png",
method="mpl",
workers=None,
),
"mpl_svg": Namespace(
outdir=self.outdir / "mpl",
run_id=self.run_id,
run_ids=self.run_id,
dbpath=self.dbpath,
formats="svg",
method="mpl",
workers=None,
),
"mpl_jpg": Namespace(
outdir=self.outdir / "mpl",
run_id=self.run_id,
run_ids=self.run_id,
dbpath=self.dbpath,
formats="jpg",
method="mpl",
workers=None,
),
"seaborn_pdf": Namespace(
outdir=self.outdir / "seaborn",
run_id=self.run_id,
run_ids=self.run_id,
dbpath=self.dbpath,
formats="pdf",
method="seaborn",
workers=None,
),
"seaborn_png": Namespace(
outdir=self.outdir / "seaborn",
run_id=self.run_id,
run_ids=self.run_id,
dbpath=self.dbpath,
formats="png",
method="seaborn",
workers=None,
),
"seaborn_svg": Namespace(
outdir=self.outdir / "seaborn",
run_id=self.run_id,
run_ids=self.run_id,
dbpath=self.dbpath,
formats="svg",
method="seaborn",
workers=None,
),
"seaborn_jpg": Namespace(
outdir=self.outdir / "seaborn",
run_id=self.run_id,
run_ids=self.run_id,
dbpath=self.dbpath,
formats="jpg",
method="seaborn",
Expand Down

0 comments on commit 19517df

Please sign in to comment.