Skip to content

Commit

Permalink
Patch to fix pgscatalog-intersect with bim input (#25)
Browse files Browse the repository at this point in the history
* fix pgscatalog-intersect with bim input

* bump patch

* delete unused fixture target_pvar

* drop unneeded try / except block for KeyErrors
  • Loading branch information
nebfield authored Jun 19, 2024
1 parent c8f7f02 commit a6440c3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pgscatalog.match/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pgscatalog.match"
version = "0.2.1"
version = "0.2.2"
description = "Tools for matching variants in PGS scoring files and target variant information files"
authors = ["Benjamin Wingfield <bwingfield@ebi.ac.uk>", "Samuel Lambert <sl925@medschl.cam.ac.uk>", "Laurent Gil <lg10@sanger.ac.uk>"]
readme = "README.md"
Expand Down
12 changes: 9 additions & 3 deletions pgscatalog.match/src/pgscatalog/match/cli/intersect_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,30 @@ def run_intersect():
o_tmp_t = []
target_heap = []
for path in args.target:
# assume inputs always have two extensions (bim.zst / pvar.zst)
path = pathlib.Path(path)
basename = path.name
stem = pathlib.Path(basename.split(".")[0])

logger.info("Reading TARGET variants: {}".format(path))
pvar = read_var_general(
path, chrom=None
) # essential not to filter target (messes up common line indexing)

loc_afreq = path.replace(".pvar.zst", ".afreq.gz")
loc_afreq = path.parent / stem.with_suffix(".afreq.gz")
afreq = read_var_general(
loc_afreq, chrom=None
) # essential not to filter target (messes up common line indexing)

loc_vmiss = path.replace(".pvar.zst", ".vmiss.gz")
loc_vmiss = path.parent / stem.with_suffix(".vmiss.gz")
vmiss = read_var_general(
loc_vmiss, chrom=None
) # essential not to filter target (messes up common line indexing)

for v, freq, miss in zip(pvar, afreq, vmiss):
if all([v["ID"], freq["ID"], miss["#ID"]]) is False:
if not all([v["ID"], freq["ID"], miss["#ID"]]):
raise ValueError("TARGET variant files are not sorted")

count_var_t += 1
ALTs = v["ALT"].split(",")
ALT_FREQS = [float(x) for x in freq["ALT_FREQS"].split(",")]
Expand Down
Binary file added pgscatalog.match/tests/data/target.bim.zst
Binary file not shown.
10 changes: 5 additions & 5 deletions pgscatalog.match/tests/test_intersect_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ def afreq(request):
return request.path.parent / "data" / "target.afreq.gz"


@pytest.fixture(scope="module")
def target(request):
return request.path.parent / "data" / "target.pvar.zst"


@pytest.fixture(scope="module")
def ref(request):
return request.path.parent / "data" / "ref.pvar.zst"


@pytest.fixture(params=["target.bim.zst", "target.pvar.zst"], scope="module")
def target(request):
return request.path.parent / "data" / request.param


def test_intersect_cli(tmp_path_factory, ref, target, afreq, vmiss):
outdir = tmp_path_factory.mktemp("outdir")

Expand Down

0 comments on commit a6440c3

Please sign in to comment.