Given a file of genes:
$ head data/rp-genes.tsv
NCBIGene:6295 SAG
NCBIGene:1258 CNGB1
NCBIGene:3614 IMPDH1
NCBIGene:26121 PRPF31
The example file here is derived from a Monarch query for all retinitis pigmentosa genes.
We want to test each class in HPO to see if it is enriched for genes in this set.
First we need to parse the gene Ids in the file
In [18]:
## Parse ids from file
file = open("data/rp-genes.tsv", "r")
gene_ids = [row.split("\t")[0] for row in file]
## show first 10 IDs:
gene_ids[:10]
Out[18]:
['NCBIGene:6295',
'NCBIGene:1258',
'NCBIGene:3614',
'NCBIGene:26121',
'NCBIGene:7275',
'NCBIGene:55857',
'NCBIGene:79797',
'NCBIGene:10594',
'NCBIGene:64218',
'NCBIGene:7401']
In [8]:
## Create an ontology factory in order to fetch HPO
from ontobio.ontol_factory import OntologyFactory
ofactory = OntologyFactory()
ont = ofactory.create("hp") ## Load HP. Note the first time this runs Jupyter will show '*' - be patient
In [9]:
## Create an association factory to get gene-phenotype associations
from ontobio.assoc_factory import AssociationSetFactory
afactory = AssociationSetFactory()
## Load Associations from Monarch. Note the first time this runs Jupyter will show '*' - be patient
aset = afactory.create(ontology=ont, subject_category='gene', object_category='phenotype', taxon='NCBITaxon:9606')
In [12]:
## Run enrichment tests using all classes in ontology
enr = aset.enrichment_test(subjects=gene_ids, threshold=0.00005, labels=True)
In [19]:
## Show first 20 results
for r in enr[:20]:
print("{:8.3g} {} {:40s}".format(r['p'],r['c'],str(r['n'])))
1.24e-123 HP:0030466 Abnormal full-field electroretinogram
4.25e-111 HP:0000512 Abnormal electroretinogram
6.94e-104 HP:0000546 Retinal degeneration
1.28e-103 HP:0030453 Abnormal visual electrophysiology
3.03e-102 HP:0008323 Abnormal light- and dark-adapted electroretinogram
7.84e-97 HP:0000608 Macular degeneration
1.08e-95 HP:0001103 Abnormality of the macula
1.66e-93 HP:0000556 Retinal dystrophy
3.85e-90 HP:0001147 Retinal exudate
5.53e-90 HP:0000662 Nyctalopia
4.51e-89 HP:0007675 Progressive night blindness
1.37e-88 HP:0008020 Progressive cone degeneration
1.55e-85 HP:0007703 Abnormality of retinal pigmentation
2.43e-84 HP:0030506 Yellow/white lesions of the retina
9.5e-84 HP:0200065 Chorioretinal degeneration
4.22e-83 HP:0001730 Progressive hearing impairment
2.91e-81 HP:0030469 Abnormal dark-adapted electroretinogram
2.91e-81 HP:0030470 Abnormal dark-adapted bright flash electroretinogram
2.91e-81 HP:0030478 Abnormal amplitude of dark-adapted bright flash electroretinogram
2.91e-81 HP:0007984 Electronegative electroretinogram
Given that the initial gene set is for retinitis pigmentosa genes, it's not surprising that enriched phenotype terms are related to retinal degeneration
In [14]:
## Get all enriched class Ids
terms = [r['c'] for r in enr]
In [15]:
## Create a minimal slim of HPO consisting of enriched terms,
## with non-informative intermediate nodes removed
from ontobio.slimmer import get_minimal_subgraph
g = get_minimal_subgraph(ont.get_graph(), terms)
In [17]:
## Render as ascii-tree
from ontobio.graph_io import GraphRenderer
w = GraphRenderer.create('tree')
w.write(g, query_ids=terms)
. HP:0000118 ! Phenotypic abnormality
% HP:0000478 ! Abnormality of the eye *
% HP:0012372 ! Abnormal eye morphology *
% HP:0012374 ! Abnormality of the globe *
% HP:0100887 ! Abnormality of globe size *
% HP:0000568 ! Microphthalmia *
% HP:0008056 ! Aplasia/Hypoplasia affecting the eye *
% HP:0000568 ! Microphthalmia *
% HP:0008057 ! Aplasia/Hypoplasia affecting the fundus *
% HP:0008061 ! Aplasia/Hypoplasia of the retina *
% HP:0007770 ! Hypoplasia of the retina *
% HP:0008047 ! Abnormality of the vasculature of the eye *
% HP:0008046 ! Abnormality of the retinal vasculature *
% HP:0007843 ! Attenuation of retinal blood vessels *
% HP:0004329 ! Abnormality of the posterior segment of the globe *
% HP:0001098 ! Abnormality of the fundus *
% HP:0000479 ! Abnormality of the retina *
% HP:0000532 ! Chorioretinal abnormality *
% HP:0200065 ! Chorioretinal degeneration *
% HP:0000533 ! Chorioretinal atrophy *
% HP:0011958 ! Retinal perforation *
% HP:0011530 ! Retinal hole *
% HP:0000546 ! Retinal degeneration *
% HP:0000547 ! Tapetoretinal degeneration *
% HP:0007893 ! Progressive retinal degeneration *
% HP:0007769 ! Peripheral retinal degeneration *
% HP:0000655 ! Vitreoretinal degeneration *
% HP:0001105 ! Retinal atrophy *
% HP:0008020 ! Progressive cone degeneration *
% HP:0008061 ! Aplasia/Hypoplasia of the retina *
% HP:0007770 ! Hypoplasia of the retina *
% HP:0007703 ! Abnormality of retinal pigmentation *
% HP:0007894 ! Hypopigmentation of the fundus *
% HP:0000580 ! Pigmentary retinopathy *
% HP:0000510 ! Rod-cone dystrophy *
% HP:0001146 ! Pigmentary retinal degeneration *
% HP:0007737 ! Bone spicule pigmentation of the retina *
% HP:0000488 ! Retinopathy *
% HP:0001103 ! Abnormality of the macula *
% HP:0007754 ! Macular dystrophy *
% HP:0000608 ! Macular degeneration *
% HP:0007868 ! Age-related macular degeneration *
% HP:0030498 ! Macular thickening *
% HP:0040049 ! Macular edema *
% HP:0011505 ! Cystoid macular edema *
% HP:0030506 ! Yellow/white lesions of the retina *
% HP:0001147 ! Retinal exudate *
% HP:0007898 ! Exudative retinopathy *
% HP:0011532 ! Subretinal exudate *
% HP:0012777 ! Retinal neoplasm *
% HP:0009919 ! Retinoblastoma *
% HP:0000556 ! Retinal dystrophy *
% HP:0000548 ! Cone/cone-rod dystrophy *
% HP:0000510 ! Rod-cone dystrophy *
% HP:0007754 ! Macular dystrophy *
% HP:0008046 ! Abnormality of the retinal vasculature *
% HP:0007843 ! Attenuation of retinal blood vessels *
% HP:0000587 ! Abnormality of the optic nerve *
% HP:0012795 ! Abnormality of the optic disc *
% HP:0000648 ! Optic atrophy *
% HP:0000543 ! Optic disc pallor *
% HP:0008057 ! Aplasia/Hypoplasia affecting the fundus *
% HP:0008061 ! Aplasia/Hypoplasia of the retina *
% HP:0007770 ! Hypoplasia of the retina *
% HP:0000610 ! Abnormality of the choroid *
% HP:0000532 ! Chorioretinal abnormality *
% HP:0200065 ! Chorioretinal degeneration *
% HP:0000533 ! Chorioretinal atrophy *
% HP:0000553 ! Abnormality of the uvea *
% HP:0000610 ! Abnormality of the choroid *
% HP:0000532 ! Chorioretinal abnormality *
% HP:0200065 ! Chorioretinal degeneration *
% HP:0000533 ! Chorioretinal atrophy *
% HP:0004328 ! Abnormality of the anterior segment of the globe *
% HP:0000517 ! Abnormality of the lens *
% HP:0000518 ! Cataract *
% HP:0000481 ! Abnormality of the cornea *
% HP:0011486 ! Abnormality of corneal thickness *
% HP:0100689 ! Decreased corneal thickness *
% HP:0000563 ! Keratoconus *
% HP:0100691 ! Abnormality of the curvature of the cornea *
% HP:0100692 ! Increased corneal curvature *
% HP:0000563 ! Keratoconus *
% HP:0100012 ! Neoplasm of the eye *
% HP:0012777 ! Retinal neoplasm *
% HP:0009919 ! Retinoblastoma *
% HP:0012373 ! Abnormal eye physiology *
% HP:0030637 ! Cone dysfunction syndrome *
% HP:0000551 ! Abnormality of color vision *
% HP:0000496 ! Abnormality of eye movement *
% HP:0012547 ! Abnormal involuntary eye movements *
% HP:0000639 ! Nystagmus *
% HP:0000597 ! Ophthalmoparesis *
% HP:0000602 ! Ophthalmoplegia *
% HP:0000504 ! Abnormality of vision *
% HP:0000505 ! Visual impairment *
% HP:0000618 ! Blindness *
% HP:0007875 ! Congenital blindness *
% HP:0000662 ! Nyctalopia *
% HP:0007675 ! Progressive night blindness *
% HP:0000613 ! Photophobia *
% HP:0001123 ! Visual field defect *
% HP:0001133 ! Constriction of peripheral visual field *
% HP:0000551 ! Abnormality of color vision *
% HP:0007663 ! Reduced visual acuity *
% HP:0000572 ! Visual loss *
% HP:0000529 ! Progressive visual loss *
% HP:0000501 ! Glaucoma *
% HP:0030453 ! Abnormal visual electrophysiology *
% HP:0000512 ! Abnormal electroretinogram *
% HP:0030466 ! Abnormal full-field electroretinogram *
% HP:0008323 ! Abnormal light- and dark-adapted electroretinogram *
% HP:0000654 ! Decreased light- and dark-adapted electroretinogram amplitude *
% HP:0030469 ! Abnormal dark-adapted electroretinogram *
% HP:0030470 ! Abnormal dark-adapted bright flash electroretinogram *
% HP:0030478 ! Abnormal amplitude of dark-adapted bright flash electroretinogram *
% HP:0007984 ! Electronegative electroretinogram *
% HP:0000550 ! Undetectable electroretinogram *
% HP:0040064 ! Abnormality of limbs *
% HP:0040068 ! Abnormality of limb bone *
% HP:0002813 ! Abnormality of limb bone morphology *
% HP:0045060 ! Aplasia/hypoplasia involving bones of the extremities *
% HP:0006496 ! Aplasia/hypoplasia involving bones of the upper limbs *
% HP:0009824 ! Upper limb undergrowth *
% HP:0011297 ! Abnormality of digit *
% HP:0010442 ! Polydactyly *
% HP:0009815 ! Aplasia/hypoplasia of the extremities *
% HP:0009826 ! Limb undergrowth *
% HP:0009824 ! Upper limb undergrowth *
% HP:0045060 ! Aplasia/hypoplasia involving bones of the extremities *
% HP:0006496 ! Aplasia/hypoplasia involving bones of the upper limbs *
% HP:0009824 ! Upper limb undergrowth *
% HP:0002817 ! Abnormality of the upper limb *
% HP:0006496 ! Aplasia/hypoplasia involving bones of the upper limbs *
% HP:0009824 ! Upper limb undergrowth *
% HP:0000598 ! Abnormality of the ear *
% HP:0000370 ! Abnormality of the middle ear *
% HP:0011452 ! Functional abnormality of the middle ear *
% HP:0000405 ! Conductive hearing impairment *
% HP:0000364 ! Hearing abnormality *
% HP:0000365 ! Hearing impairment *
% HP:0012714 ! Severe hearing impairment *
% HP:0008625 ! Severe sensorineural hearing impairment *
% HP:0000405 ! Conductive hearing impairment *
% HP:0000407 ! Sensorineural hearing impairment *
% HP:0008625 ! Severe sensorineural hearing impairment *
% HP:0000408 ! Progressive sensorineural hearing impairment *
% HP:0008527 ! Congenital sensorineural hearing impairment *
% HP:0001730 ! Progressive hearing impairment *
% HP:0000408 ! Progressive sensorineural hearing impairment *
% HP:0000359 ! Abnormality of the inner ear *
% HP:0011389 ! Functional abnormality of the inner ear *
% HP:0000407 ! Sensorineural hearing impairment *
% HP:0008625 ! Severe sensorineural hearing impairment *
% HP:0000408 ! Progressive sensorineural hearing impairment *
% HP:0008527 ! Congenital sensorineural hearing impairment *
% HP:0002664 ! Neoplasm *
% HP:0011793 ! Neoplasm by anatomical site *
% HP:0100012 ! Neoplasm of the eye *
% HP:0012777 ! Retinal neoplasm *
% HP:0009919 ! Retinoblastoma *
% HP:0011792 ! Neoplasm by histology *
% HP:0030060 ! Nervous tissue neoplasm *
% HP:0030061 ! Neuroectodermal neoplasm *
% HP:0030063 ! Neuroepithelial neoplasm *
% HP:0009919 ! Retinoblastoma *
% HP:0002898 ! Embryonal neoplasm *
% HP:0009919 ! Retinoblastoma *
% HP:0000119 ! Abnormality of the genitourinary system *
% HP:0010935 ! Abnormality of the upper urinary tract *
% HP:0000077 ! Abnormality of the kidney *
% HP:0012210 ! Abnormal renal morphology *
% HP:0100957 ! Abnormality of the renal medulla *
% HP:0000090 ! Nephronophthisis *
% HP:0000078 ! Abnormality of the genital system *
% HP:0000080 ! Abnormality of reproductive system physiology *
% HP:0000135 ! Hypogonadism *
% HP:0012243 ! Abnormal genital system morphology *
% HP:0000812 ! Abnormal internal genitalia *
% HP:0000008 ! Abnormality of female internal genitalia *
% HP:0000140 ! Abnormality of the menstrual cycle *
% HP:0100608 ! Metrorrhagia *
% HP:0010461 ! Abnormality of the male genitalia *
% HP:0000032 ! Abnormality of male external genitalia *
% HP:0000036 ! Abnormality of the penis *
% HP:0008736 ! Hypoplasia of penis *
% HP:0000035 ! Abnormality of the testis *
% HP:0010460 ! Abnormality of the female genitalia *
% HP:0000008 ! Abnormality of female internal genitalia *
% HP:0000140 ! Abnormality of the menstrual cycle *
% HP:0100608 ! Metrorrhagia *
% HP:0000811 ! Abnormal external genitalia *
% HP:0000032 ! Abnormality of male external genitalia *
% HP:0000036 ! Abnormality of the penis *
% HP:0008736 ! Hypoplasia of penis *
% HP:0000035 ! Abnormality of the testis *
% HP:0003241 ! External genital hypoplasia *
% HP:0000050 ! Hypoplastic male external genitalia *
% HP:0008736 ! Hypoplasia of penis *
% HP:0001507 ! Growth abnormality *
% HP:0000002 ! Abnormality of body height *
% HP:0004322 ! Short stature *
% HP:0001510 ! Growth delay *
% HP:0004322 ! Short stature *
% HP:0004323 ! Abnormality of body weight *
% HP:0004324 ! Increased body weight *
% HP:0001513 ! Obesity *
% HP:0000818 ! Abnormality of the endocrine system *
% HP:0000819 ! Diabetes mellitus *
% HP:0005978 ! Type II diabetes mellitus *
% HP:0008373 ! Puberty and gonadal disorders *
% HP:0000135 ! Hypogonadism *
% HP:0000858 ! Menstrual irregularities *
% HP:0000140 ! Abnormality of the menstrual cycle *
% HP:0100608 ! Metrorrhagia *
% HP:0003117 ! Abnormality of circulating hormone level *
% HP:0040214 ! Abnormal insulin level *
% HP:0040215 ! Abnormal circulating insulin level *
% HP:0000842 ! Hyperinsulinemia *
% HP:0002597 ! Abnormality of the vasculature *
% HP:0008047 ! Abnormality of the vasculature of the eye *
% HP:0008046 ! Abnormality of the retinal vasculature *
% HP:0007843 ! Attenuation of retinal blood vessels *
% HP:0001574 ! Abnormality of the integument *
% HP:0000951 ! Abnormality of the skin *
% HP:0011121 ! Abnormality of skin morphology *
% HP:0001000 ! Abnormality of skin pigmentation *
% HP:0001070 ! Mottled pigmentation *
% HP:0011354 ! Generalized abnormality of skin *
% HP:0000987 ! Atypical scarring of skin *
% HP:0001939 ! Abnormality of metabolism/homeostasis *
% HP:0011032 ! Abnormality of fluid regulation *
% HP:0000969 ! Edema *
% HP:0040049 ! Macular edema *
% HP:0011505 ! Cystoid macular edema *
% HP:0003119 ! Abnormality of lipid metabolism *
% HP:0003107 ! Abnormality of cholesterol metabolism *
% HP:0010979 ! Abnormality of the level of lipoprotein cholesterol *
% HP:0010981 ! Hypolipoproteinemia *
% HP:0003563 ! Hypobetalipoproteinemia *
% HP:0008181 ! Abetalipoproteinemia *
% HP:0011013 ! Abnormality of carbohydrate metabolism/homeostasis *
% HP:0011014 ! Abnormal glucose homeostasis *
% HP:0000819 ! Diabetes mellitus *
% HP:0005978 ! Type II diabetes mellitus *
% HP:0000842 ! Hyperinsulinemia *
% HP:0000707 ! Abnormality of the nervous system *
% HP:0012639 ! Abnormality of nervous system morphology *
% HP:0000759 ! Abnormal peripheral nervous system morphology *
% HP:0009830 ! Peripheral neuropathy *
% HP:0012757 ! Abnormal neuron morphology *
% HP:0002450 ! Abnormal motor neuron morphology *
% HP:0007373 ! Motor neuron atrophy *
% HP:0007354 ! Amyotrophic lateral sclerosis *
% HP:0002011 ! Morphological abnormality of the central nervous system *
% HP:0011282 ! Abnormality of hindbrain morphology *
% HP:0011283 ! Abnormality of the metencephalon *
% HP:0001317 ! Abnormality of the cerebellum *
% HP:0001251 ! Ataxia *
% HP:0007367 ! Atrophy/Degeneration affecting the central nervous system *
% HP:0007373 ! Motor neuron atrophy *
% HP:0007354 ! Amyotrophic lateral sclerosis *
% HP:0002180 ! Neurodegeneration *
% HP:0100705 ! Abnormality of the glial cells *
% HP:0002171 ! Gliosis *
% HP:0012638 ! Abnormality of nervous system physiology *
% HP:0001250 ! Seizures *
% HP:0012759 ! Neurodevelopmental abnormality *
% HP:0001249 ! Intellectual disability *
% HP:0012758 ! Neurodevelopmental delay *
% HP:0001263 ! Global developmental delay *
% HP:0011442 ! Abnormality of central motor function *
% HP:0011443 ! Abnormality of coordination *
% HP:0001251 ! Ataxia *
% HP:0002493 ! Upper motor neuron dysfunction *
% HP:0001347 ! Hyperreflexia *
% HP:0000708 ! Behavioral abnormality *
% HP:0000613 ! Photophobia *
% HP:0000924 ! Abnormality of the skeletal system *
% HP:0011842 ! Abnormality of skeletal morphology *
% HP:0011844 ! Abnormal appendicular skeleton morphology *
% HP:0002813 ! Abnormality of limb bone morphology *
% HP:0045060 ! Aplasia/hypoplasia involving bones of the extremities *
% HP:0006496 ! Aplasia/hypoplasia involving bones of the upper limbs *
% HP:0009824 ! Upper limb undergrowth *
% HP:0011297 ! Abnormality of digit *
% HP:0010442 ! Polydactyly *
% HP:0009115 ! Aplasia/hypoplasia involving the skeleton *
% HP:0009815 ! Aplasia/hypoplasia of the extremities *
% HP:0009826 ! Limb undergrowth *
% HP:0009824 ! Upper limb undergrowth *
% HP:0045060 ! Aplasia/hypoplasia involving bones of the extremities *
% HP:0006496 ! Aplasia/hypoplasia involving bones of the upper limbs *
% HP:0009824 ! Upper limb undergrowth *
% HP:0040068 ! Abnormality of limb bone *
% HP:0002813 ! Abnormality of limb bone morphology *
% HP:0045060 ! Aplasia/hypoplasia involving bones of the extremities *
% HP:0006496 ! Aplasia/hypoplasia involving bones of the upper limbs *
% HP:0009824 ! Upper limb undergrowth *
% HP:0011297 ! Abnormality of digit *
% HP:0010442 ! Polydactyly *
% HP:0003549 ! Abnormality of connective tissue *
% HP:0100699 ! Scarring *
% HP:0000987 ! Atypical scarring of skin *
% HP:0001324 ! Muscle weakness *
% HP:0001871 ! Abnormality of blood and blood-forming tissues *
% HP:0005561 ! Abnormality of bone marrow cell morphology *
% HP:0012130 ! Abnormality of cells of the erythroid lineage *
% HP:0001877 ! Abnormality of erythrocytes *
% HP:0004447 ! Poikilocytosis *
% HP:0001927 ! Acanthocytosis *
% HP:0000152 ! Abnormality of head or neck *
% HP:0000234 ! Abnormality of the head *
% HP:0000271 ! Abnormality of the face *
% HP:0000366 ! Abnormality of the nose *
% HP:0000422 ! Abnormality of the nasal bridge *
% HP:0000431 ! Wide nasal bridge *
% HP:0005288 ! Abnormality of the nares *
% HP:0000463 ! Anteverted nares *
% HP:0010938 ! Abnormality of the external nose *
% HP:0000429 ! Abnormality of the nasal alae *
% HP:0000463 ! Anteverted nares *
% HP:0005105 ! Abnormal nasal morphology *
% HP:0000463 ! Anteverted nares *
% HP:0000315 ! Abnormality of the orbital region *
% HP:0100887 ! Abnormality of globe size *
% HP:0000568 ! Microphthalmia *
In [22]:
terms = [r['c'] for r in enr[:30]]
g = get_minimal_subgraph(ont.get_graph(), terms)
w = GraphRenderer.create('png')
w.outfile = "output/enr.png"
w.write(g, query_ids=terms)
In [ ]:
Content source: biolink/ontobio
Similar notebooks: