Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/perl -w
#
# pubmed_trend.pl
#
# Created by David Ruau on 2011-02-17.
# Department of Pediatrics/Div. System Medicine Stanford University.
#
##################### USAGE #########################
#
# Query PubMed with Eutils tools
@bobthecat
bobthecat / pubmed_barplot
Created May 15, 2012 22:40
Barplot for pubmed trend
plot_bar <- function(x=sex.pub, linecol="royalblue", cols, addArg=TRUE) {
bp <- barplot(x, col=cols, add=addArg)
fit <- stats::lowess(x, f=1/3)
lines(x=bp, fit$y, col=linecol, lwd=3)
}
@bobthecat
bobthecat / pubmed_pain.r
Created May 15, 2012 22:44
pubmed trend for pain
source('pubmed_trend.r')
sex.pub <- pubmed_trend(search.str = 'Sex+Characteristics[mh] AND Pain[mh]', year.span=1970:2011)
analgesic.pub <- pubmed_trend(search.str = 'Sex+Characteristics[mh] AND Analgesics[mh]', year.span=1970:2011)
source('plot_bar.r')
library("RColorBrewer")
pdf(file='sex_pain.pdf', height=8, width=8)
par(las=1)
colorfunction = colorRampPalette(brewer.pal(9, "Reds"))
@bobthecat
bobthecat / get_the_data.r
Created May 16, 2012 06:35
Obtaining a gene list from data in GEO
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
## Rank Product
eRP <- RP(e[,c(1:3, 7:10)], cl=c(0,0,0,1,1,1,1), rand = 123)
table <- topGene(eRP, cutoff=0.001, method="pfp", logged=TRUE,
logbase=2, gene.names=rownames(e))
@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
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 / 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
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
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
)
@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)
}