Created
January 29, 2016 21:56
-
-
Save dela3499/201c198b40aa18806b82 to your computer and use it in GitHub Desktop.
GEO2R test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version info: R 2.14.1, Biobase 2.15.3, GEOquery 2.23.2, limma 3.10.1 | |
# R scripts generated Fri Jan 29 16:56:51 EST 2016 | |
################################################################ | |
# Differential expression analysis with limma | |
library(Biobase) | |
library(GEOquery) | |
library(limma) | |
# load series and platform data from GEO | |
gset <- getGEO("GSE38410", GSEMatrix =TRUE) | |
if (length(gset) > 1) idx <- grep("GPL6947", attr(gset, "names")) else idx <- 1 | |
gset <- gset[[idx]] | |
# make proper column names to match toptable | |
fvarLabels(gset) <- make.names(fvarLabels(gset)) | |
# group names for all samples | |
sml <- c("G0","G0","G0","G0","G0","G1","G1","G1","G1","G1"); | |
# set up the data and proceed with analysis | |
fl <- as.factor(sml) | |
gset$description <- fl | |
design <- model.matrix(~ description + 0, gset) | |
colnames(design) <- levels(fl) | |
fit <- lmFit(gset, design) | |
cont.matrix <- makeContrasts(G1-G0, levels=design) | |
fit2 <- contrasts.fit(fit, cont.matrix) | |
fit2 <- eBayes(fit2, 0.01) | |
tT <- topTable(fit2, adjust="fdr", sort.by="B", number=250) | |
# load NCBI platform annotation | |
gpl <- annotation(gset) | |
platf <- getGEO(gpl, AnnotGPL=TRUE) | |
ncbifd <- data.frame(attr(dataTable(platf), "table")) | |
# replace original platform annotation | |
tT <- tT[setdiff(colnames(tT), setdiff(fvarLabels(gset), "ID"))] | |
tT <- merge(tT, ncbifd, by="ID") | |
tT <- tT[order(tT$P.Value), ] # restore correct order | |
tT <- subset(tT, select=c("ID","adj.P.Val","P.Value","t","B","logFC","Gene.symbol","Gene.title")) | |
write.table(tT, file=stdout(), row.names=F, sep="\t") | |
################################################################ | |
# Boxplot for selected GEO samples | |
library(Biobase) | |
library(GEOquery) | |
# load series and platform data from GEO | |
gset <- getGEO("GSE38410", GSEMatrix =TRUE) | |
if (length(gset) > 1) idx <- grep("GPL6947", attr(gset, "names")) else idx <- 1 | |
gset <- gset[[idx]] | |
# group names for all samples in a series | |
sml <- c("G0","G0","G0","G0","G0","G1","G1","G1","G1","G1") | |
# order samples by group | |
ex <- exprs(gset)[ , order(sml)] | |
sml <- sml[order(sml)] | |
fl <- as.factor(sml) | |
labels <- c("Control","Case") | |
# set parameters and draw the plot | |
palette(c("#dfeaf4","#f4dfdf", "#AABBCC")) | |
dev.new(width=4+dim(gset)[[2]]/5, height=6) | |
par(mar=c(2+round(max(nchar(sampleNames(gset)))/2),4,2,1)) | |
title <- paste ("GSE38410", '/', annotation(gset), " selected samples", sep ='') | |
boxplot(ex, boxwex=0.6, notch=T, main=title, outline=FALSE, las=2, col=fl) | |
legend("topleft", labels, fill=palette(), bty="n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment