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')