phenocor.core package
phenocor.core.dataset module
- class PhenotypeDataset(phenotype_matrix: DataFrame, hpo_labels: dict[str, str]=<factory>, relationship_mask: DataFrame | None = None, phenopackets: list[Phenopacket] = <factory>)
Bases:
objectStore an analysis-ready phenotype dataset.
The dataset contains a phenotype status matrix together with HPO term labels, a pairwise ontology relationship mask, and the source Phenopackets.
Phenotype matrix values follow the convention:
1 = observed 0 = excluded NaN = unknown
- phenotype_matrix
Phenotype status matrix with individuals as rows and canonical HPO term IDs as columns.
- Type:
pd.DataFrame
- hpo_labels
Mapping from canonical HPO term IDs to their labels.
- Type:
dict[str, str]
- relationship_mask
Pairwise HPO relationship mask aligned to
phenotype_matrix. Self-pairs and ancestor-descendant pairs are represented byNaN; unrelated pairs are represented by0.- Type:
pd.DataFrame | None
- phenopackets
Source Phenopackets corresponding to the individuals in the phenotype matrix.
- Type:
list[ppkt.Phenopacket]
- get_diseases() Series
Return observed disease IDs associated with each individual.
Diseases explicitly marked as excluded are ignored.
- Returns:
Series indexed by individual ID. Each value is a sorted list of unique disease IDs.
- Return type:
pd.Series
- get_pmids() Series
Return PubMed IDs associated with each individual.
PubMed IDs are extracted from Phenopacket metadata external references whose identifiers begin with
"PMID:".- Returns:
Series indexed by individual ID. Each value is a sorted list of unique PubMed IDs without the
"PMID:"prefix.- Return type:
pd.Series
- property hpo_ids: Index
Return HPO term IDs in the phenotype matrix.
- hpo_labels: dict[str, str]
- property individual_ids: Index
Return individual IDs in the phenotype matrix.
- phenopackets: list[Phenopacket]
- phenotype_matrix: DataFrame
- relationship_mask: DataFrame | None = None
phenocor.core.builder module
- class PhenotypeDatasetBuilder(phenopackets: list[Phenopacket], *, hpo_file: str | IO[Any] | None = None, hpo_release: str | None = None)
Bases:
objectBuild an analysis-ready
PhenotypeDatasetfrom Phenopackets.The builder extracts observed and excluded HPO annotations, constructs the phenotype status matrix, propagates annotations through the HPO hierarchy, and constructs the ontology relationship mask.
- build() PhenotypeDataset
Build an analysis-ready phenotype dataset.
- Returns:
Dataset containing the propagated phenotype status matrix, HPO term labels, ontology relationship mask, and source Phenopackets.
- Return type:
- Raises:
ValueError – If no HPO terms are found in the input Phenopackets or no valid HPO terms remain after ontology processing.