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

Improve GDCAPIPhenoset #102

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
63 changes: 52 additions & 11 deletions xena_gdc_etl/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,67 @@
},
"GDC-PANCAN": {
"fields": [
"demographic.age_at_index",
"demographic.created_datetime",
"demographic.days_to_birth",
"demographic.days_to_death",
"demographic.demographic_id",
"demographic.ethnicity",
"demographic.gender",
"demographic.race",
"demographic.state",
"demographic.submitter_id",
"demographic.updated_datetime",
"demographic.vital_status",
"demographic.year_of_birth",
"demographic.year_of_death",
"diagnoses.age_at_diagnosis",
"diagnoses.classification_of_tumor",
"diagnoses.created_datetime",
"diagnoses.days_to_diagnosis",
"diagnoses.days_to_last_follow_up",
"diagnoses.diagnosis_id",
"diagnoses.icd_10_code",
"diagnoses.last_known_disease_status",
"diagnoses.morphology",
"diagnoses.primary_diagnosis",
"diagnoses.prior_malignancy",
"diagnoses.prior_treatment",
"diagnoses.progression_or_recurrence",
"diagnoses.site_of_resection_or_biopsy",
"diagnoses.state",
"diagnoses.submitter_id",
"diagnoses.synchronous_malignancy",
"diagnoses.tissue_or_organ_of_origin",
"diagnoses.tumor_grade",
"diagnoses.tumor_stage",
"diagnoses.updated_datetime",
"diagnoses.year_of_diagnosis",
"exposures.alcohol_history",
"exposures.bmi",
"exposures.cigarettes_per_day",
"exposures.created_datetime",
"exposures.exposure_id",
"exposures.height",
"exposures.pack_years_smoked",
"exposures.state",
"exposures.submitter_id",
"exposures.updated_datetime",
"exposures.weight",
"exposures.years_smoked",
"id",
"project.name",
"project.project_id",
"samples.is_ffpe",
"samples.sample_id",
"samples.sample_type",
"samples.sample_type_id",
"samples.submitter_id",
"samples.tissue_type",
"samples.tumor_code",
"samples.tumor_code_id",
"samples.tumor_descriptor",
"tissue_source_site.name",
"samples.submitter_id",
],
"expand": [
"demographic",
"diagnoses",
"exposures",
"family_histories",
],
}
"expand": [],
},
}
LIST_FIELDS = {
"FISH_test_component",
Expand Down
57 changes: 39 additions & 18 deletions xena_gdc_etl/xena_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,33 @@ def __get_samples_clinical(self, projects, fields, expand):
merged_df.drop(list(to_drops), axis=1, inplace=True)
return merged_df

def __build_query_dict(self, projects):
"""Builds the query dict that will be fed into ``gdc.search()``.

Args:
projects (list or str): one (str) or a list of GDC "project_id"(s).

Returns:
dict: A dictionary with projects, fields and expand as keys.
"""

if not isinstance(projects, list):
projects = [projects]
fields = set()
modified_projects = []
for project in projects:
fields |= set(CASES_FIELDS_EXPANDS[project]["fields"])
modified_projects.extend(projects)
if "GDC-PANCAN" in projects:
modified_projects.extend(list(GDC_XENA_COHORT.keys()))
modified_projects.remove("GDC-PANCAN")
query_dict = {
"projects": modified_projects,
"fields": list(fields),
"expand": [],
}
return query_dict

def __init__(
self,
projects,
Expand Down Expand Up @@ -1885,24 +1912,18 @@ def __init__(
)

def transform(self):
if self.projects == ["CPTAC-3"]:
xena_matrix = self.__get_samples_clinical(
projects=["CPTAC-3"],
fields=CASES_FIELDS_EXPANDS["CPTAC-3"]["fields"],
expand=CASES_FIELDS_EXPANDS["CPTAC-3"]["expand"],
)
xena_matrix = xena_matrix.set_index("samples.submitter_id")
elif self.projects == ["GDC-PANCAN"]:
xena_matrix = self.__get_samples_clinical(
projects=list(GDC_XENA_COHORT.keys()),
fields=CASES_FIELDS_EXPANDS["GDC-PANCAN"]["fields"],
expand=CASES_FIELDS_EXPANDS["GDC-PANCAN"]["expand"],
)
xena_matrix = (
xena_matrix
.dropna(axis=1, how="all")
.set_index("samples.submitter_id")
)
query_dict = self.__build_query_dict(self.projects)
xena_matrix = self.__get_samples_clinical(
projects=query_dict["projects"],
fields=query_dict["fields"],
expand=query_dict["expand"],
)
xena_matrix = (
xena_matrix
.dropna(axis=1, how="all")
.set_index("samples.submitter_id")
)
if "GDC-PANCAN" in self.projects:
print('Dropping TCGA-**-****-**Z samples ...')
xena_matrix = xena_matrix[~xena_matrix.index.str.endswith('Z')]
print('\rSaving matrix to {} ...'.format(self.matrix), end='')
Expand Down