Skip to content

Commit

Permalink
Add examples of plotting from the command line using new plot_go script
Browse files Browse the repository at this point in the history
  • Loading branch information
dvklopfenstein committed Jun 16, 2018
1 parent ab12c1e commit e913106
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ the output that are not present in their `association` file. Use

### Read and plot GO lineage

* [plot_go.py](doc/md/README_plot_go.md)
* [plot_go_term.py](plot_go_term-py)


#### plot_go_term.py

See `plot_go_term.py` for usage. `plot_go_term.py` can plot the lineage
of a certain GO term, by:

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions doc/md/README_plot_go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Plot the GO hierarchy with go_plot.py

* [Plot one GO term and its ancestors]()
* [Plot one GO term and its ancestors (with relationships)]()

## Plot one GO term and its ancestors
Plot one term and all ancestors using the 'is_a' attribute.
```
scripts/go_plot.py GO:0003304
```
![heart_jogging_r0](../images/plot_go/GO_0003304_myocardial_epithelial_involution_involved_in_heart_jogging.png)


## Plot one GO term and its ancestors (with relationships)
Plot one term and all ancestors using the 'is_a' attribute and all relationships (--r).

```
scripts/go_plot.py GO:0003304 --r
```
![heart_jogging_r1](../images/plot_go/GO_0003304_myocardial_epithelial_involution_involved_in_heart_jogging_r1.png)

Copyright (C) 2010-2018, DV Klopfenstein, Haibao Tang et al. All rights reserved.
15 changes: 10 additions & 5 deletions goatools/cli/gosubdag_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def cli(self):
def _plt_gogrouped(self, goids, go2color_usr, **kws):
"""Plot grouped GO IDs."""
print("Plotting with GOATOOLS grouping coming soon...")
# fout_img = self.get_outfile(kws['outfile'], goids)
# fout_img = self.get_outfile(kws['outfile'], goids, 'relationship' in kws)
# sections = read_sections(kws['sections'], exclude_ungrouped=True)
# # kws_plt = {k:v for k, v in kws.items if k in self.kws_plt}
# grprobj_cur = self._get_grprobj(goids, sections)
Expand Down Expand Up @@ -234,7 +234,8 @@ def _plt_gogrouped(self, goids, go2color_usr, **kws):

def _plt_gosubdag(self, goids, go2color, **kws):
"""Plot GO IDs."""
fout_img = self.get_outfile(kws['outfile'], goids)
print("PLOTTING KWS", kws)
fout_img = self.get_outfile(kws['outfile'], goids, 'relationship' in kws)
objcolor = Go2Color(self.gosubdag, objgoea=None, go2color=go2color)
objplt = GoSubDagPlot(self.gosubdag, Go2Color=objcolor, **kws)
objplt.prt_goids(sys.stdout)
Expand Down Expand Up @@ -294,19 +295,23 @@ def _err(self, msg, err=True):
sys.stdout.write(txt)
sys.exit(0)

def get_outfile(self, outfile, goids=None):
def get_outfile(self, outfile, goids=None, b_rel=False):
"""Return output file for GO Term plot."""
# 1. Use the user-specfied output filename for the GO Term plot
if outfile != self.dflt_outfile:
return outfile
rstr = "_r1" if b_rel else ""
# 2. If only plotting 1 GO term, use GO is in plot name
if goids is not None and len(goids) == 1:
goid = next(iter(goids))
goobj = self.gosubdag.go2obj[goid]
fout = "GO_{NN}_{NM}".format(NN=goid.replace("GO:", ""), NM=goobj.name)
return ".".join([re.sub(r"[\s#'()+,-./:<=>\[\]_}]", '_', fout), 'png'])
return "".join([re.sub(r"[\s#'()+,-./:<=>\[\]_}]", '_', fout), rstr, '.png'])
# 3. Return default name
return self.dflt_outfile
if not b_rel:
return self.dflt_outfile
else:
return self.dflt_outfile.replace('.png', '_r1.png')

@staticmethod
def _get_optional_attrs(kws):
Expand Down

0 comments on commit e913106

Please sign in to comment.