Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding data specific p-value filters #788

Merged
merged 9 commits into from
Sep 30, 2024
8 changes: 7 additions & 1 deletion src/gentropy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,16 @@ class GWASCatalogSumstatsPreprocessConfig(StepConfig):
class EqtlCatalogueConfig(StepConfig):
"""eQTL Catalogue step configuration."""

session: Any = field(
default_factory=lambda: {
"start_hail": True,
}
)
eqtl_catalogue_paths_imported: str = MISSING
eqtl_catalogue_study_index_out: str = MISSING
eqtl_catalogue_credible_sets_out: str = MISSING
mqtl_quantification_methods_blacklist: list[str] = field(default_factory=lambda: [])
eqtl_lead_pvalue_threshold: float = 1e-3
_target_: str = "gentropy.eqtl_catalogue.EqtlCatalogueStep"


Expand Down Expand Up @@ -169,6 +175,7 @@ class FinngenFinemappingConfig(StepConfig):
_target_: str = (
"gentropy.finngen_finemapping_ingestion.FinnGenFinemappingIngestionStep"
)
finngen_finemapping_lead_pvalue_threshold: float = 1e-5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one thing I'm not sure about. You have added finngen_finemapping_lead_pvalue_threshold to the relevant config, and refer to as pvalue_cutoff=FinngenFinemappingConfig().finngen_finemapping_lead_pvalue_threshold in the step. However, finngen_finemapping_lead_pvalue_threshold it not an argument for FinnGenFinemappingIngestionStep. Is it OK? Would all parameters in the config passed to the step? Would that cause any problem? @project-defiant , what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, double-checked with @project-defiant and @d0choa and all parameters in the setepConfig classes needs to be parameters in the init function of the step.



@dataclass
Expand Down Expand Up @@ -503,7 +510,6 @@ class StudyLocusValidationStepConfig(StepConfig):
valid_study_locus_path: str = MISSING
invalid_study_locus_path: str = MISSING
invalid_qc_reasons: list[str] = MISSING
gwas_significance: float = WindowBasedClumpingStepConfig.gwas_significance
_target_: str = "gentropy.study_locus_validation.StudyLocusValidationStep"


Expand Down
5 changes: 5 additions & 0 deletions src/gentropy/eqtl_catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from gentropy.common.session import Session
from gentropy.config import EqtlCatalogueConfig
from gentropy.datasource.eqtl_catalogue.finemapping import EqtlCatalogueFinemapping
from gentropy.datasource.eqtl_catalogue.study_index import EqtlCatalogueStudyIndex

Expand Down Expand Up @@ -61,6 +62,10 @@ def __init__(
credible_sets = EqtlCatalogueFinemapping.from_susie_results(processed_susie_df)
study_index = EqtlCatalogueStudyIndex.from_susie_results(processed_susie_df)

credible_sets = credible_sets.validate_lead_pvalue(
pvalue_cutoff=EqtlCatalogueConfig().eqtl_lead_pvalue_threshold
)

# Load
study_index.df.write.mode(session.write_mode).parquet(
eqtl_catalogue_study_index_out
Expand Down
4 changes: 4 additions & 0 deletions src/gentropy/finngen_finemapping_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def __init__(
finngen_susie_finemapping_cs_summary_files=finngen_susie_finemapping_cs_summary_files,
)

finngen_finemapping_df = finngen_finemapping_df.validate_lead_pvalue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor stylistic comment, and it is absolutely my preference, but I like to use as few variables as possible:

(
    # Reading Finngen finemapped dataset and convert it to study locus:
    FinnGenFinemapping.from_finngen_susie_finemapping(
        spark=session.spark,
        finngen_susie_finemapping_snp_files=finngen_susie_finemapping_snp_files,
        finngen_susie_finemapping_cs_summary_files=finngen_susie_finemapping_cs_summary_files,
    )
    # Flagging sub-significnat loci:
    .validate_lead_pvalue(
        pvalue_cutoff=FinngenFinemappingConfig().finngen_finemapping_lead_pvalue_threshold
    )
    # Write the output.
    .df.write.mode(session.write_mode).parquet(
        finngen_finemapping_out
    )
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please carefully check, I removed the variables but not sure

pvalue_cutoff=FinngenFinemappingConfig().finngen_finemapping_lead_pvalue_threshold
)

# Write the output.
finngen_finemapping_df.df.write.mode(session.write_mode).parquet(
finngen_finemapping_out
Expand Down
7 changes: 7 additions & 0 deletions src/gentropy/pics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from gentropy.common.session import Session
from gentropy.config import WindowBasedClumpingStepConfig
from gentropy.dataset.study_locus import CredibleInterval, StudyLocus
from gentropy.method.pics import PICS

Expand Down Expand Up @@ -31,5 +32,11 @@ def __init__(
picsed_sl = PICS.finemap(study_locus_ld_annotated).filter_credible_set(
credible_interval=CredibleInterval.IS99
)

# Validate lead p-value
picsed_sl = picsed_sl.validate_lead_pvalue(
pvalue_cutoff=WindowBasedClumpingStepConfig().gwas_significance
)

# Write
picsed_sl.df.write.mode(session.write_mode).parquet(picsed_study_locus_out)
2 changes: 0 additions & 2 deletions src/gentropy/study_locus_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def __init__(
session: Session,
study_index_path: str,
study_locus_path: list[str],
gwas_significance: float,
valid_study_locus_path: str,
invalid_study_locus_path: str,
invalid_qc_reasons: list[str] = [],
Expand All @@ -30,7 +29,6 @@ def __init__(
session (Session): Session object.
study_index_path (str): Path to study index file.
study_locus_path (list[str]): Path to study locus dataset.
gwas_significance (float): GWAS significance threshold.
valid_study_locus_path (str): Path to write the valid records.
invalid_study_locus_path (str): Path to write the output file.
invalid_qc_reasons (list[str]): List of invalid quality check reason names from `StudyLocusQualityCheck` (e.g. ['SUBSIGNIFICANT_FLAG']).
Expand Down
Loading