Skip to content

Commit fcffead

Browse files
Reorder commands minor CLI cleanups
Closes #38
1 parent 384e92f commit fcffead

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

bio2zarr/cli.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@
77
from . import plink
88
from . import provenance
99

10+
class NaturalOrderGroup(click.Group):
11+
"""
12+
List commands in the order they are provided in the help text.
13+
"""
14+
15+
def list_commands(self, ctx):
16+
return self.commands.keys()
17+
18+
1019
# Common arguments/options
1120
verbose = click.option("-v", "--verbose", count=True, help="Increase verbosity")
1221

22+
version = click.version_option(version=f"{provenance.__version__}")
23+
1324
worker_processes = click.option(
1425
"-p", "--worker-processes", type=int, default=1, help="Number of worker processes"
1526
)
@@ -19,12 +30,11 @@
1930
"--column-chunk-size",
2031
type=int,
2132
default=64,
22-
help="Size of exploded column chunks",
33+
help="Approximate uncompressed size of exploded column chunks in MiB",
2334
)
2435

2536
# Note: -l and -w were chosen when these were called "width" and "length".
2637
# possibly there are better letters now.
27-
# TODO help text
2838
variants_chunk_size = click.option(
2939
"-l",
3040
"--variants-chunk-size",
@@ -41,21 +51,15 @@
4151
help="Chunk size in the samples dimension",
4252
)
4353

44-
version = click.version_option(version=f"{provenance.__version__}")
45-
4654

47-
# Note: logging hasn't been implemented in the code at all, this is just
48-
# a first pass to try out some ways of doing things to see what works.
4955
def setup_logging(verbosity):
5056
level = "WARNING"
5157
if verbosity == 1:
5258
level = "INFO"
5359
elif verbosity >= 2:
5460
level = "DEBUG"
5561
# NOTE: I'm not that excited about coloredlogs, just trying it out
56-
# as it is installed by cyvcf2 anyway. We will have some complicated
57-
# stuff doing on with threads and processes, to logs might not work
58-
# so well anyway.
62+
# as it is installed by cyvcf2 anyway.
5963
coloredlogs.install(level=level)
6064

6165

@@ -78,13 +82,14 @@ def explode(vcfs, out_path, verbose, worker_processes, column_chunk_size):
7882
show_progress=True,
7983
)
8084

85+
8186
@click.command
8287
@click.argument("vcfs", nargs=-1, required=True)
8388
@click.argument("out_path", type=click.Path())
8489
@click.option("-n", "--target-num-partitions", type=int, required=True)
8590
@verbose
8691
@worker_processes
87-
def explode_init(vcfs, out_path, target_num_partitions, verbose, worker_processes):
92+
def dexplode_init(vcfs, out_path, target_num_partitions, verbose, worker_processes):
8893
"""
8994
Initial step for parallel conversion of VCF(s) to columnar intermediate format
9095
"""
@@ -97,13 +102,15 @@ def explode_init(vcfs, out_path, target_num_partitions, verbose, worker_processe
97102
show_progress=True,
98103
)
99104

105+
100106
@click.command
101107
@click.argument("path", type=click.Path())
102-
def explode_partition_count(path):
108+
def dexplode_partition_count(path):
103109
"""
104110
Count the actual number of partitions in a parallel conversion of VCF(s) to columnar intermediate format
105111
"""
106-
print(vcf.explode_partition_count(path))
112+
click.echo(vcf.explode_partition_count(path))
113+
107114

108115
@click.command
109116
@click.argument("path", type=click.Path(), required=True)
@@ -112,7 +119,7 @@ def explode_partition_count(path):
112119
@verbose
113120
@worker_processes
114121
@column_chunk_size
115-
def explode_slice(path, start, end, verbose, worker_processes, column_chunk_size):
122+
def dexplode_slice(path, start, end, verbose, worker_processes, column_chunk_size):
116123
"""
117124
Convert VCF(s) to columnar intermediate format
118125
"""
@@ -126,22 +133,24 @@ def explode_slice(path, start, end, verbose, worker_processes, column_chunk_size
126133
show_progress=True,
127134
)
128135

136+
129137
@click.command
130138
@click.argument("path", type=click.Path(), required=True)
131139
@verbose
132-
def explode_finalise(path, verbose):
140+
def dexplode_finalise(path, verbose):
133141
"""
134142
Final step for parallel conversion of VCF(s) to columnar intermediate format
135143
"""
136144
setup_logging(verbose)
137145
vcf.explode_finalise(path)
138146

147+
139148
@click.command
140149
@click.argument("if_path", type=click.Path())
141150
@verbose
142151
def inspect(if_path, verbose):
143152
"""
144-
Inspect an intermediate format file
153+
Inspect an intermediate format or Zarr path.
145154
"""
146155
setup_logging(verbose)
147156
data = vcf.inspect(if_path)
@@ -248,21 +257,21 @@ def validate(vcfs, out_path):
248257

249258

250259
@version
251-
@click.group()
260+
@click.group(cls=NaturalOrderGroup)
252261
def vcf2zarr():
253262
pass
254263

255264

256265
# TODO figure out how to get click to list these in the given order.
266+
vcf2zarr.add_command(convert_vcf)
257267
vcf2zarr.add_command(explode)
258-
vcf2zarr.add_command(explode_init)
259-
vcf2zarr.add_command(explode_partition_count)
260-
vcf2zarr.add_command(explode_slice)
261-
vcf2zarr.add_command(explode_finalise)
262268
vcf2zarr.add_command(inspect)
263269
vcf2zarr.add_command(mkschema)
264270
vcf2zarr.add_command(encode)
265-
vcf2zarr.add_command(convert_vcf)
271+
vcf2zarr.add_command(dexplode_init)
272+
vcf2zarr.add_command(dexplode_partition_count)
273+
vcf2zarr.add_command(dexplode_slice)
274+
vcf2zarr.add_command(dexplode_finalise)
266275
vcf2zarr.add_command(validate)
267276

268277

0 commit comments

Comments
 (0)