-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e1c238
commit ac397a9
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pathlib | ||
from io import StringIO | ||
|
||
from tests.utils import vcz_path_cache | ||
from vcztools.query import list_samples | ||
|
||
|
||
def test_list_samples(tmp_path): | ||
vcf_path = pathlib.Path("tests/data/vcf") / "sample.vcf.gz" | ||
vcz_path = vcz_path_cache(vcf_path) | ||
expected_output = "NA00001\nNA00002\nNA00003\n" | ||
|
||
with StringIO() as output: | ||
list_samples(vcz_path, output) | ||
assert output.getvalue() == expected_output | ||
|
||
list_samples(vcz_path, output=tmp_path / "sample_ids.txt") | ||
|
||
with open(tmp_path / "sample_ids.txt") as file: | ||
assert file.read() == expected_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pathlib | ||
from contextlib import ExitStack | ||
|
||
import zarr | ||
|
||
|
||
def list_samples(vcz_path, output=None): | ||
root = zarr.open(vcz_path, mode="r") | ||
|
||
with ExitStack() as stack: | ||
if isinstance(output, str) or isinstance(output, pathlib.Path): | ||
output = stack.enter_context(open(output, mode="w")) | ||
|
||
sample_ids = root["sample_id"][:] | ||
print("\n".join(sample_ids), file=output) |