Skip to content

Instantly share code, notes, and snippets.

@dridk
Created January 11, 2022 22:54
Show Gist options
  • Save dridk/b20a09a67510377c5400cb35297adf30 to your computer and use it in GitHub Desktop.
Save dridk/b20a09a67510377c5400cb35297adf30 to your computer and use it in GitHub Desktop.
OWL to oracle thesaurus
from nxontology.imports import from_file
import networkx as nx
g = from_file("hp.owl")
space = 0
previous_first =""
previous_second =""
tab = " "
for i, node in enumerate(nx.dfs_labeled_edges(g.graph)):
first, second, sens = node
if "HP" in first:
if sens =="forward":
label = g.node_info(second).label
margin = ""
if space > 0:
margin = tab * space + " NT "
print(f"{margin}{label}")
if sens == "forward":
space +=1
if sens == "reverse":
space -= 1
@dridk
Copy link
Author

dridk commented Jan 11, 2022

This code convert an OWL ontology to a nested text suitable for ORACLE thesaurus .
Output examples :

All
    NT Mode of inheritance
       NT Autosomal dominant inheritance
          NT Autosomal dominant somatic cell mutation
          NT Autosomal dominant contiguous gene syndrome
          NT Sex-limited autosomal dominant
             NT Male-limited autosomal dominant
          NT Autosomal dominant inheritance with paternal imprinting
          NT Autosomal dominant inheritance with maternal imprinting
          NT Autosomal dominant germline de novo mutation
       NT Autosomal recessive inheritance
          NT Sex-limited autosomal recessive inheritance
       NT Heterogeneous
       NT Multifactorial inheritance
          NT Polygenic inheritance
          NT Oligogenic inheritance
          NT Digenic inheritance
       NT Mitochondrial inheritance
       NT Somatic mutation
          NT Somatic mosaicism
       NT Contiguous gene syndrome
       NT Genetic anticipation
          NT Genetic anticipation with paternal anticipation bias
       NT Sporadic
       NT Gonosomal inheritance
          NT X-linked inheritance
             NT X-linked recessive inheritance
             NT X-linked dominant inheritance
          NT Y-linked inheritance
       NT Semidominant mode of inheritance
       NT Uniparental disomy
          NT Uniparental heterodisomy
          NT Uniparental isodisomy
    NT Phenotypic abnormality
       NT Abnormality of the genitourinary system
          NT Abnormality of the genital system
             NT Abnormality of reproductive system physiology
                NT Hypogonadism
                   NT Male hypogonadism
                   NT Hypogonadotropic hypogon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment