Skip to content

Instantly share code, notes, and snippets.

@bobthecat
bobthecat / expr_matrix.r
Created August 10, 2012 21:40
expr_matrix
library(GEOquery); library(RankProd); library(mouse4302.db)
## Download the data from GEO
gse12499 <- getGEO('GSE12499',GSEMatrix=TRUE)
e <- exprs(gse12499[[1]])
dim(e)
[1] 45101 10
@bobthecat
bobthecat / tweet_air_pol.r
Last active October 7, 2015 20:18
twitter air pollution
library(twitteR)
library(ggplot2)
library(grid)
# download all that you can
pol <- userTimeline('BeijingAir', n=3200)
length(pol)
# 3200
myGrep <- function(x){
@bobthecat
bobthecat / tweet_air_pol.r
Created July 31, 2012 18:36
twitter air pollution
library(twitteR)
library(ggplot2)
library(grid)
# download all that you can
pol <- userTimeline('BeijingAir', n=3200)
length(pol)
# 3200
myGrep <- function(x){
@bobthecat
bobthecat / rcpp_speed.r
Created June 9, 2012 23:32
Rcpp cosine speed comparison
library(rbenchmark)
res <- benchmark( cosine(mat),
cosineRcpp(mat),
columns=c("test", "replications", "elapsed",
"relative", "user.self", "sys.self"),
order="relative",
replications=1000)
res
test replications elapsed relative user.self sys.self
@bobthecat
bobthecat / Rcpp_cosine.r
Created June 9, 2012 23:29
Rcpp cosine similarity
require(inline)
require(RcppArmadillo)
## extract cosine similarity between columns
cosine <- function(x) {
y <- t(x) %*% x
res <- 1 - y / (sqrt(diag(y)) %*% t(sqrt(diag(y))))
return(res)
}
library("igraph")
gg <- graph.data.frame(ppi)
plot(gg,
layout = layout.fruchterman.reingold,
vertex.label = V(gg)$name,
vertex.label.color= "black",
edge.arrow.size=0,
edge.curved=FALSE
)
ppi <- get.ppiNCBI(head(glist, 20))
[1] "7 interactions found"
## Annotate the gene list with Mus musculus metadata
library(org.Mm.eg.db)
ppi$egSymbol <- mget(ppi$egID, envir=org.Mm.egSYMBOL, ifnotfound=NA)
ppi$intID <- mget(ppi$intSymbol, envir=org.Mm.egSYMBOL2EG, ifnotfound=NA)
ppi <- ppi[,c(3,2,1,4)]
ppi
egSymbol intSymbol egID intID
1 Ifi202b Pou5f1 26388 18999
@bobthecat
bobthecat / get.ppiNCBI.r
Created June 4, 2012 03:43
get.ppiNCBI
get.ppiNCBI <- function(g.n) {
require(XML)
ppi <- data.frame()
for(i in 1:length(g.n)){
o <- htmlParse(paste("http://www.ncbi.nlm.nih.gov/gene/", g.n[i], sep=''))
# check if interaction table exists
exist <- length(getNodeSet(o, "//table//th[@id='inter-prod']"))>0
if(exist){
p <- getNodeSet(o, "//table")
## need to know which table is the good one
library(org.Mm.eg.db); library(gplots); library(bioDist)
# get gene in GO cat
gGOcat <- list()
for(i in 1:dim(mrnaGO)[1]){
gGOcat[[mrnaGO$GOBPID[i]]] <- as.vector(unlist(mget(mrnaGO$GOBPID[i], org.Mm.egGO2ALLEGS)))
}
# filter each GO cat by the genes found to be DE
f <- function(vecGO, vecDE){
@bobthecat
bobthecat / GO_over.r
Last active October 4, 2015 22:18
GO_over
source('source_https.r')
## You can now source R scripts from GitHub. The RAW URL is needed.
source_https('https://raw.github.com/bobthecat/codebox/master/GO_over.r')
## Define the universe
library(mouse4302.db)
uniqueId <- unique(as.vector(unlist(as.list(mouse4302ENTREZID))))
entrezUniverse <- uniqueId[!is.na(uniqueId)]
length(entrezUniverse)
[1] 20877