Skip to content

Commit

Permalink
implement graph orientation change (graphviz rankdir) (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchwarzMarek committed Apr 12, 2024
1 parent d01169e commit f21c24c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
Binary file added doc/images/plot_go/rankdir_LR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/plot_go/rankdir_TB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions doc/md/README_go_plot.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,22 @@ scripts/go_plot.py GO:0003304 GO:0003146#d6fffa --r -o heart_jogging_ice_r1.png
![heart_jogging_r1](../images/plot_go/heart_jogging_ice_r1.png)


## Chage orietation of plot output
With graphviz, it is possible to change the orientation of the graph output, which may be convenient for large graphs.
Options are TB, LR, BT and RL mirroring GraphViz ![https://graphviz.org/docs/attrs/rankdir/](https://graphviz.org/docs/attrs/rankdir/)

```
# top -> bottom (default)
scripts/go_plot.py GO:0000010 -o orientation_TB.png --obo=tests/data/mini_obo.obo --rankdir=TB
```
![TB](../images/plot_go/rankdir_TB.png)

```
# left -> right
scripts/go_plot.py GO:0000010 -o orientation_LR.png --obo=tests/data/mini_obo.obo --rankdir=LR
```
![LR](../images/plot_go/rankdir_LR.png)



Copyright (C) 2010-2018, DV Klopfenstein, Haibao Tang et al. All rights reserved.
6 changes: 5 additions & 1 deletion goatools/cli/gosubdag_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
[--draw-children]
[--norel]
[--go_color_file=<file.txt>]
[--rankdir=<rankdir>]
go_plot.py [GO ...] [--obo=<file.obo>] [-o <file.png>] [-t <title>]
[--shorten] [-p] [-c]
go_plot.py [GO ...] [-o <file.png>] [--draw-children]
Expand Down Expand Up @@ -58,6 +59,7 @@
--draw-children Draw children. By default, they are not drawn.
--go_aliases=<go_aliases.txt> ASCII file containing letter alias
--go_color_file=<file.txt> GO color file. GO and color (eg #cafffb)
--rankdir=TB|LR|BT|RL Choose orientation of graph; Top->Bottom, Left->Right, ... [default: TB]
--norel Don't load relationship from the GO DAG
"""
Expand Down Expand Up @@ -151,7 +153,9 @@ class PlotCli(object):
'obo',
'relationships',
'go_color_file',
'go_aliases'])
'go_aliases',
'rankdir',
])
kws_set = set(['relationship',
'parentcnt', 'childcnt', 'mark_alt_id', 'shorten',
'draw-children',
Expand Down
1 change: 1 addition & 0 deletions goatools/gosubdag/plot/gosubdag_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _init_kws(self, **kws_usr):
kws_self['dag']['labelloc'] = 't'
dpi = str(kws_self['dag'].get('dpi', self.dflts['dpi']))
kws_self['dag']['dpi'] = dpi
kws_self['dag']['rankdir'] = kws_usr.get('rankdir', 'TB')
return kws_self

def plt_dag(self, fout_img, engine="pydot"):
Expand Down
40 changes: 40 additions & 0 deletions tests/test_go_plot_orient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""Test running go_plot subdag with different output orientation."""

from __future__ import print_function

import os
import subprocess


def cmds_plot_annos():
"""Test running go_plot subdag with different output orientation."""
for idx, (cmd, check) in enumerate(_get_cmds()):
print('------------------- TEST {I} ------------------------------------'.format(I=idx))
print(f'CMD: {cmd}')
r = subprocess.run(cmd, shell=True, cwd='..')
assert r.returncode == 0

with open('bbbb.dot') as f:
ff = f.read()
if check not in ff:
raise AssertionError(f'Expected phrase "{check}" were not found in dot output.')
os.remove('bbbb.dot')

print("TEST PASSED")


def _get_cmds():
"""Commands for generation of different styles, output md5sum"""
# pylint: disable=line-too-long
return [
('scripts/go_plot.py GO:0000010 -o tests/bbbb.dot --obo=tests/data/mini_obo.obo', 'rankdir=TB'),
('scripts/go_plot.py GO:0000010 -o tests/bbbb.dot --obo=tests/data/mini_obo.obo --rankdir=TB', 'rankdir=TB'),
('scripts/go_plot.py GO:0000010 -o tests/bbbb.dot --obo=tests/data/mini_obo.obo --rankdir=LR', 'rankdir=LR'),
('scripts/go_plot.py GO:0000010 -o tests/bbbb.dot --obo=tests/data/mini_obo.obo --rankdir=BT', 'rankdir=BT'),
('scripts/go_plot.py GO:0000010 -o tests/bbbb.dot --obo=tests/data/mini_obo.obo --rankdir=RL', 'rankdir=RL'),
]


if __name__ == '__main__':
cmds_plot_annos()

0 comments on commit f21c24c

Please sign in to comment.