a) The is_a relationships will always be traversed to find the children or parents of a GO term
In [1]:
from goatools.base import get_godag
godag = get_godag("go-basic.obo", optional_attrs={'relationship'})
# We are going to use a GO DAG subset for this example
godag = get_godag("../tests/data/i126/viral_gene_silence.obo", optional_attrs={'relationship'})
In [2]:
virus_trigger_silence = 'GO:0060150'
The GO DAG and go-color files for this example are located in: ./tests/data/i126
GO colors are stored in viral_gene_silence.txt as 6-digit hax numbers, like #ffe5b4.
The color file looks like this:
Relationship, part_of, shall be orange (#ffe5b4):
#ffe5b4 GO:0002376 immune system process
#ffe5b4 GO:0050896 response to stimulus
#ffe5b4 GO:0051704 multi-organism process
...
In [3]:
from goatools.cli.gos_get import get_go2color
go2hexcolor = get_go2color('../tests/data/i126/viral_gene_silence.txt')
# For printing GO terms and their color names to the print
hex2color = {
'#e6fad2': 'green',
'#ffe5b4': 'orange',
'#d2d2fa': 'purple',
'#d2fafa': 'cyan',
'#fad2fa': 'magenta',
'#d8dcd6': 'grey',
}
GREY = '#d8dcd6'
GO2COLORNAME = {go: hex2color[rgb] for go, rgb in go2hexcolor.items()}
In [4]:
from goatools.gosubdag.gosubdag import GoSubDag
gosubdag_r0 = GoSubDag({virus_trigger_silence}, godag)
In [5]:
# Decide which GO fields to print. Save in prtfmt
# Print one namedtuple
print(next(iter(gosubdag_r0.go2nt.values())))
# Use some namedtuple fields in print of GO terms
PRTFMT = '{NS} {GO} D-{depth:02} {color:7} {dcnt:2} {GO_name}'
In [6]:
# Report all ancesters of term, GO:001922 (colored grey)
grey_go = 'GO:0019222'
ancestors = gosubdag_r0.rcntobj.go2parents[grey_go]
def prt_goids(goids, gosubdag):
"""Print GO IDs"""
nts = [gosubdag.go2nt[go] for go in goids]
for nt_go in sorted(nts, key=lambda nt: [nt.depth, nt.dcnt]):
color = GO2COLORNAME[nt_go.GO]
print(PRTFMT.format(color=color, **nt_go._asdict()))
prt_goids(ancestors, gosubdag_r0)
In [7]:
from goatools.gosubdag.plot.gosubdag_plot import GoSubDagPlot
# Color the GO of interest in a copy of the color dictionary
go2col = dict(go2hexcolor)
go2col[grey_go] = GREY
pltobj = GoSubDagPlot(gosubdag_r0, go2color=go2col)
pltobj.plt_dag('viral_r0.png')
In [8]:
gosubdag_r1 = GoSubDag({virus_trigger_silence}, godag, relationships=True)
# Report all ancesters of grey term
grey_go = 'GO:0010468' # regulation of gene expression
ancestors = gosubdag_r1.rcntobj.go2parents[grey_go]
prt_goids(ancestors, gosubdag_r1)
In [9]:
# Color the GO of interest in a copy of the color dictionary
go2col = dict(go2hexcolor)
go2col[grey_go] = GREY
pltobj = GoSubDagPlot(gosubdag_r1, go2color=go2col)
pltobj.plt_dag('viral_r1.png')
In [10]:
gosubdag_partof = GoSubDag({virus_trigger_silence}, godag, relationships={'part_of',})
# Report all ancesters of grey term
grey_go = 'GO:0010468' # regulation of gene expression
ancestors = gosubdag_partof.rcntobj.go2parents[grey_go]
prt_goids(ancestors, gosubdag_partof)
In [11]:
# Color the GO of interest in a copy of the color dictionary
go2col = dict(go2hexcolor)
go2col[grey_go] = GREY
pltobj = GoSubDagPlot(gosubdag_partof, go2color=go2col)
pltobj.plt_dag('viral_r_partof.png')
In [12]:
gosubdag_reg = GoSubDag({virus_trigger_silence}, godag, relationships={'regulates',})
# Report all ancesters of grey term
grey_go = 'GO:0050794' # regulation of cellular process
ancestors = gosubdag_reg.rcntobj.go2parents[grey_go]
prt_goids(ancestors, gosubdag_reg)
In [13]:
# Color the GO of interest in a copy of the color dictionary
go2col = dict(go2hexcolor)
go2col[grey_go] = GREY
pltobj = GoSubDagPlot(gosubdag_reg, go2color=go2col)
pltobj.plt_dag('viral_reg.png')
In [14]:
gosubdag_regp = GoSubDag({virus_trigger_silence}, godag, relationships={'positively_regulates',})
In [15]:
# Report all ancesters of grey term
grey_go = 'GO:0048522' # positive regulation of cellular process
ancestors = gosubdag_regp.rcntobj.go2parents[grey_go]
prt_goids(ancestors, gosubdag_regp)
In [16]:
# Color the GO of interest in a copy of the color dictionary
go2col = dict(go2hexcolor)
go2col[grey_go] = GREY
pltobj = GoSubDagPlot(gosubdag_regp, go2color=go2col)
pltobj.plt_dag('viral_rp.png')
In [17]:
gosubdag_regn = GoSubDag({virus_trigger_silence}, godag, relationships={'regulates', 'negatively_regulates',})
# Report all ancesters of grey term
grey_go = 'GO:0050794' # regulation of cellular process
ancestors = gosubdag_regn.rcntobj.go2parents[grey_go]
prt_goids(ancestors, gosubdag_regn)
Cyan dashed lines represent negatively regulates relationships
NOTE: In this example, the following relationships argument will have no affect because no green GO IDs have the relationship, negatively_regulates:
--relationships=negatively_regulates
To see negatively_regulates, specify both regulates and negatively_regulates:
--relationships=regulates,negatively_regulates
Note that specifying both regulates and negatively_regulates will case the magenta GO IDs to be traversed. The magenta GO IDs are accessed by both the regulates and the positively_regulates relationships.
$ go_plot.py -o viral_rn.png --relationships=regulates,negatively_regulates GO:0050794#d8dcd6 GO:0060150 --obo=viral_gene_silence.obo --go_color_file=viral_gene_silence.txt
In [18]:
# Color the GO of interest in a copy of the color dictionary
go2col = dict(go2hexcolor)
go2col[grey_go] = GREY
pltobj = GoSubDagPlot(gosubdag_regn, go2color=go2col)
pltobj.plt_dag('viral_rn.png')
Copyright (C) 2016-2019, DV Klopfenstein et al. All rights reserved