Generating RDF from Phenopackets
One of the advantages of LinkML is automated conversion between different serialization forms of Phenopackets:
- YAML/JSON
- RDF
- SQL Databases
In this notebook we'll demonstrate conversion to RDF. We will use LinkML conversion libraries via Python, but all this can also be done via the command line.
Import libraries
We will use the (autogenerated) Phenopacket python classes, plus the LinkML loaders and dumpers.
See Data Conversion in the LinkML docs for more information.
from phenopackets.datamodel.phenopackets import Phenopacket
from linkml_runtime.loaders import json_loader
We'll use the generic LinkML json_loader:
pkt = json_loader.load("../../../examples/Phenopacket-retinoblastoma.json", Phenopacket)
Let's print out the features as a basic sanity check
for pf in pkt.phenotypicFeatures:
print(f" {pf.type.id} {pf.type.label}")
HP:0030084 Clinodactyly
HP:0000555 Leukocoria
HP:0000486 Strabismus
HP:0000541 Retinal detachment
Dumping to RDF
We will first import the RDF dumper. This is a generic dumper from LinkML - there is no phenopackets-specific dumper.
We will also need to use the SchemaView library to load the Phenopackets schema, as the RDF dumper nees this metadata.
from phenopackets.datamodel import MAIN_SCHEMA_PATH
from linkml_runtime import SchemaView
sv = SchemaView(str(MAIN_SCHEMA_PATH))
We will also provide a prefix map
prefix_map = {
"HP": "http://purl.obolibrary.org/obo/HP_",
"ex": "https://example.org/",
"MONDO": "http://purl.obolibrary.org/obo/MONDO_",
"NCBITaxon": "http://purl.obolibrary.org/obo/NCBITaxon_",
"NCIT": "http://purl.obolibrary.org/obo/NCIT_",
"EFO": "http://www.ebi.ac.uk/efo/EFO_",
"PMID": "https://www.ncbi.nlm.nih.gov/pubmed/",
"OMIM": "http://omim.org/entry/",
"GENO": "http://purl.obolibrary.org/obo/GENO_",
"ECO": "http://purl.obolibrary.org/obo/ECO_",
"DOI": "https://doi.org/",
"DrugCentral": "http://identifiers.org/drugcentral/",
"LOINC": "https://loinc.org/",
"UCUM": "http://unitsofmeasure.org/",
"PATO": "http://purl.obolibrary.org/obo/PATO_",
"CHEBI": "http://purl.obolibrary.org/obo/CHEBI_",
"SCTID": "http://snomed.info/id/",
"SNOMEDCT": "http://snomed.info/id/",
"UO": "http://purl.obolibrary.org/obo/UO_",
"__base": "https://example.org/base/",
}
from linkml_runtime.dumpers import rdflib_dumper
print(rdflib_dumper.dumps(pkt, schemaview=sv, prefix_map=prefix_map))
@prefix DrugCentral: <http://identifiers.org/drugcentral/> .
@prefix GENO: <http://purl.obolibrary.org/obo/GENO_> .
@prefix HP: <http://purl.obolibrary.org/obo/HP_> .
@prefix LOINC: <https://loinc.org/> .
@prefix NCIT: <http://purl.obolibrary.org/obo/NCIT_> .
@prefix UBERON: <http://purl.obolibrary.org/obo/UBERON_> .
@prefix UCUM: <http://unitsofmeasure.org/> .
@prefix base: <https://w3id.org/linkml/phenopackets/base/> .
@prefix biosample: <https://w3id.org/linkml/phenopackets/biosample/> .
@prefix disease: <https://w3id.org/linkml/phenopackets/disease/> .
@prefix individual: <https://w3id.org/linkml/phenopackets/individual/> .
@prefix interpretation: <https://w3id.org/linkml/phenopackets/interpretation/> .
@prefix measurement: <https://w3id.org/linkml/phenopackets/measurement/> .
@prefix medical_action: <https://w3id.org/linkml/phenopackets/medical_action/> .
@prefix meta_data: <https://w3id.org/linkml/phenopackets/meta_data/> .
@prefix phenopackets: <https://w3id.org/linkml/phenopackets/phenopackets/> .
@prefix phenotypic_feature: <https://w3id.org/linkml/phenopackets/phenotypic_feature/> .
@prefix vrs: <https://w3id.org/linkml/phenopackets/vrs/> .
@prefix vrsatile: <https://w3id.org/linkml/phenopackets/vrsatile/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
DrugCentral:1678 a base:OntologyClass ;
base:label "melphalan" .
GENO:0000135 a base:OntologyClass ;
base:label "heterozygous" .
HP:0000486 a base:OntologyClass ;
base:label "Strabismus" .
HP:0000541 a base:OntologyClass ;
base:label "Retinal detachment" .
HP:0000555 a base:OntologyClass ;
base:label "Leukocoria" .
HP:0012834 a base:OntologyClass ;
base:label "Right" .
HP:0025637 a base:OntologyClass ;
base:label "Vasospasm" .
HP:0030084 a base:OntologyClass ;
base:label "Clinodactyly" .
NCIT:C10894 a base:OntologyClass ;
base:label "Carboplatin/Etoposide/Vincristine" .
NCIT:C132485 a base:OntologyClass ;
base:label "Apoptosis and Necrosis" .
NCIT:C140678 a base:OntologyClass ;
base:label "Retinoblastoma cM0 TNM Finding v8" .
NCIT:C140711 a base:OntologyClass ;
base:label "Retinoblastoma pN0 TNM Finding v8" .
NCIT:C140720 a base:OntologyClass ;
base:label "Retinoblastoma pT3 TNM Finding v8" .
NCIT:C35941 a base:OntologyClass ;
base:label "Flexner-Wintersteiner Rosette Formation" .
NCIT:C38222 a base:OntologyClass ;
base:label "Intraarterial Route of Administration" .
NCIT:C41331 a base:OntologyClass ;
base:label "Adverse Event" .
NCIT:C64576 a base:OntologyClass ;
base:label "Once" .
NCIT:C8509 a base:OntologyClass ;
base:label "Primary Neoplasm" .
UBERON:0000970 a base:OntologyClass ;
base:label "eye" .
UCUM:mg.kg-1 a base:OntologyClass ;
base:label "milligram per kilogram" .
UCUM:mm a base:OntologyClass ;
base:label "millimeter" .
LOINC:33728-7 a base:OntologyClass ;
base:label "Size.maximum dimension in Tumor" .
LOINC:79892-6 a base:OntologyClass ;
base:label "Right eye Intraocular pressure" .
LOINC:79893-4 a base:OntologyClass ;
base:label "Left eye Intraocular pressure" .
LOINC:LA24739-7 a base:OntologyClass ;
base:label "Group E" .
NCIT:C48601 a base:OntologyClass ;
base:label "Enucleation" .
<http://unitsofmeasure.org/mm[Hg]> a base:OntologyClass ;
base:label "millimetres of mercury" .
LOINC:56844-4 a base:OntologyClass ;
base:label "Intraocular pressure of Eye" .
HP:0012835 a base:OntologyClass ;
base:label "Left" .
NCIT:C62220 a base:OntologyClass ;
base:label "Cure" .
UBERON:0004548 a base:OntologyClass ;
base:label "left eye" .
NCIT:C7541 a base:OntologyClass ;
base:label "Retinoblastoma" .
[] a phenopackets:Phenopacket ;
phenopackets:biosamples [ a biosample:Biosample ;
biosample:files [ a base:File ;
base:fileAttributes [ a base:DictionaryEntry ;
base:key "fileFormat" ;
base:value "VCF" ],
[ a base:DictionaryEntry ;
base:key "genomeAssembly" ;
base:value "GRCh38" ] ;
base:individualToFileIdentifiers [ a base:DictionaryEntry ;
base:key "biosample.1" ;
base:value "specimen.1" ] ;
base:uri "file://data/fileSomaticWgs.vcf.gz" ] ;
biosample:id "biosample.1" ;
biosample:measurements [ a measurement:Measurement ;
measurement:assay LOINC:33728-7 ;
measurement:timeObserved [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P8M2W" ] ] ;
measurement:value [ a measurement:Value ;
measurement:quantity [ a measurement:Quantity ;
measurement:unit UCUM:mm ;
measurement:value 1.5e+01 ] ] ] ;
biosample:pathologicalTnmFinding NCIT:C140711,
NCIT:C140720 ;
biosample:phenotypicFeatures [ a phenotypic_feature:PhenotypicFeature ;
phenotypic_feature:excluded false ;
phenotypic_feature:type NCIT:C132485 ],
[ a phenotypic_feature:PhenotypicFeature ;
phenotypic_feature:excluded false ;
phenotypic_feature:type NCIT:C35941 ] ;
biosample:procedure [ a base:Procedure ;
base:bodySite UBERON:0004548 ;
base:code NCIT:C48601 ;
base:performed [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P8M2W" ] ] ] ;
biosample:sampledTissue UBERON:0000970 ;
biosample:tumorProgression NCIT:C8509 ] ;
phenopackets:diseases [ a disease:Disease ;
disease:clinicalTnmFinding NCIT:C140678 ;
disease:diseaseStage LOINC:LA24739-7 ;
disease:excluded false ;
disease:onset [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P4M" ] ] ;
disease:primarySite UBERON:0004548 ;
disease:term NCIT:C7541 ] ;
phenopackets:files [ a base:File ;
base:fileAttributes [ a base:DictionaryEntry ;
base:key "fileFormat" ;
base:value "VCF" ],
[ a base:DictionaryEntry ;
base:key "genomeAssembly" ;
base:value "GRCh38" ] ;
base:individualToFileIdentifiers [ a base:DictionaryEntry ;
base:key "proband A" ;
base:value "sample1" ] ;
base:uri "file://data/germlineWgs.vcf.gz" ] ;
phenopackets:id "arbitrary.id" ;
phenopackets:interpretations [ a interpretation:Interpretation ;
interpretation:diagnosis [ a interpretation:Diagnosis ;
interpretation:disease NCIT:C7541 ;
interpretation:genomicInterpretations [ a interpretation:GenomicInterpretation ;
interpretation:interpretationStatus "CAUSATIVE" ;
interpretation:subjectOrBiosampleId "biosample.1" ;
interpretation:variantInterpretation [ a interpretation:VariantInterpretation ;
interpretation:acmgPathogenicityClassification "PATHOGENIC" ;
interpretation:therapeuticActionability "ACTIONABLE" ;
interpretation:variationDescriptor [ a vrsatile:VariationDescriptor ;
vrsatile:allelicState GENO:0000135 ;
vrsatile:expressions [ a vrsatile:Expression ;
vrsatile:syntax "transcript_reference" ;
vrsatile:value "NM_000321.2" ],
[ a vrsatile:Expression ;
vrsatile:syntax "hgvs.c" ;
vrsatile:value "NM_000321.2:c.958C>T" ] ;
vrsatile:extensions [ a vrsatile:Extension ;
vrsatile:name "allele-frequency" ;
vrsatile:value "25.0%" ] ;
vrsatile:geneContext [ a vrsatile:GeneDescriptor ;
vrsatile:symbol "RB1" ;
vrsatile:valueId "HGNC:9884" ] ;
vrsatile:id "rs121913300" ;
vrsatile:label "RB1 c.958C>T (p.Arg320Ter)" ;
vrsatile:moleculeContext "genomic" ;
vrsatile:variation [ a vrs:Variation ;
vrs:allele [ a vrs:Allele ;
vrs:literalSequenceExpression [ a vrs:LiteralSequenceExpression ;
vrs:sequence "T" ] ;
vrs:sequenceLocation [ a vrs:SequenceLocation ;
vrs:sequenceId "refseq:NC_000013.11" ;
vrs:sequenceInterval [ a vrs:SequenceInterval ;
vrs:endNumber [ a vrs:Number ;
vrs:value 48367512 ] ;
vrs:startNumber [ a vrs:Number ;
vrs:value 48367511 ] ] ] ] ] ;
vrsatile:vcfRecord [ a vrsatile:VcfRecord ;
vrsatile:alt "T" ;
vrsatile:chrom "NC_000013.11" ;
vrsatile:genomeAssembly "GRCh38" ;
vrsatile:pos 48367512 ;
vrsatile:ref "C" ] ] ] ],
[ a interpretation:GenomicInterpretation ;
interpretation:interpretationStatus "CAUSATIVE" ;
interpretation:subjectOrBiosampleId "proband A" ;
interpretation:variantInterpretation [ a interpretation:VariantInterpretation ;
interpretation:acmgPathogenicityClassification "PATHOGENIC" ;
interpretation:therapeuticActionability "ACTIONABLE" ;
interpretation:variationDescriptor [ a vrsatile:VariationDescriptor ;
vrsatile:extensions [ a vrsatile:Extension ;
vrsatile:name "mosaicism" ;
vrsatile:value "40.0%" ] ;
vrsatile:id "variant-id" ;
vrsatile:moleculeContext "unspecified_molecule_context" ;
vrsatile:variation [ a vrs:Variation ;
vrs:copyNumber [ a vrs:CopyNumber ;
vrs:derivedSequenceExpression [ a vrs:DerivedSequenceExpression ;
vrs:location [ a vrs:SequenceLocation ;
vrs:sequenceId "refseq:NC_000013.14" ;
vrs:sequenceInterval [ a vrs:SequenceInterval ;
vrs:endNumber [ a vrs:Number ;
vrs:value 61706822 ] ;
vrs:startNumber [ a vrs:Number ;
vrs:value 25981249 ] ] ] ;
vrs:reverseComplement false ] ;
vrs:number [ a vrs:Number ;
vrs:value 1 ] ] ] ] ] ] ] ;
interpretation:id "interpretation.id" ;
interpretation:progressStatus "SOLVED" ] ;
phenopackets:measurements [ a measurement:Measurement ;
measurement:assay LOINC:79892-6 ;
measurement:timeObserved [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P6M" ] ] ;
measurement:value [ a measurement:Value ;
measurement:quantity [ a measurement:Quantity ;
measurement:referenceRange [ a measurement:ReferenceRange ;
measurement:high 2.1e+01 ;
measurement:low 1e+01 ;
measurement:unit LOINC:56844-4 ] ;
measurement:unit <http://unitsofmeasure.org/mm[Hg]> ;
measurement:value 1.5e+01 ] ] ],
[ a measurement:Measurement ;
measurement:assay LOINC:79893-4 ;
measurement:timeObserved [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P6M" ] ] ;
measurement:value [ a measurement:Value ;
measurement:quantity [ a measurement:Quantity ;
measurement:referenceRange [ a measurement:ReferenceRange ;
measurement:high 2.1e+01 ;
measurement:low 1e+01 ;
measurement:unit LOINC:56844-4 ] ;
measurement:unit <http://unitsofmeasure.org/mm[Hg]> ;
measurement:value 2.5e+01 ] ] ] ;
phenopackets:medicalActions [ a medical_action:MedicalAction ;
medical_action:therapeuticRegimen [ a medical_action:TherapeuticRegimen ;
medical_action:endTime [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P8M" ] ] ;
medical_action:ontologyClass NCIT:C10894 ;
medical_action:regimenStatus "COMPLETED" ;
medical_action:startTime [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P7M" ] ] ] ;
medical_action:treatmentIntent NCIT:C62220 ;
medical_action:treatmentTarget NCIT:C7541 ],
[ a medical_action:MedicalAction ;
medical_action:adverseEvents HP:0025637 ;
medical_action:treatment [ a medical_action:Treatment ;
medical_action:agent DrugCentral:1678 ;
medical_action:doseIntervals [ a medical_action:DoseInterval ;
medical_action:interval [ a base:TimeInterval ;
base:end "2020-09-02T00:00:00Z" ;
base:start "2020-09-02T00:00:00Z" ] ;
medical_action:quantity [ a measurement:Quantity ;
measurement:unit UCUM:mg.kg-1 ;
measurement:value 4e-01 ] ;
medical_action:scheduleFrequency NCIT:C64576 ] ;
medical_action:drugType "UNKNOWN_DRUG_TYPE" ;
medical_action:routeOfAdministration NCIT:C38222 ] ;
medical_action:treatmentIntent NCIT:C62220 ;
medical_action:treatmentTarget NCIT:C7541 ;
medical_action:treatmentTerminationReason NCIT:C41331 ],
[ a medical_action:MedicalAction ;
medical_action:procedure [ a base:Procedure ;
base:bodySite UBERON:0004548 ;
base:code NCIT:C48601 ;
base:performed [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P8M2W" ] ] ] ;
medical_action:treatmentIntent NCIT:C62220 ;
medical_action:treatmentTarget NCIT:C7541 ] ;
phenopackets:metaData [ a meta_data:MetaData ;
meta_data:created "2021-05-14T10:35:00Z" ;
meta_data:createdBy "anonymous biocurator" ;
meta_data:phenopacketSchemaVersion "2.0.0" ;
meta_data:resources [ a meta_data:Resource ;
meta_data:id "uberon" ;
meta_data:iriPrefix "http://purl.obolibrary.org/obo/UBERON_" ;
meta_data:name "Uber-anatomy ontology" ;
meta_data:namespacePrefix "UBERON" ;
meta_data:url "http://purl.obolibrary.org/obo/uberon.owl" ;
meta_data:version "2021-07-27" ],
[ a meta_data:Resource ;
meta_data:id "ucum" ;
meta_data:iriPrefix "https://units-of-measurement.org/" ;
meta_data:name "Unified Code for Units of Measure" ;
meta_data:namespacePrefix "UCUM" ;
meta_data:url "https://ucum.org" ;
meta_data:version "2.1" ],
[ a meta_data:Resource ;
meta_data:id "efo" ;
meta_data:iriPrefix "http://purl.obolibrary.org/obo/EFO_" ;
meta_data:name "Experimental Factor Ontology" ;
meta_data:namespacePrefix "EFO" ;
meta_data:url "http://www.ebi.ac.uk/efo/efo.owl" ;
meta_data:version "3.34.0" ],
[ a meta_data:Resource ;
meta_data:id "ncit" ;
meta_data:iriPrefix "http://purl.obolibrary.org/obo/NCIT_" ;
meta_data:name "NCI Thesaurus" ;
meta_data:namespacePrefix "NCIT" ;
meta_data:url "http://purl.obolibrary.org/obo/ncit.owl" ;
meta_data:version "21.05d" ],
[ a meta_data:Resource ;
meta_data:id "drugcentral" ;
meta_data:iriPrefix "https://drugcentral.org/drugcard/" ;
meta_data:name "Drug Central" ;
meta_data:namespacePrefix "DrugCentral" ;
meta_data:url "https://drugcentral.org/" ;
meta_data:version "2022-08-22" ],
[ a meta_data:Resource ;
meta_data:id "hp" ;
meta_data:iriPrefix "http://purl.obolibrary.org/obo/HP_" ;
meta_data:name "human phenotype ontology" ;
meta_data:namespacePrefix "HP" ;
meta_data:url "http://purl.obolibrary.org/obo/hp.owl" ;
meta_data:version "2022-06-11" ],
[ a meta_data:Resource ;
meta_data:id "ncbitaxon" ;
meta_data:iriPrefix "http://purl.obolibrary.org/obo/NCBITaxon_" ;
meta_data:name "NCBI organismal classification" ;
meta_data:namespacePrefix "NCBITaxon" ;
meta_data:url "http://purl.obolibrary.org/obo/ncbitaxon.owl" ;
meta_data:version "2021-06-10" ],
[ a meta_data:Resource ;
meta_data:id "geno" ;
meta_data:iriPrefix "http://purl.obolibrary.org/obo/GENO_" ;
meta_data:name "Genotype Ontology" ;
meta_data:namespacePrefix "GENO" ;
meta_data:url "http://purl.obolibrary.org/obo/geno.owl" ;
meta_data:version "2022-03-05" ],
[ a meta_data:Resource ;
meta_data:id "loinc" ;
meta_data:iriPrefix "https://loinc.org/" ;
meta_data:name "Logical Observation Identifiers Names and Codes" ;
meta_data:namespacePrefix "LOINC" ;
meta_data:url "https://loinc.org" ;
meta_data:version "2.73" ] ] ;
phenopackets:phenotypicFeatures [ a phenotypic_feature:PhenotypicFeature ;
phenotypic_feature:excluded false ;
phenotypic_feature:modifiers HP:0012835 ;
phenotypic_feature:onset [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P4M" ] ] ;
phenotypic_feature:type HP:0000555 ],
[ a phenotypic_feature:PhenotypicFeature ;
phenotypic_feature:excluded false ;
phenotypic_feature:modifiers HP:0012834 ;
phenotypic_feature:onset [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P3M" ] ] ;
phenotypic_feature:type HP:0030084 ],
[ a phenotypic_feature:PhenotypicFeature ;
phenotypic_feature:excluded false ;
phenotypic_feature:modifiers HP:0012835 ;
phenotypic_feature:onset [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P6M" ] ] ;
phenotypic_feature:type HP:0000541 ],
[ a phenotypic_feature:PhenotypicFeature ;
phenotypic_feature:excluded false ;
phenotypic_feature:modifiers HP:0012835 ;
phenotypic_feature:onset [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P5M15D" ] ] ;
phenotypic_feature:type HP:0000486 ] ;
phenopackets:subject [ a individual:Individual ;
individual:id "proband A" ;
individual:karyotypicSex "XX" ;
individual:sex "FEMALE" ;
individual:timeAtLastEncounter [ a base:TimeElement ;
base:age [ a base:Age ;
base:iso8601duration "P6M" ] ] ] .