-
Notifications
You must be signed in to change notification settings - Fork 0
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!: use regbot for clinical trial fetching #89
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 @@ | ||
"""Provide tools for integrating DGIdb data with related resources.""" |
This file contains 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,135 @@ | ||
"""Integrate data from FDA clinical trials API.""" | ||
|
||
import logging | ||
|
||
from regbot.fetch.clinical_trials import StandardAge, Status, Study | ||
from regbot.fetch.clinical_trials import get_clinical_trials as get_trials_from_fda | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def _add_study_to_output(output: dict[str, list], drug_name: str, study: Study) -> None: | ||
"""Update `output` in-place with results from study | ||
|
||
:param output: in-progress raw columnar data | ||
:param drug_name: name of drug that was searched | ||
:param study: clinical trial study data to add to output | ||
""" | ||
output["drug_name"].append(drug_name.upper()) | ||
output["trial_id"].append(study.protocol.identification.nct_id) | ||
output["brief"].append(study.protocol.identification.brief_title) | ||
output["study_type"].append(study.protocol.design.study_type) | ||
min_age = ( | ||
study.protocol.eligibility.min_age | ||
if study.protocol and study.protocol.eligibility | ||
else None | ||
) | ||
output["min_age"].append(min_age) | ||
max_age = ( | ||
study.protocol.eligibility.max_age | ||
if study.protocol and study.protocol.eligibility | ||
else None | ||
) | ||
output["max_age"].append(max_age) | ||
age_groups = ( | ||
study.protocol.eligibility.std_age | ||
if study.protocol and study.protocol.eligibility | ||
else None | ||
) | ||
output["age_groups"].append(age_groups) | ||
output["pediatric"].append(StandardAge.CHILD in age_groups if age_groups else None) | ||
output["conditions"].append( | ||
study.protocol.conditions.conditions | ||
if study.protocol and study.protocol.conditions | ||
else None | ||
) | ||
output["interventions"].append( | ||
[i._asdict() for i in study.protocol.arms_intervention.interventions] | ||
if study.protocol | ||
and study.protocol.arms_intervention | ||
and study.protocol.arms_intervention.interventions | ||
else None | ||
) | ||
eligibility = study.protocol.eligibility | ||
if not eligibility: | ||
output["incl_excl_criteria"].append(None) | ||
output["population_sex"].append(None) | ||
output["population_description"] | ||
else: | ||
output["incl_excl_criteria"].append(eligibility.description) | ||
output["population_sex"].append(eligibility.sex) | ||
output["population_description"].append(eligibility.population) | ||
all_locations = ( | ||
study.protocol.contacts_locations.locations | ||
if study.protocol.contacts_locations | ||
and study.protocol.contacts_locations.locations | ||
else [] | ||
) | ||
|
||
potential_sites = [ | ||
{ | ||
"name": location.facility, | ||
"status": location.status, | ||
"city": location.city, | ||
"country": location.country, | ||
"coordinates": location.geo, | ||
} | ||
for location in all_locations | ||
if location.status | ||
in { | ||
Status.RECRUITING, | ||
Status.NOT_YET_RECRUITING, | ||
Status.AVAILABLE, | ||
Status.TEMPORARILY_NOT_AVAILABLE, | ||
Status.UNKNOWN, | ||
} | ||
] | ||
output["potential_sites"].append(potential_sites) | ||
|
||
|
||
def get_clinical_trials(terms: list[str]) -> dict: | ||
"""Acquire associated clinical trials data for drug term | ||
|
||
>>> from dgipy.dgidb import get_drugs | ||
>>> from dgipy.integration.clinical_trials import get_clinical_trials | ||
>>> import polars as pl # or another dataframe library of your choosing | ||
>>> drugs = ["imatinib", "sunitinib"] | ||
>>> df = pl.DataFrame(get_drugs(drugs)) | ||
>>> trial_df = pl.DataFrame(get_clinical_trials(drugs)) | ||
>>> annotated_df = df.join(trial_df, on="drug_name") | ||
|
||
:param terms: drugs of interest | ||
:return: all clinical trials data for drugs of interest in a DataFrame-ready dict | ||
""" | ||
if not isinstance(terms, list): | ||
_logger.warning( | ||
"Given `terms` arg doesn't appear to be a list. This argument should be a sequence of drug names (as strings)." | ||
) | ||
if not terms: | ||
msg = "Must supply nonempty argument for `terms`" | ||
raise ValueError(msg) | ||
|
||
output = { | ||
"drug_name": [], | ||
"trial_id": [], | ||
"brief": [], | ||
"study_type": [], | ||
"min_age": [], | ||
"max_age": [], | ||
"age_groups": [], | ||
"pediatric": [], | ||
"conditions": [], | ||
"interventions": [], | ||
"incl_excl_criteria": [], | ||
"population_sex": [], | ||
"population_description": [], | ||
"potential_sites": [], | ||
} | ||
|
||
for drug in terms: | ||
results = get_trials_from_fda(drug) | ||
|
||
for study in results: | ||
_add_study_to_output(output, drug, study) | ||
|
||
return output |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing drug_name