Calculating Wang’s Semantic Similarity between two GO Terms¶
Setup
Calculate Wang’s semantic similarity using optional part_of relationship
Calculate Wang’s semantic similarity using researcher-set edge weights.
Calculate Wang’s semantic similarity usint is_of relationship only
1) Setup¶
Create a list of all GO IDs that will be compared¶
# Researcher-provided GO terms related to smell
go_a = 'GO:0007608'
go_b = 'GO:0050911'
go_c = 'GO:0042221'
# Optional relationships. (Relationship, is_a, is required and always used)
relationships = {'part_of'}
goids = {go_a, go_b, go_c}
# Annotations for plotting
go2txt = {
go_a:'GO TERM A',
go_b:'GO TERM B',
go_c:'GO TERM C'}
Read the GO DAG¶
from goatools.base import get_godag
godag = get_godag("go-basic.obo", optional_attrs={'relationship'})
EXISTS: go-basic.obo
go-basic.obo: fmt(1.2) rel(2020-11-18) 47,326 GO Terms; optional_attrs(relationship)
Create a printing function for this notebook¶
def print_details(go_a, go_b, val):
"""Print concise and informative report: GO terms and their semantic similarity"""
pattern = ('go_a: {GOa} {GOa_name}\n'
'go_b: {GOb} {GOb_name}\n'
'wang: {VAL:.8f}\n')
print(pattern.format(
GOa=go_a, GOa_name=godag[go_a].name,
GOb=go_b, GOb_name=godag[go_b].name,
VAL=val))
2) Calculate Wang’s semantic similarity using part_of relationship¶
Instantiate a Wang’s Semantic Similarity object¶
We choose to use the optional relationship, part_of, in addition the required is_a relationships for this example.
Load all GO IDs that you will be comparing.
from goatools.semsim.termwise.wang import SsWang
# goids: researcher-provided GO terms
wang_r1 = SsWang(goids, godag, relationships)
Visualize researcher GO terms¶
from goatools.gosubdag.gosubdag import GoSubDag
from goatools.gosubdag.plot.gosubdag_plot import GoSubDagPlot
r1_png = 'smell_r1.png'
r1_gosubdag = GoSubDag(goids, godag, relationships)
GoSubDagPlot(r1_gosubdag, go2txt=go2txt).plt_dag(r1_png)
GoSubDag: 3 sources in 14 GOs rcnt(True). 0 alt GO IDs
GoSubDag: namedtuple fields: NS level depth reldepth GO alt GO_name dcnt D1 childcnt REL REL_short rel id
GoSubDag: relationships: {'part_of'}
3 usr 14 GOs WROTE: smell_r1.png

val = wang_r1.get_sim(go_a, go_b)
print_details(go_a, go_b, val)
go_a: GO:0007608 sensory perception of smell
go_b: GO:0050911 detection of chemical stimulus involved in sensory perception of smell
wang: 0.59684773
val = wang_r1.get_sim(go_a, go_c)
print_details(go_a, go_c, val)
go_a: GO:0007608 sensory perception of smell
go_b: GO:0042221 response to chemical
wang: 0.14114914
val = wang_r1.get_sim(go_b, go_c)
print_details(go_b, go_c, val)
go_a: GO:0050911 detection of chemical stimulus involved in sensory perception of smell
go_b: GO:0042221 response to chemical
wang: 0.38020047
3) Calculate Wang’s semantic similarity using researcher-set edge weights¶
Print the default edge weights in the Wang configuration¶
wang_r1.prt_cfg()
Wang Semantic Similarity Configuration:
Optional relationships: part_of
Edge weights:
0.80000000 is_a
0.60000000 part_of
Use researcher-specified edge weights¶
relationship2weight = {
'is_a': 0.9,
'part_of': 0.9
}
wang_r1 = SsWang(goids, godag, relationships, relationship2weight)
val = wang_r1.get_sim(go_a, go_b)
print_details(go_a, go_b, val)
go_a: GO:0007608 sensory perception of smell
go_b: GO:0050911 detection of chemical stimulus involved in sensory perception of smell
wang: 0.64019253
val = wang_r1.get_sim(go_a, go_c)
print_details(go_a, go_c, val)
go_a: GO:0007608 sensory perception of smell
go_b: GO:0042221 response to chemical
wang: 0.16922363
val = wang_r1.get_sim(go_b, go_c)
print_details(go_b, go_c, val)
go_a: GO:0050911 detection of chemical stimulus involved in sensory perception of smell
go_b: GO:0042221 response to chemical
wang: 0.35627471
4) Calculate Wang’s semantic similarity with is_a relationships only¶
wang_r0 = SsWang(goids, godag)
Calculate Wang’s semantic similarity using is_a relationship only¶
r0_png = 'smell_r0.png'
r0_gosubdag = GoSubDag(goids, godag)
GoSubDagPlot(r0_gosubdag, go2txt=go2txt).plt_dag(r0_png)
GoSubDag: 3 sources in 14 GOs rcnt(True). 0 alt GO IDs
GoSubDag: namedtuple fields: NS level depth GO alt GO_name dcnt D1 id
GoSubDag: relationships: set()
3 usr 14 GOs WROTE: smell_r0.png

Instantiate a Wang’s Semantic Similarity object¶
We use the required is_a relationships only.
Load all GO IDs that you will be comparing.
val = wang_r0.get_sim(go_a, go_b)
print_details(go_a, go_b, val)
go_a: GO:0007608 sensory perception of smell
go_b: GO:0050911 detection of chemical stimulus involved in sensory perception of smell
wang: 0.07122873
val = wang_r0.get_sim(go_a, go_c)
print_details(go_a, go_c, val)
go_a: GO:0007608 sensory perception of smell
go_b: GO:0042221 response to chemical
wang: 0.14114914
val = wang_r0.get_sim(go_b, go_c)
print_details(go_b, go_c, val)
go_a: GO:0050911 detection of chemical stimulus involved in sensory perception of smell
go_b: GO:0042221 response to chemical
wang: 0.32164130
Copyright (C) DV Klopfenstein and Haibao Tang, All rights reserved.