from IPython.display import Image Image('https://raw.githubusercontent.com/jmchilton/ipython_notebooks/master/images/launch_ipython_cropped.png') # Load IPython magic for R integration. %load_ext rpy2.ipython %R library(cummeRbund) get(72, True) # Download Galaxy history id number 72 as file in current directory with name '72' %R cuff <- readCufflinks(dbFile='72') # Load history downloaded item (cuffdiff for cummeRbund) %R print(fpkmSCVPlot(genes(cuff))) # Demonstrate plotting with R # Find all differentially expressed genes at a given alpha %R sig <- getSig(cuff, alpha=0.01, level='genes') %R sigGenes <- getGenes(cuff,sig) %R print(length(sig)) # Print a heatmap here and then save as PNG in Galaxy's history. %R print(csHeatmap(sigGenes, cluster='both')) %R png(filename = 'siggene_heatmap.png', width = 900, height = 1000, units = 'px'); \ print(csHeatmap(sigGenes, cluster='both')); \ dev.off() put('siggene_heatmap.png') # Describe gene density. %R dens <- csDensity(genes(cuff)) %R print(dens) # Now pull that dens data structure out of R and make available as a numpy structure in Python %Rpull dens # Iterate through it in Python and create a file 'gene_fpkm.tsv' and upload it to Galaxy history. with open('gene_fpkm.tsv', "w") as f: for val in zip(dens[0]['gene_id'], dens[0]['fpkm']): f.write("\t".join(map(str, val)) + "\n") put("gene_fpkm.tsv") from IPython.display import Image Image('https://raw.githubusercontent.com/jmchilton/ipython_notebooks/master/images/save_notebook_cropped.png')