Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add samples file option to view CLI #76

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/data/txt/samples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NA00001
NA00003
5 changes: 5 additions & 0 deletions tests/test_bcftools_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def run_vcztools(args: str) -> str:
"view --no-version -G",
"sample.vcf.gz"
),
(
"view --no-update --no-version --samples-file "
"tests/data/txt/samples.txt",
"sample.vcf.gz"),
("view -I --no-version -S tests/data/txt/samples.txt", "sample.vcf.gz"),
]
)
# fmt: on
Expand Down
22 changes: 22 additions & 0 deletions vcztools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,26 @@ def query(path, list_samples, format):
default=None,
help="Regions to include.",
)
@click.option(
"-I",
"--no-update",
is_flag=True,
help="Do not recalculate INFO fields for the sample subset.",
)
@click.option(
"-s",
"--samples",
type=str,
default=None,
help="Samples to include.",
)
@click.option(
"-S",
"--samples-file",
type=str,
default=None,
help="File of sample names to include.",
)
@click.option(
"-G",
"--drop-genotypes",
Expand Down Expand Up @@ -120,7 +133,9 @@ def view(
no_version,
regions,
targets,
no_update,
samples,
samples_file,
drop_genotypes,
include,
exclude,
Expand All @@ -129,6 +144,13 @@ def view(
split = output.split(".")
raise ValueError(f"Output file extension must be .vcf, got: .{split[-1]}")

if samples_file:
with open(samples_file) as file:
samples = samples or ""
samples += ",".join(line.strip() for line in file.readlines())

# TODO: use no_update when fixing https://github.com/sgkit-dev/vcztools/issues/75

vcf_writer.write_vcf(
path,
output,
Expand Down