Skip to content

Commit 5f5ac35

Browse files
committed
Add tskit CLI
1 parent 598c95f commit 5f5ac35

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

bio2zarr/cli.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,71 @@ def vcfpartition(vcfs, verbose, num_partitions, partition_size):
630630
)
631631
for region in regions:
632632
click.echo(f"{region}\t{vcf_path}")
633+
634+
635+
@click.command(name="convert")
636+
@click.argument("ts_path", type=click.Path(exists=True))
637+
@click.argument("zarr_path", type=click.Path())
638+
@click.option(
639+
"--ploidy",
640+
type=int,
641+
default=2,
642+
help="Ploidy to use when tree sequence has no individuals (default: 2)",
643+
)
644+
@click.option("--contig-id", type=str, help="Contig/chromosome ID (default: '1')")
645+
@click.option(
646+
"--isolated-as-missing", is_flag=True, help="Treat isolated nodes as missing"
647+
)
648+
@variants_chunk_size
649+
@samples_chunk_size
650+
@verbose
651+
@progress
652+
@worker_processes
653+
@force
654+
def convert_tskit(
655+
ts_path,
656+
zarr_path,
657+
ploidy,
658+
contig_id,
659+
isolated_as_missing,
660+
variants_chunk_size,
661+
samples_chunk_size,
662+
verbose,
663+
progress,
664+
worker_processes,
665+
force,
666+
):
667+
setup_logging(verbose)
668+
check_overwrite_dir(zarr_path, force)
669+
670+
import tskit
671+
672+
from bio2zarr import tskit as tskit_mod
673+
674+
ts = tskit.load(ts_path)
675+
676+
if ts.num_individuals == 0:
677+
individuals_nodes = ts.split_samples_by_ploidy(ploidy)
678+
else:
679+
individuals_nodes = ts.individuals_nodes
680+
681+
tskit_mod.convert(
682+
ts_path,
683+
zarr_path,
684+
individuals_nodes,
685+
contig_id=contig_id,
686+
isolated_as_missing=isolated_as_missing,
687+
variants_chunk_size=variants_chunk_size,
688+
samples_chunk_size=samples_chunk_size,
689+
worker_processes=worker_processes,
690+
show_progress=progress,
691+
)
692+
693+
694+
@version
695+
@click.group(cls=NaturalOrderGroup, name="tskit2zarr")
696+
def tskit2zarr_main():
697+
pass
698+
699+
700+
tskit2zarr_main.add_command(convert_tskit)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ documentation = "https://sgkit-dev.github.io/bio2zarr/"
5252
[project.scripts]
5353
vcf2zarr = "bio2zarr.cli:vcf2zarr_main"
5454
vcfpartition = "bio2zarr.cli:vcfpartition"
55+
tskit2zarr = "bio2zarr.cli:tskit2zarr_main"
5556

5657
[project.optional-dependencies]
5758
dev = [

0 commit comments

Comments
 (0)