Skip to content

Instantly share code, notes, and snippets.

@daler
Created April 27, 2013 15:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save daler/5473540 to your computer and use it in GitHub Desktop.
Save daler/5473540 to your computer and use it in GitHub Desktop.
Run REVIGO on some example data, download R scripts, and run them.
#!/usr/bin/python
"""
- Submit example data to REVIGO server (http://revigo.irb.hr/)
- Download and run R script for creating the treemap
- Download and run R script for creating the scatterplot
Creates files:
treemap.R, treemap.Rout, revigo_treemap.pdf
scatter.R, scatter.Rout, revigo_scatter.pdf
"""
import os
import urllib
import mechanize
url = "http://revigo.irb.hr/"
# RobustFactory because REVIGO forms not well-formatted
br = mechanize.Browser(factory=mechanize.RobustFactory())
# For actual data, use open('mydata.txt').read()
br.open(os.path.join(url, 'examples', 'example1.txt'))
txt = br.response().read()
# Encode and request
data = {'inputGoList': txt}
br.open(url, data=urllib.urlencode(data))
# Submit form
br.select_form(name="submitToRevigo")
response = br.submit()
# Exact string match on the url for getting the R treemap script
br.follow_link(url="toR_treemap.jsp?table=3")
with open('treemap.R', 'w') as f:
f.write(br.response().read())
# go back and get R script for scatter
br.back()
br.follow_link(url="toR.jsp?table=3")
with open('scatter.R', 'w') as f:
f.write(br.response().read())
# Downloaded scatter script doesn't save PDF, so add this line
f.write('ggsave("revigo_scatter.pdf")')
# Create PDFs
os.system('R CMD BATCH treemap.R')
os.system('R CMD BATCH scatter.R')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment