-
Notifications
You must be signed in to change notification settings - Fork 11
feat: GWAS Catalog harmonisation prototype #270
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b260081
chore: merge main
d0choa ac51225
feat: partitioning GWAS Catalog dataset to 20 equally-sized partitions
d0choa 02095fd
fix: missing config
d0choa 5764336
feat: dag with gwas catalog harmonisation
d0choa cfc7a75
feat: adding more primary workers to help with the task
d0choa 43c7ad1
refactor: changed autoscaling policy
d0choa 57a3e02
feat: allow to specify number of preeptible workers
d0choa 6c16a72
fix: bugs on to_do_list
d0choa 4625afd
chore: merge branch 'main' into do_gwascat_harmonisation
d0choa 55e21be
revert: version number
d0choa 55046b5
fix: gwas_catalog_sumstat_preprocess no longer needs study_id
d0choa 85cfff5
fix: unnecessary config causes issues
d0choa 019c52f
Merge branch 'main' into do_gwascat_harmonisation
d0choa 14d6103
chore: merge branch 'main' into do_gwascat_harmonisation
d0choa 2c8c54e
fix: improved regexp
d0choa e03ccfb
chore: merge branch 'main' into do_gwascat_harmonisation
d0choa fd5d103
refactor: generalising the config
d0choa 5ea1db7
Merge branch 'main' into do_gwascat_harmonisation
d0choa 6f897c3
fix: rename cluster to prevent clashes with other dags
d0choa 2d64fe2
Merge branch 'main' into do_gwascat_harmonisation
d0choa 6a373ea
Update src/airflow/dags/gwas_catalog_harmonisation.py
d0choa caa8895
Merge branch 'main' into do_gwascat_harmonisation
DSuveges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_target_: otg.gwas_catalog_sumstat_preprocess.GWASCatalogSumstatsPreprocessStep | ||
raw_sumstats_path: ??? | ||
out_sumstats_path: ??? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
"""Airflow DAG for the Preprocess part of the pipeline.""" | ||
from __future__ import annotations | ||
|
||
import re | ||
import time | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import common_airflow as common | ||
from airflow.decorators import task | ||
from airflow.models.dag import DAG | ||
from airflow.providers.google.cloud.operators.gcs import GCSListObjectsOperator | ||
|
||
CLUSTER_NAME = "otg-gwascatalog-harmonisation" | ||
AUTOSCALING = "gwascatalog-harmonisation" | ||
|
||
SUMMARY_STATS_BUCKET_NAME = "open-targets-gwas-summary-stats" | ||
|
||
with DAG( | ||
dag_id=Path(__file__).stem, | ||
description="Open Targets Genetics — GWAS Catalog harmonisation", | ||
default_args=common.shared_dag_args, | ||
**common.shared_dag_kwargs, | ||
): | ||
# List raw harmonised files from GWAS Catalog | ||
list_inputs = GCSListObjectsOperator( | ||
task_id="list_raw_harmonised", | ||
bucket=SUMMARY_STATS_BUCKET_NAME, | ||
prefix="raw-harmonised", | ||
match_glob="**/*.h.tsv.gz", | ||
) | ||
# List parquet files that have been previously processed | ||
list_outputs = GCSListObjectsOperator( | ||
task_id="list_harmonised_parquet", | ||
bucket=SUMMARY_STATS_BUCKET_NAME, | ||
prefix="harmonised", | ||
match_glob="**/_SUCCESS", | ||
) | ||
|
||
# Create list of pending jobs | ||
@task(task_id="create_to_do_list") | ||
def create_to_do_list(**kwargs: Any) -> Any: | ||
"""Create the to-do list of studies. | ||
|
||
Args: | ||
**kwargs (Any): Keyword arguments. | ||
|
||
Returns: | ||
Any: To-do list. | ||
""" | ||
ti = kwargs["ti"] | ||
raw_harmonised = ti.xcom_pull( | ||
task_ids="list_raw_harmonised", key="return_value" | ||
) | ||
print("Number of raw harmonised files: ", len(raw_harmonised)) | ||
to_do_list = [] | ||
# Remove the ones that have been processed | ||
parquets = ti.xcom_pull(task_ids="list_harmonised_parquet", key="return_value") | ||
print("Number of parquet files: ", len(parquets)) | ||
for path in raw_harmonised: | ||
match_result = re.search( | ||
"raw-harmonised/(.*)/(GCST\d+)/harmonised/(.*)\.h\.tsv\.gz", path | ||
) | ||
if match_result: | ||
study_id = match_result.group(2) | ||
if f"harmonised/{study_id}.parquet/_SUCCESS" not in parquets: | ||
to_do_list.append(path) | ||
print("Number of jobs to submit: ", len(to_do_list)) | ||
ti.xcom_push(key="to_do_list", value=to_do_list) | ||
|
||
# Submit jobs to dataproc | ||
@task(task_id="submit_jobs") | ||
def submit_jobs(**kwargs: Any) -> None: | ||
"""Submit jobs to dataproc. | ||
|
||
Args: | ||
**kwargs (Any): Keyword arguments. | ||
""" | ||
ti = kwargs["ti"] | ||
todo = ti.xcom_pull(task_ids="create_to_do_list", key="to_do_list") | ||
print("Number of jobs to submit: ", len(todo)) | ||
for i in range(len(todo)): | ||
# Not to exceed default quota 400 jobs per minute | ||
if i > 0 and i % 399 == 0: | ||
time.sleep(60) | ||
input_path = todo[i] | ||
match_result = re.search( | ||
"raw-harmonised/(.*)/(GCST\d+)/harmonised/(.*)\.h\.tsv\.gz", input_path | ||
) | ||
if match_result: | ||
study_id = match_result.group(2) | ||
print("Submitting job for study: ", study_id) | ||
common.submit_pyspark_job_no_operator( | ||
cluster_name=CLUSTER_NAME, | ||
step_id="gwas_catalog_sumstat_preprocess", | ||
other_args=[ | ||
f"step.raw_sumstats_path=gs://{SUMMARY_STATS_BUCKET_NAME}/{input_path}", | ||
f"step.out_sumstats_path=gs://{SUMMARY_STATS_BUCKET_NAME}/harmonised/{study_id}.parquet", | ||
], | ||
) | ||
|
||
# list_inputs >> | ||
( | ||
[list_inputs, list_outputs] | ||
>> create_to_do_list() | ||
>> common.create_cluster( | ||
CLUSTER_NAME, | ||
autoscaling_policy=AUTOSCALING, | ||
num_workers=8, | ||
num_preemptible_workers=8, | ||
master_machine_type="n1-highmem-64", | ||
worker_machine_type="n1-standard-2", | ||
) | ||
>> common.install_dependencies(CLUSTER_NAME) | ||
>> submit_jobs() | ||
# >> common.delete_cluster(CLUSTER_NAME) | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.