Overview

oGraph is a package for ontology representation and visualization.

Quick start guide

This section describes a simple working session using oGraph.

A typical session can be divided into two steps:

  1. Data preparation build the oGraph object which has the ontology store in an underlying igraph object.

  2. Running analysis treeview, subtree, find parent/child terms...

Here are example vignettes:

Load the package and see what ontology packages are available in you current .libPaths()

library('ograph')
ograph::initWHAT()

init the ontGraph object.

ontGraph<-new("ontGraph",ontology='HDO')
print(ontGraph)

The ontGraph object contains the 'DAG', 'level' and 'termid2def' mapping. You can access these properties by using '@'.

levels<-ontGraph@levels
head(levels$nodes2level)

The most important object is the 'DAG' object.

g=ontGraph@graph
g

A complete list of functions can be found by running:

ls('package:ograph')

A set of functions are designed to manipulate this igrph object reporesenting the ontology 'DAG': First let's plot the graph

treeplot(g,label = F)

This graph is too big, we will use a subgraph that seeded from c('DOID:10652','DOID:14330')

g<-subGraphByNodes(g,c('DOID:10652','DOID:14330'))
##plot again
treeplot(g,label = T)
nomalplot(g,label = T)
plot.graphNEL(g,term2def = ontGraph@term2def)

We can change the node attributes

list.vertex.attributes(g)
g<-set.node.attribute(graph = g,attr_name = 'color',attr_value = 'red',nodes = c('DOID:10652'))
get.node.attribute(g,'color')
##replot
treeplot(g,T)

We want to know the path between two node:

##to root
nodes2root<-shortest_path_to_root(graph=g,node='DOID:10652')
g<-set.node.attribute(graph = g,attr_name = 'color',attr_value = 'red',nodes = nodes2root)
treeplot(g,T)
##to another node
node2node<-shortest_path(g,'DOID:10652','DOID:14330',levels = ontGraph@levels,self.includ = T)
##node2node contains two object, up and down. This is two route going from node A to node B. In this case, there is only a route 
##connecting these two node by going up the tree
node2node
g<-set.node.attribute(graph = g,attr_name = 'color',attr_value = 'green',nodes = node2node$up)
treeplot(g,T)

We are interested in getting all the children/parents nodes:

##direct parents/children
findChildrenNodes(g,'DOID:1289')
findParentNodes(g,'DOID:1289')
##all parents/children
findAllChildrenNodes(g,'DOID:1289')
findAllParentNodes(g,'DOID:1289')

We want to create a sub 'DAG' with a set of interesting nodes. We are using a seed node c('DOID:150') and we need to work first on the full graph.

g<-ontGraph@graph
nodes<-c('DOID:150')
cs<-findAllChildrenNodes(g,nodes)
cs
sub<-subGraphByNodes(g,cs)
sub
treeplot(sub,F)

We want to take all the node in this sub 'DAG' for clipping?

get.node.attribute(sub,attr = 'name')

Other functions:

findRoot(graph=g)
leaves<-findLeafNode(graph=g)
subg<-subGraphByLevel(graph=g,l=3)
subg
sub=mapGene2Graph(graph=sub,file=system.file("extdata","human_gene2HDO_o", package ="ograph"),rollup = T)
treeplot(subGraphByLevel(sub,3),label=1,show.genes=TRUE)
term='DOID:150'
get.node.attribute(sub,attr='def',nodes=term)
peekNode(sub,node=term)

We can search keyword in ontology terms.

clip_neuro<-unique(c(searchDescription4Keyword(graph=g,keys=c('neuro')),searchName4Keyword(g,keys=c('neuro'))))
head(get.node.attribute(g,attr='def',clip_neuro))
clip_brain=unique(c(searchDescription4Keyword(graph=g,keys=c('brain')),searchName4Keyword(g,keys=c('brain'))))
head(get.node.attribute(g,attr='def',clip_neuro))

g.clip=subGraphByNodes(g,nodes=unique(c(clip_brain,clip_neuro)))
g.clip=set.node.attribute(graph=g.clip,attr_name='color',attr_value='green',nodes=clip_neuro)
g.clip=set.node.attribute(graph=g.clip,attr_name='color',attr_value='blue',nodes=clip_brain)
g.clip=set.node.attribute(graph=g.clip,attr_name='color',attr_value='red',nodes=intersect(clip_brain,clip_neuro))
treeplot(g.clip,label=0)


hxin/ograph documentation built on May 17, 2019, 9:15 p.m.