Skip to content

Commit

Permalink
feat: check for if no overlapping variants in LD index (#594)
Browse files Browse the repository at this point in the history
* feat: check for if no overlapping variants in LD index

* fix: removing unnecessary else statement
  • Loading branch information
Daniel-Considine authored May 1, 2024
1 parent 690d158 commit 962b79c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/gentropy/susie_finemapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import logging
import time
from typing import Any

Expand Down Expand Up @@ -142,9 +143,10 @@ def __init__(
sum_pips=sum_pips,
)
# Write result
result.df.write.mode(session.write_mode).parquet(
output_path + "/" + study_locus_to_finemap
)
if result is not None:
result.df.write.mode(session.write_mode).parquet(
output_path + "/" + study_locus_to_finemap
)

@staticmethod
def susie_finemapper_one_studylocus_row(
Expand Down Expand Up @@ -529,7 +531,7 @@ def susie_finemapper_ss_gathered(
purity_min_r2_threshold: float = 0.25,
cs_lbf_thr: float = 2,
sum_pips: float = 0.99,
) -> StudyLocus:
) -> StudyLocus | None:
"""Susie fine-mapper for StudyLocus row with locus annotated summary statistics.
Args:
Expand All @@ -546,7 +548,7 @@ def susie_finemapper_ss_gathered(
sum_pips (float): the expected sum of posterior probabilities in the locus, default is 0.99 (99% credible set)
Returns:
StudyLocus: StudyLocus object with fine-mapped credible sets
StudyLocus | None: StudyLocus object with fine-mapped credible sets, or None
"""
# PLEASE DO NOT REMOVE THIS LINE
pd.DataFrame.iteritems = pd.DataFrame.items
Expand Down Expand Up @@ -615,7 +617,9 @@ def susie_finemapper_ss_gathered(
gwas_index = gwas_df.join(
ld_index.select("variantId", "alleles", "idx"), on="variantId"
).sort("idx")

if gwas_index.rdd.isEmpty():
logging.warning("No overlapping variants in the LD Index")
return None
gnomad_ld = GnomADLDMatrix.get_numpy_matrix(
gwas_index, gnomad_ancestry=major_population
)
Expand Down

0 comments on commit 962b79c

Please sign in to comment.