Installing R & Bioconductor on High Sierra

I had some trouble getting R and Bioconductor installed on macOS 10.13 High Sierra because of issues with compilers. Here is how I got it to work.

  • Download and install miniconda (https://conda.io/miniconda.html)
  • Use conda to install compilers:
    conda install clang_osx-64 clangxx_osx-64 gfortran_osx-64
  • Use conda to install R and R packages XML and openssl (for some reason I could not install these from within R):
    conda install r r-xml r-openssl
  • Open R and install bioconductor:
    >source("https://bioconductor.org/biocLite.R")
    >biocLite()

     

Installing pip on OS X without sudo

Without administrator privledges, it may not be possible to install the Python package manager, pip, using the default method:

python get-pip.py

In this case, pip can be installed in the user’s home folder using:

python get-pip.py --user

This installs pip in the site.USER_BASE/bin directory. But where is this? To find out, open python, import the site module, and extract the USER_BASE variable:

python
 >>> import site
 >>> print(site.USER_BASE)
 /Users/jgalazka/Library/Python/2.7

Thus, in this case, pip is installed in /Users/jgalazka/Library/Python/2.7/bin. Add this directory to your path and test your install:

pip --help

When you use pip, remember to include the —user option:

pip install --user

Credit to Ramesh Nethi:
https://forcecarrier.wordpress.com/2013/07/26/installing-pip-virutalenv-in-sudo-free-way/

Credit to Richard Michael:
https://github.com/pypa/pip/issues/3027

Visualizing differentially expressed genes in Cytoscape

go_network_all

A network of differentially expressed GO terms produced with Cytoscape.

The Cytoscape app, EnrichmentMap, displays differentially expressed Gene Ontology (GO) terms as a network, which aids in the interpretation of RNA-sequencing experiments. Below is a step-by-step guide to preparing the necessary input files for running Enrichment Map, along with the necessary python scripts.

First, prepare a Genesets File. Each row of this file corresponds to one GO term and has the following format: GO term (tab) description (tab) tab delimited list of all genes associated with this GO term. To prepare this, download the core ontology (go.obo), and the gene annotation for your genome of choice from the Gene Ontology Consortium. Using these as inputs, run: python GOontology2gmt.py > gene_sets_file.gmt.

Next, prepare an Enrichment Results File. Each row of this file lists one GO term and  the probability that it is differentially expressed. To prepare this, use the gene_sets_file.gmt file prepared above (necessary in case only a subset of GO terms was used), and the output from the R package, goseq, as inputs for the python script, goseq2enrichmentresults.py. See this post for advice on running goseq.

Finally, prepare an Expression Data File. To do this, run the script cufflinksGeneExpdiff2expressionDataFile.py, which takes the Cufflinks output file, gene_exp.diff, and reformats it appropriately.

Use these as inputs for the EnrichmentMap app.

 

goseq from Cufflinks output using mm10

I prefer to use Tophat and Cufflinks to identify differentially expressed  (DE) genes from RNA-seq datasets, and the R package, goseq, to identify significantly enriched gene ontology (GO) terms within the set of DE genes. Getting Cufflinks and goseq to interoperate  is relatively straight forward, but is a bit more complicated if using a genome not natively supported by goseq. This guide walks through the process step-by-step and provides links to necessary python scripts. I used this process successfully with the UCSC mm10 annotation available from iGenomes.

First, produce a file listing the tested genes and whether or not they were differentially expressed. This file will have two, tab-delimited columns. The first column lists the gene, while the second signifies if this gene is or isn’t DE with a 1 or 0. This information is contained in the Cufflinks output file, gene_exp.diff, and simply needs to be reformatted by running: cat gene_exp.diff | python cufflinksout2goseq.py > de4goseq.txt.

Now, produce a file listing the transcript lengths of all genes. The ordering must match the ordering of de4goseq.txt above. Transcript lengths can be constructed from the appropriate .gtf file (must be the same .gtf used by Tophat and Cufflinks) by running: python geneLengths4Goseq.py > lengths4goseq.txt. This script requires access to the Cufflinks output gene_exp.diff to ensure that the ordering matches the de4goseq.txt file above.

Next, produce a file listing the GO term mappings for each gene. A given gene often has more than one mapping, and will be listed multiple times. This can be done by downloading the mm10 GO mapping from the Gene Ontology Consortium and running: python GOmappings4goseq.py > go4goseq.txt.

In R, load de4goseq.txt and convert to goseq friendly format:

de_data = read.csv('de4goseq.txt', sep='\t', header=FALSE)
diff_express = de_data$V2
names(diff_express) = de_data$V1
head(diff_express)

Still in R, load lengths4goseq.txt and convert to goseq friendly format:

length_df = read.csv('lengths4goseq.txt', sep='\t', header=FALSE)
lengths = length_df$V2
head(lengths)

Still in R, load go4seq.txt:

cat_map = read.csv('go4goseq.txt', sep='\t', head=FALSE)
head(cat_map)

Still in R, install goseq, load it and run:

source('http://bioconductor.org/biocLite.R')
biocLite('goseq')
library(goseq)
pwf = nullp(diff_express, bias.data=lengths, plot.fit=TRUE)
GO.wall = goseq(pwf, gene2cat=cat_map)

Still in R, output to a tab delimited file:

write.table(GO.wall, file='goseq_out.txt', sep='\t')

Inexact computing for complex systems

Clouds_from_the_ISS

Currently, the best climate models depict the Earth as an interlocking grid of 100 km2 cells and predict conditions monolithically within each cell. That resolution is not sufficient, and scientist are looking to push the grid size down to 1 km2. A computer capable of running such a model could be built with present technology but it would consume an immense amount of energy, and so the real challenge is staying under a stated energy budget of 20 MW.

One proposed strategy to achieve this is building processors with reduced precision but increased efficiency. The idea is profiled in the New York Times (A Climate-Modeling Strategy That Won’t Hurt the Climate). The trick is to reduce precision in the right places. Certain geophysical processes are deterministically chaotic and their behavior could be captured with reduced precision calculations. Work on what parts are tolerant to this approach is ongoing (On the use of inexact, pruned hardware in atmospheric modelling).

Does this have relevance to modeling cellular and sub cellular processes? A future update will address this question.