Skip to content

Commit

Permalink
Add optional pt_id arg when making phenopackets
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Reese committed Feb 21, 2024
1 parent 7dccebb commit 4b6b1fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/phenotype2phenopacket/create/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create_synthetic_patient_phenopacket(
omim_disease: pl.DataFrame,
ontology_factory: Ontology,
output_dir: Path,
pt_id: str,
hpoa_version: str,
):
"""
Expand Down
10 changes: 7 additions & 3 deletions src/phenotype2phenopacket/utils/phenopacket_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ def __init__(self, human_phenotype_ontology: ProntoImplementation):
self.human_phenotype_ontology = human_phenotype_ontology
self.secrets_random_num = secrets.SystemRandom()

def create_individual(self, onset_range: OnsetTerm = None) -> Individual:
def create_individual(self,
onset_range: OnsetTerm = None,
pt_id: str = "patient1") -> Individual:
"""
Create an Individual object.
Expand All @@ -612,7 +614,7 @@ def create_individual(self, onset_range: OnsetTerm = None) -> Individual:
if onset_range is None or onset_range.upper_age == 0 and onset_range.lower_age == 0:
age = None
return Individual(
id="patient1",
id="patient1" if pt_id is None else pt_id,
time_at_last_encounter=(
TimeElement(age=Age(iso8601duration=f"P{age}Y")) if age is not None else None
),
Expand Down Expand Up @@ -792,6 +794,7 @@ def create_phenopacket(
self,
omim_disease_df: pl.DataFrame,
hpoa_version: str,
pt_id: str,
onset: OnsetTerm = None,
) -> PhenopacketFile:
"""
Expand All @@ -803,6 +806,7 @@ def create_phenopacket(
Args:
omim_disease_df (pl.DataFrame): DataFrame containing phenotype annotation disease entries.
hpoa_version (str): Version of the Human Phenotype Ontology Annotation.
pt_id (str): The patient ID. If not given, defaults to "patient1" in create_individual()
onset (OnsetTerm, optional): An OnsetTerm object representing the age range of onset. Defaults to None.
Returns:
Expand All @@ -814,7 +818,7 @@ def create_phenopacket(
return PhenopacketFile(
phenopacket=Phenopacket(
id=phenotype_annotation_entry["disease_name"].lower().replace(" ", "_"),
subject=self.create_individual(onset),
subject=self.create_individual(onset, pt_id),
phenotypic_features=phenotypic_features,
diseases=[self.create_disease(phenotype_annotation_entry)],
meta_data=self.create_metadata(hpoa_version),
Expand Down

0 comments on commit 4b6b1fa

Please sign in to comment.