CLUI - Snailz Docs

Skip to content

# CLUI

Command-line interface.

## `cli()`

Main driver.

Source code in `src/snailz/clui.py`

    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    def cli():
        """Main driver."""

        args = parse_args()

        if args.defaults:
            print(json_dump(DEFAULT_PARAMS))
            return

        if args.outdir is None:
            print("output directory required (used --outdir)", file=sys.stderr)
            sys.exit(1)

        if args.params:
            try:
                params = ScenarioParams.model_validate(json.load(open(args.params, "r")))
            except Exception as exc:
                print(f"unable to read parameters from {args.params}: {exc}")
                sys.exit(1)
        else:
            params = ScenarioParams(
                rng_seed=DEFAULT_SEED,
                specimen_params=SpecimenParams(),
                assay_params=AssayParams(),
            )

        random.seed(params.rng_seed)
        scenario = Scenario.generate(params)
        scenario.to_csv(args.outdir)

## `parse_args()`

Parse command-line arguments.

Source code in `src/snailz/clui.py`

    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    def parse_args():
        """Parse command-line arguments."""

        parser = argparse.ArgumentParser()
        parser.add_argument(
            "--defaults", action="store_true", help="show default parameters"
        )
        parser.add_argument("--outdir", default=None, help="output directory")
        parser.add_argument("--params", default=None, help="JSON parameter file")
        return parser.parse_args()