Skip to content

Instantly share code, notes, and snippets.

@oganm
Created February 14, 2018 01:31
Show Gist options
  • Save oganm/61b19eed384f9ad488b7710545a6e016 to your computer and use it in GitHub Desktop.
Save oganm/61b19eed384f9ad488b7710545a6e016 to your computer and use it in GitHub Desktop.
playing with ontologies
# ontologyPlot package requires bioconductor package Rgraphvis
# source("https://bioconductor.org/biocLite.R")
# biocLite("Rgraphvis")
# install.packages('ontologyIndex')
# install.packages('ontologyPlot')
library(ontologyIndex)
library(ontologyPlot)
download.file(url = 'http://purl.obolibrary.org/obo/uberon.obo',destfile = 'uberon.obo')
# get is_a connections. I'm doing this to understand which relationships to take
forRelationships = get_ontology('uberon.obo',propagate_relationships = c('is_a'))
# here I am taking all relationships that "is_a" "part_of" relationship
relationships = get_descendants(forRelationships,'part_of')
# Now I re-read the ontology to get all connections I am interested in
uberon = ontologyIndex::get_ontology('uberon.obo',propagate_relationships = c(relationships,'contributes_to_morphology_of','is_a'),
extract_tags = 'everything')
# here I get all children of the term "brain"
uberonBrain = get_descendants(uberon,'UBERON:0000955') %>% unique
relatedTerms = uberon$xref[uberonBrain] %>% unlist %>% unique
uberonOrgans = get_descendants(uberon,'UBERON:0000062') %>% unique # organ
uberonOrgans = uberonOrgans[!uberonOrgans %in% uberonBrain] # remove all brain regions from organs
# this is a list of brain regions
baseRegionTerms =
list(All = 'UBERON:0000955',
Cerebrum = c('UBERON:0001869', # cerebral hemisphere
'UBERON:0005401', # cerebral hemisphere gray matter
'UBERON:0016526', # lobe of cerebral hemisphere
'UBERON:0001890', # forebrain
'birnlex_1042', # cerebrum
'birnlex_1173'), # regional part of cerebrum,
Cortex = c('UBERON:0001870', # frontal cortex
'UBERON:0000956'), # cerebral cortex
BasalForebrain = 'UBERON:0002743', # basal forebrain
Striatum = 'UBERON:0002435',
Amygdala = 'UBERON:0001876',
Hippocampus = 'UBERON:0002421',
Subependymal = c('UBERON:0005357', # brain ependyma
'UBERON:0005380'), # olfactory bulb subependymal zone
Thalamus = c('UBERON:0010225', # thalamic complex, kinda contraversial used to be UBERON:0001903 "thalamic reticular nucleus"
'birnlex_954', # thalamus
'birnlex_1517'), # regional part of thalamus
Brainstem = 'UBERON:0002298',
Midbrain = 'UBERON:0001891',
# SubstantiaNigra = 'UBERON:0002038',
LocusCoeruleus = 'UBERON:0002148',
Cerebellum = 'UBERON:0002037',
SpinalCord = 'UBERON:0002240')
# see how they stand in the ontology
onto_plot(uberon,baseRegionTerms %>% unlist)
# look at all descendants of cortex. sometimes plots additonal terms to connect things to each other. not sure why
onto_plot(uberon,get_descendants(uberon,'UBERON:0001870'),fontsize = 70)
# look at all ancestors of brain
onto_plot(uberon,get_ancestors(uberon,'UBERON:0000955'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment