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

feat(l2g): limit l2g predictions to gwas-derived associations #408

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/otg/dataset/l2g_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def from_credible_set(
v2g: V2G,
coloc: Colocalisation,
) -> L2GPrediction:
"""Initialise L2G from feature matrix.
"""Extract L2G predictions for a set of credible sets derived from GWAS.

Args:
model_path (str): Path to the fitted model
Expand All @@ -62,9 +62,17 @@ def from_credible_set(
Returns:
L2GPrediction: L2G dataset
"""
gwas_study_locus = StudyLocus(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be a reasonable StudyLocus method. Most likely we will use it again study_locus.filterByStudyType(study_index, ["gwas"]).

It's a refactor so it could go in a different PR

_df=study_locus.df.join(
study_index.study_type_lut().filter(f.col("studyType") == "gwas"),
on="studyId",
how="inner",
),
_schema=StudyLocus.get_schema(),
)
fm = L2GFeatureMatrix.generate_features(
features_list=features_list,
study_locus=study_locus,
study_locus=gwas_study_locus,
study_index=study_index,
variant_gene=v2g,
colocalisation=coloc,
Expand Down
23 changes: 11 additions & 12 deletions src/otg/l2g.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ def __init__(
v2g = V2G.from_parquet(session, variant_gene_path)
coloc = Colocalisation.from_parquet(session, colocalisation_path)

if run_mode == "train":
if run_mode == "predict":
if not model_path or not predictions_path:
raise ValueError(
"model_path and predictions_path must be set for predict mode."
)
predictions = L2GPrediction.from_credible_set(
model_path, features_list, credible_set, studies, v2g, coloc
)
predictions.df.write.mode(session.write_mode).parquet(predictions_path)
session.logger.info(predictions_path)
elif run_mode == "train":
# Process gold standard and L2G features
gs_curation = session.spark.read.json(gold_standard_curation_path)
interactions = session.spark.read.parquet(gene_interactions_path)
Expand Down Expand Up @@ -160,14 +170,3 @@ def __init__(
**hyperparameters,
)
session.logger.info(model_path)

if run_mode == "predict":
if not model_path or not predictions_path:
raise ValueError(
"model_path and predictions_path must be set for predict mode."
)
predictions = L2GPrediction.from_credible_set(
model_path, features_list, credible_set, studies, v2g, coloc
)
predictions.df.write.mode(session.write_mode).parquet(predictions_path)
session.logger.info(predictions_path)