microview.cli

The CLI module, intended for end users.

main()

MicroView, a reporting tool for taxonomic classification

MicroView agreggates reports from taxonomic classification tools, such as Kaiju and Kraken.

You can provide either a path to results in the -t argument or, with -df, a path to a 2-column CSV file, the first column sample paths and the second containing group names or contrasts.

Source code in microview/cli.py
14
15
16
17
18
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@click.command(context_settings=dict(help_option_names=["-h", "--help"]))
@click.version_option(prog_name="MicroView")
@optgroup.group(
    "Input data source",
    cls=RequiredMutuallyExclusiveOptionGroup,
    help="Input data source",
)
@optgroup.option(
    "-t",
    "--taxonomy",
    type=click.Path(path_type=Path),
    help="Path to taxonomy classification results",
)
@optgroup.option(
    "-df",
    "--csv-file",
    type=click.Path(path_type=Path),
    help="2-column CSV table (sample,group) with taxonomy classification results paths",
)
@click.option(
    "-o",
    "--output",
    default="microview_report.html",
    help="Report file name",
    type=click.Path(path_type=Path, writable=True, resolve_path=True),
)
def main(taxonomy: Path, csv_file: Path, output: Path) -> None:
    """
    MicroView, a reporting tool for taxonomic classification

    MicroView agreggates reports from taxonomic classification tools,
    such as Kaiju and Kraken.

    You can provide either a path to results
    in the -t argument or, with -df, a path to a 2-column CSV file,
    the first column sample paths and the second containing group names
    or contrasts.
    """

    console = Console(stderr=True, highlight=False)
    console.print(
        f"\n [bold]Running [blue]Micro[/][red]View[/] :glasses: [dim]v{mv_version}[/] \n"
    )
    data_source = taxonomy if taxonomy else csv_file

    with console.status("[bold]Reading report...[/]"):
        if csv_file is not None:
            parsed_result = parse_source_table(data_source, console)
            reports = parsed_result["samples"]
        else:
            reports = find_reports(data_source, console)
            parsed_result = None

    try:
        console.print(f"\n Found [bold]{len(reports)}[/] reports... \n")
        with console.status("[bold]Calculating metrics...[/]"):
            tax_results = get_tax_data(reports)
            # TODO: Improve this double check
            if parsed_result is not None:
                tax_plots = generate_taxo_plots(
                    tax_results, parsed_result["dataframe"], output_path=output
                )
            else:
                tax_plots = generate_taxo_plots(tax_results, output_path=output)
            render_base(tax_plots=tax_plots, dir_path=data_source, output_path=output)
        console.print(f"\n Done!\n", style="bold green")
    except Exception:
        console.print_exception(show_locals=True)