Skip to content

Commit 10fe15f

Browse files
author
Corentin
committed
documentation command
1 parent ea5d84e commit 10fe15f

File tree

5 files changed

+228
-1
lines changed

5 files changed

+228
-1
lines changed

CLI_Documentation.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# `MyoQuant`
2+
3+
MyoQuant Analysis Command Line Interface
4+
5+
**Usage**:
6+
7+
```console
8+
$ MyoQuant [OPTIONS] COMMAND [ARGS]...
9+
```
10+
11+
**Options**:
12+
13+
* `--help`: Show this message and exit.
14+
15+
**Commands**:
16+
17+
* `docs`: Generate documentation
18+
* `he-analysis`: Run the HE analysis and quantification on...
19+
* `sdh-analysis`: Run the SDH analysis and quantification on...
20+
21+
## `MyoQuant docs`
22+
23+
Generate documentation
24+
25+
**Usage**:
26+
27+
```console
28+
$ MyoQuant docs [OPTIONS] COMMAND [ARGS]...
29+
```
30+
31+
**Options**:
32+
33+
* `--help`: Show this message and exit.
34+
35+
**Commands**:
36+
37+
* `generate`: Generate markdown version of usage...
38+
39+
### `MyoQuant docs generate`
40+
41+
Generate markdown version of usage documentation
42+
43+
**Usage**:
44+
45+
```console
46+
$ MyoQuant docs generate [OPTIONS]
47+
```
48+
49+
**Options**:
50+
51+
* `--name TEXT`: The name of the CLI program to use in docs.
52+
* `--output FILE`: An output file to write docs to, like README.md.
53+
* `--help`: Show this message and exit.
54+
55+
## `MyoQuant he-analysis`
56+
57+
Run the HE analysis and quantification on the image.
58+
59+
**Usage**:
60+
61+
```console
62+
$ MyoQuant he-analysis [OPTIONS] IMAGE_PATH
63+
```
64+
65+
**Arguments**:
66+
67+
* `IMAGE_PATH`: The HE image file path to analyse. If using single channel images, this will be used as cytoplasm image to run CellPose. Please use the --fluo-nuc option to indicate the path to the nuclei single image to run Stardist. [required]
68+
69+
**Options**:
70+
71+
* `--mask-path FILE`: The path to a binary mask to hide slide region during analysis. It needs to be of the same resolution as input image and only pixel marked as 1 will be analyzed.
72+
* `--cellpose-path FILE`: The pre-computed CellPose mask to use for analysis. Will run Cellpose if no path provided. Required as an image file.
73+
* `--stardist-path FILE`: The pre-computed Stardist mask to use for analysis. Will run Stardist if no path provided. Required as an image file.
74+
* `--output-path PATH`: The path to the folder to save the results. Will save in the same folder as input image if not specified.
75+
* `--cellpose-diameter INTEGER`: Approximative single cell diameter in pixel for CellPose detection. If not specified, Cellpose will try to deduce it.
76+
* `--nms-thresh FLOAT RANGE`: NMS Threshold for Stardist nuclei detection. [default: 0.4; 0<=x<=1]
77+
* `--prob-thresh FLOAT RANGE`: Probability Threshold for Stardist nuclei detection. [default: 0.5; 0.5<=x<=1]
78+
* `--eccentricity-thresh FLOAT RANGE`: Eccentricity threshold value for a nucleus to be considered as internalized during nuclei classification. When very close to 1 almost all nuclei are considered as internalized. [default: 0.75; 0<=x<=1]
79+
* `--export-map / --no-export-map`: Export the original image with cells painted by classification label. [default: export-map]
80+
* `--export-stats / --no-export-stats`: Export per fiber and per nuclei stat table. [default: export-stats]
81+
* `--fluo-nuc FILE`: The path to single channel fluo image for nuclei.
82+
* `--help`: Show this message and exit.
83+
84+
## `MyoQuant sdh-analysis`
85+
86+
Run the SDH analysis and quantification on the image.
87+
88+
**Usage**:
89+
90+
```console
91+
$ MyoQuant sdh-analysis [OPTIONS] IMAGE_PATH
92+
```
93+
94+
**Arguments**:
95+
96+
* `IMAGE_PATH`: The image file path to analyse. [required]
97+
98+
**Options**:
99+
100+
* `--mask-path FILE`: The path to a binary mask to hide slide region during analysis. It needs to be of the same resolution as input image and only pixel marked as 1 will be analyzed.
101+
* `--model-path FILE`: The SDH model path to use for analysis. Will download latest one if no path provided.
102+
* `--cellpose-path FILE`: The pre-computed CellPose mask to use for analysis. Will run Cellpose if no path provided. Required as an image file.
103+
* `--output-path PATH`: The path to the folder to save the results. Will save in the current folder if not specified.
104+
* `--cellpose-diameter INTEGER`: Approximative single cell diameter in pixel for CellPose detection. If not specified, Cellpose will try to deduce it.
105+
* `--export-map / --no-export-map`: Export the original image with cells painted by classification label. [default: export-map]
106+
* `--export-stats / --no-export-stats`: Export per fiber stat table. [default: export-stats]
107+
* `--help`: Show this message and exit.
108+

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Using pip, you can simply install MyoQuant in a python environment with a simple
3333
To use the command-line tool, first activate your venv in which MyoQuant is installed: `source .venv/bin/activate`
3434
Then you can perform SDH or HE analysis. You can use the command `myoquant --help` to list available commands.
3535

36+
## 💡Full command documentation is avaliable here: [CLI Documentation](https://github.com/lambda-science/MyoQuant/blob/main/CLI_Documentation.md)
37+
3638
- **For SDH Image Analysis** the command is:
3739
`myoquant sdh-analysis IMAGE_PATH`
3840
Don't forget to run `myoquant sdh-analysis --help` for information about options.

myoquant/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
pretty_exceptions_show_locals=False,
1616
)
1717

18+
from .utils.docs import app as docs_app
19+
20+
app.add_typer(docs_app, name="docs", help="Generate documentation")
21+
1822

1923
@app.command()
2024
def sdh_analysis(

myoquant/utils/docs.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
from pathlib import Path
2+
from typing import cast
3+
4+
import typer
5+
import typer.core
6+
from click import Command, Group
7+
8+
9+
app = typer.Typer()
10+
11+
12+
def get_docs_for_click(
13+
*,
14+
obj: Command,
15+
ctx: typer.Context,
16+
indent: int = 0,
17+
name: str = "",
18+
call_prefix: str = "",
19+
) -> str:
20+
docs = "#" * (1 + indent)
21+
command_name = name or obj.name
22+
if call_prefix:
23+
command_name = f"{call_prefix} {command_name}"
24+
title = f"`{command_name}`" if command_name else "CLI"
25+
docs += f" {title}\n\n"
26+
if obj.help:
27+
docs += f"{obj.help}\n\n"
28+
usage_pieces = obj.collect_usage_pieces(ctx)
29+
if usage_pieces:
30+
docs += "**Usage**:\n\n"
31+
docs += "```console\n"
32+
docs += "$ "
33+
if command_name:
34+
docs += f"{command_name} "
35+
docs += f"{' '.join(usage_pieces)}\n"
36+
docs += "```\n\n"
37+
args = []
38+
opts = []
39+
for param in obj.get_params(ctx):
40+
rv = param.get_help_record(ctx)
41+
if rv is not None:
42+
if param.param_type_name == "argument":
43+
args.append(rv)
44+
elif param.param_type_name == "option":
45+
opts.append(rv)
46+
if args:
47+
docs += "**Arguments**:\n\n"
48+
for arg_name, arg_help in args:
49+
docs += f"* `{arg_name}`"
50+
if arg_help:
51+
docs += f": {arg_help}"
52+
docs += "\n"
53+
docs += "\n"
54+
if opts:
55+
docs += "**Options**:\n\n"
56+
for opt_name, opt_help in opts:
57+
docs += f"* `{opt_name}`"
58+
if opt_help:
59+
docs += f": {opt_help}"
60+
docs += "\n"
61+
docs += "\n"
62+
if obj.epilog:
63+
docs += f"{obj.epilog}\n\n"
64+
if isinstance(obj, Group):
65+
group: Group = cast(Group, obj)
66+
commands = group.list_commands(ctx)
67+
if commands:
68+
docs += "**Commands**:\n\n"
69+
for command in commands:
70+
command_obj = group.get_command(ctx, command)
71+
assert command_obj
72+
docs += f"* `{command_obj.name}`"
73+
command_help = command_obj.get_short_help_str()
74+
if command_help:
75+
docs += f": {command_help}"
76+
docs += "\n"
77+
docs += "\n"
78+
for command in commands:
79+
command_obj = group.get_command(ctx, command)
80+
assert command_obj
81+
use_prefix = ""
82+
if command_name:
83+
use_prefix += f"{command_name}"
84+
docs += get_docs_for_click(
85+
obj=command_obj, ctx=ctx, indent=indent + 1, call_prefix=use_prefix
86+
)
87+
return docs
88+
89+
90+
@app.command(help="Generate markdown version of usage documentation")
91+
def generate(
92+
ctx: typer.Context,
93+
name: str = typer.Option("", help="The name of the CLI program to use in docs."),
94+
output: Path = typer.Option(
95+
None,
96+
help="An output file to write docs to, like README.md.",
97+
file_okay=True,
98+
dir_okay=False,
99+
),
100+
) -> None:
101+
"""
102+
Generate Markdown docs for a Typer app.
103+
"""
104+
from __main__ import app as main_app
105+
106+
click_obj = typer.main.get_command(main_app)
107+
docs = get_docs_for_click(obj=click_obj, ctx=ctx, name=name)
108+
clean_docs = f"{docs.strip()}\n"
109+
if output:
110+
output.write_text(clean_docs)
111+
typer.echo(f"Docs saved to: {output}")
112+
else:
113+
typer.echo(clean_docs)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "myoquant"
3-
version = "0.1.7"
3+
version = "0.1.9"
44
description = "MyoQuant🔬: a tool to automatically quantify pathological features in muscle fiber histology images."
55
authors = ["Corentin Meyer <[email protected]>"]
66
maintainers = ["Corentin Meyer <[email protected]>"]

0 commit comments

Comments
 (0)