Skip to content

Commit

Permalink
Merge pull request #53 from monarch-initiative/get_stage_info
Browse files Browse the repository at this point in the history
Get stage info
  • Loading branch information
pnrobinson authored Dec 5, 2023
2 parents 99093ce + d6ae809 commit 5e75975
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [
"tqdm"
]
[project.optional-dependencies]
test = ["pytest"]
test = ["pytest", "parameterized"]



Expand Down
50 changes: 47 additions & 3 deletions src/oncoexporter/cda/cda_disease_factory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

import phenopackets as PPkt
import pandas as pd

Expand Down Expand Up @@ -61,13 +63,18 @@ def to_ga4gh(self, row):
if not isinstance(row, pd.core.series.Series):
raise ValueError(f"Invalid argument. Expected pandas series but got {type(row)}")

disease_term = self._parse_diagnosis_into_ontology_term(
disease_term = self._parse_diagnosis_into_ontology_term(
primary_diagnosis=row["primary_diagnosis"],
primary_diagnosis_condition=row["primary_diagnosis_condition"],
primary_diagnosis_site=row["primary_diagnosis_site"]
)
## Collect other piences of data to add to the constructor on the next line
diseaseModel = OpDisease(disease_term=disease_term)
## Collect other pieces of data to add to the constructor on the next line

# Deal with stage
stage_term_list = self._parse_stage_into_ontology_terms(row['stage'])

diseaseModel = OpDisease(disease_term=disease_term,
disease_stage_term_list=stage_term_list)
return diseaseModel.to_ga4gh()

def _parse_diagnosis_into_ontology_term(self,
Expand Down Expand Up @@ -113,3 +120,40 @@ def _parse_diagnosis_into_ontology_term(self,
ontology_term.id = 'NCIT:C9133'
ontology_term.label = 'Lung Adenosquamous Carcinoma'
return ontology_term

def _parse_stage_into_ontology_terms(self, stage_str: str) -> List[PPkt.OntologyClass]:
ontology_term = PPkt.OntologyClass()
ontology_term.id ='NCIT:C92207' # Stage unknown
ontology_term.label = 'Stage Unknown'

if stage_str in ['Stage I', 'Stage 1', 'stage 1', 'stage I']:
ontology_term.id = 'NCIT:C27966'
ontology_term.label = 'Stage I'
elif stage_str in ['IA', 'Stage IA', 'stage IA']:
ontology_term.id = 'NCIT:C27975'
ontology_term.label = 'Stage IA'
elif stage_str in ['IB', 'Stage IB', 'stage IB']:
ontology_term.id = 'NCIT:C27976'
ontology_term.label = 'Stage IB'
elif stage_str in ['Stage II', 'Stage 2', 'stage 2', 'stage II']:
ontology_term.id = 'NCIT:C28054'
ontology_term.label = 'Stage II'
elif stage_str in ['IIA', 'Stage IIA', 'stage IIA']:
ontology_term.id = 'NCIT:C27967'
ontology_term.label = 'Stage IIA'
elif stage_str in ['IIB', 'Stage IIB', 'stage IIB']:
ontology_term.id = 'NCIT:C27968'
ontology_term.label = 'Stage IIB'
elif stage_str in ['Stage 3', 'stage 3']:
ontology_term.id = 'NCIT:C27970'
ontology_term.label = 'Stage III'
elif stage_str in ['IIIA', 'Stage IIIA', 'Stage 3A', 'stage 3A']:
ontology_term.id = 'NCIT:C27977'
ontology_term.label = 'Stage IIIA'
elif stage_str in ['IIIB', 'Stage IIIB', 'Stage 3B', 'stage 3B']:
ontology_term.id = 'NCIT:C27978'
ontology_term.label = 'Stage IIIB'
elif stage_str in ['IV', 'Stage 4']:
ontology_term.id = 'NCIT:C27971'
ontology_term.label = 'Stage IV'
return [ontology_term]
11 changes: 3 additions & 8 deletions src/oncoexporter/model/op_disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def __init__(self, disease_term:PPKt.OntologyClass,
excluded:bool=None,
iso8601duration_onset_age:str=None,
iso8601duration_resolution_age: str = None,
disease_stage_term_list:List[str]=None,
disease_stage_term_label:str=None,
disease_stage_term_list:List[PPKt.OntologyClass]=None,
clinical_tnm_finding_list:list=None,
primary_site_id:str=None,
primary_site_label: str = None,
Expand All @@ -42,13 +41,9 @@ def __init__(self, disease_term:PPKt.OntologyClass,
raise ValueError(f"If passed, argument \"disease_stage_term_list\" must be a list but was {type(disease_stage_term_list)}")
if len(disease_stage_term_list) == 0:
raise ValueError(f"If passed, argument \"disease_stage_term_list\" cannot be an empty list")


for term in disease_stage_term_list:
disease_obj.disease_stage.append(term)
self._disease = disease_obj





def to_ga4gh(self):
return self._disease
Loading

0 comments on commit 5e75975

Please sign in to comment.