Skip to content

Commit

Permalink
Support excluding samples with files
Browse files Browse the repository at this point in the history
  • Loading branch information
Will-Tyler committed Sep 11, 2024
1 parent 6708f47 commit acdeb15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_bcftools_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def run_vcztools(args: str) -> str:
("view --no-version -s ^NA00001", "sample.vcf.gz"),
("view --no-version -s ^NA00003,NA00002", "sample.vcf.gz"),
("view --no-version -s ^NA00003,NA00002,NA00003", "sample.vcf.gz"),
("view --no-version -S ^tests/data/txt/samples.txt", "sample.vcf.gz"),
]
)
# fmt: on
Expand Down
5 changes: 5 additions & 0 deletions vcztools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,13 @@ def view(
raise ValueError(f"Output file extension must be .vcf, got: .{split[-1]}")

if samples_file:
exclude_samples_file = samples_file.startswith("^")
samples_file = samples_file.lstrip("^")
with open(samples_file) as file:
samples = samples or ""
assert samples == "" or samples_file.startswith("^") == exclude_samples_file
if exclude_samples_file and not samples.startswith("^"):
samples = "^" + samples
samples += ",".join(line.strip() for line in file.readlines())

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

0 comments on commit acdeb15

Please sign in to comment.