Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Commit

Permalink
fix liftover test
Browse files Browse the repository at this point in the history
  • Loading branch information
nebfield committed Feb 16, 2024
1 parent 3a2b7f1 commit 293e74c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
53 changes: 47 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pgscatalog_utils.download.download_scorefile import download_scorefile
from pgscatalog_utils.match.preprocess import complement_valid_alleles
from pgscatalog_utils.scorefile.combine_scorefiles import combine_scorefiles
from pgscatalog_utils.scorefile.scorevariant import ScoreVariant

from tests.data import combine

Expand Down Expand Up @@ -94,17 +95,57 @@ def chain_files(tmp_path_factory):

@pytest.fixture(scope="session")
def hg38_coords():
rs11903757 = {"rsid": "rs11903757", "chr_name": "2", "chr_position": 191722478}
rs6061231 = {"rsid": "rs6061231", "chr_name": "20", "chr_position": 62381861}
return [rs11903757, rs6061231]
rs11903757 = ScoreVariant(
**{
"rsid": "rs11903757",
"chr_name": "2",
"chr_position": 191722478,
"row_nr": 0,
"effect_weight": 1,
"accession": "test",
"effect_allele": "A",
}
)
rs6061231 = ScoreVariant(
**{
"rsid": "rs6061231",
"chr_name": "20",
"chr_position": 62381861,
"row_nr": 1,
"effect_weight": 1,
"accession": "test",
"effect_allele": "A",
}
)
return (x for x in [rs11903757, rs6061231])


@pytest.fixture(scope="session")
def hg19_coords():
# hg38_coords in GRCh37, from dbSNP
rs11903757 = {"rsid": "rs11903757", "chr_name": "2", "chr_position": 192587204}
rs6061231 = {"rsid": "rs6061231", "chr_name": "20", "chr_position": 60956917}
return [rs11903757, rs6061231]
rs11903757 = ScoreVariant(
**{
"rsid": "rs11903757",
"chr_name": "2",
"chr_position": 192587204,
"row_nr": 0,
"effect_weight": 1,
"accession": "test",
"effect_allele": "A",
}
)
rs6061231 = ScoreVariant(
**{
"rsid": "rs6061231",
"chr_name": "20",
"chr_position": 60956917,
"row_nr": 1,
"effect_weight": 1,
"accession": "test",
"effect_allele": "A",
}
)
return (x for x in [rs11903757, rs6061231])


@pytest.fixture(scope="session")
Expand Down
24 changes: 11 additions & 13 deletions tests/test_liftover.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,30 @@ def test_liftover(hg38_coords, hg19_coords, chain_files):
Config.chain_dir = chain_files
Config.lo = create_liftover()
Config.min_lift = 0.95

hg38 = copy.deepcopy(hg38_coords)
hg38 = list(hg38_coords)
hg19 = list(hg19_coords)
hg19_ = copy.deepcopy(hg19)
hg38_ = copy.deepcopy(hg38)
lifted = list(
liftover(
hg38,
(x for x in hg38),
harmonised=False,
current_build=GenomeBuild.GRCh38,
target_build=GenomeBuild.GRCh37,
)
)

assert [x["chr_position"] for x in lifted] == [
x["chr_position"] for x in hg19_coords
]
assert [x["chr_name"] for x in lifted] == [x["chr_name"] for x in hg19_coords]
assert [x.chr_position for x in lifted] == [x.chr_position for x in hg19_]
assert [x.chr_name for x in lifted] == [x.chr_name for x in hg19_]

hg19 = copy.deepcopy(hg19_coords)
hg19 = copy.deepcopy(hg19)
lift_back = list(
liftover(
hg19,
(x for x in hg19),
harmonised=False,
current_build=GenomeBuild.GRCh37,
target_build=GenomeBuild.GRCh38,
)
)
assert [x["chr_position"] for x in lift_back] == [
x["chr_position"] for x in hg38_coords
]
assert [x["chr_name"] for x in lift_back] == [x["chr_name"] for x in hg38_coords]
assert [x.chr_position for x in lift_back] == [x.chr_position for x in hg38_]
assert [x.chr_name for x in lift_back] == [x.chr_name for x in hg38_]

0 comments on commit 293e74c

Please sign in to comment.