1、根据R包org.Hs.eg.db找到ensembol 基因ID对应的基因名(symbol)
library(org.Hs.eg.db)
if(!require(stringr))install.packages('stringr')
library(stringr)
g2s=toTable(org.Hs.egSYMBOL)
g2e=toTable(org.Hs.egENSEMBL)
g <- data.frame(id=c("ENSG00000000003.13","ENSG00000000005.5","ENSG00000000419.11","ENSG00000000457.12","ENSG00000000460.15","ENSG00000000938.11"))
a <- unlist(lapply(g$id,function(x){
x
str_split(x,'[.]')[[1]][1]}))
geneid <- g2e[match(a,g2e$ensembl_id),]
b <- g2s[match(geneid$gene_id,g2s$gene_id),]
merge(geneid,b,by.x='gene_id',by.y='gene_id')
2、根据R包hgu133a.db找到探针对应的基因名(symbol)
rm(list = ls())
library(hgu133a.db)
ids=toTable(hgu133aSYMBOL)
head(ids)
tz <- c("1053_at","117_at","121_at","1255_g_at","1316_at","1320_at","1405_i_at","1431_at","1438_at","1487_at","1494_f_at","1598_g_at","160020_at","1729_at","177_at")
ids[match(tz,ids$probe_id),]
3、找到R包CLL内置的数据集的表达矩阵里面的TP53基因的表达量,并且绘制在 progress-stable分组的boxplot图,通过 ggpubr 进行美化
rm(list = ls())
suppressPackageStartupMessages(library(CLL))
data(sCLLex)
pd=pData(sCLLex)
exprSet=exprs(sCLLex)
library(hgu95av2.db)
ids <- toTable(hgu95av2SYMBOL)
tmp=ids[ids$symbol=='TP53',1]
for(i in 1:length(tmp)){
boxplot(exprSet[i,]~pd$Disease)
}
library(ggpubr)
lapply(1:length(tmp),function(i){
a <- cbind(exprSet[i,],pd)
colnames(a)[1]='type'
ggboxplot(data = a,x = 'Disease',y = 'type',color = 'Disease')
})
4、找到BRCA1基因在TCGA数据库的乳腺癌数据集(Breast Invasive Carcinoma (TCGA, PanCancer Atlas))的表达情况
rm(list = ls())
options(stringsAsFactors = F)
a <- read.table('plot.txt',sep = '\t',header = T,fill = T)
library(ggplot2)
ggplot(a,aes(x=a$Subtype,y = a$BRCA1..mRNA.Expression.Zscores..RSEM..Batch.normalized.from.Illumina.HiSeq_RNASeqV2.,col=a$Subtype))+geom_boxplot()+geom_jitter()+theme_bw()
5、找到TP53基因在TCGA数据库的乳腺癌数据集的表达量分组看其是否影响生存
rm(list = ls())
options(stringsAsFactors = F)
a <- read.csv('BRCA_7157_50_50.csv',header = T,fill = T)
library(ggplot2)
library(survival)
library(survminer)
dat=a
dat$Status=ifelse(dat$Status=='Dead',1,0)
sfit <- survfit(Surv(Days,Status)~Group,data=dat)
sfit
summary(sfit)
ggsurvplot(sfit,conf.int = F,pval = TRUE)
ggsurvplot(sfit,palette = c('#E7B800','#2E9FDF'),risk.table = TRUE,pval = TRUE,conf.int = TRUE,xlab='Time in months',ggtheme = theme_light())
6、下载数据集GSE17215的表达矩阵并且提取下面的基因画热图。
ACTR3B ANLN BAG1 BCL2 BIRC5 BLVRA CCNB1 CCNE1 CDC20 CDC6 CDCA1 CDH3 CENPF CEP55 CXXC5 EGFR ERBB2 ESR1 EXO1 FGFR4 FOXA1 FOXC1 GPR160 GRB7 KIF2C KNTC2 KRT14 KRT17 KRT5 MAPT MDM2 MELK MIA MKI67 MLPH MMP11 MYBL2 MYC NAT1 ORC6L PGR PHGDH PTTG1 RRM2 SFRP1 SLC39A6 TMEM45B TYMS UBE2C UBE2T
rm(list = ls())
options(stringsAsFactors = F)
#install.packages('pheatmap')
library(GEOquery)
f='GSE17215_eSet.Rdata'
if(!file.exists(f)){
gset <- getGEO('GSE17215',destdir='.',
AnnotGPL = F,
getGPL=F)
save(gset,file = f)
}
a <- strsplit('ACTR3B ANLN BAG1 BCL2 BIRC5 BLVRA CCNB1 CCNE1 CDC20 CDC6 CDCA1 CDH3 CENPF CEP55 CXXC5 EGFR ERBB2 ESR1 EXO1 FGFR4 FOXA1 FOXC1 GPR160 GRB7 KIF2C KNTC2 KRT14 KRT17 KRT5 MAPT MDM2 MELK MIA MKI67 MLPH MMP11 MYBL2 MYC NAT1 ORC6L PGR PHGDH PTTG1 RRM2 SFRP1 SLC39A6 TMEM45B TYMS UBE2C UBE2T',' ')[[1]]
library(hgu133a.db)
ids=toTable(hgu133aSYMBOL)
#head(ids)
tz <- ids[match(a,ids$symbol,nomatch = 0),]
load(f)
class(gset)
dat=exprs(gset[[1]])
dim(dat)
dat2 <- dat[tz$probe_id,]
write.csv(dat2,'dat2.csv')
dat2=read.csv('dat2.csv',header = T)
colnames(dat2)[1]='pid'
dat3=merge(dat2,tz,by.x='pid',by.y='probe_id')
dat3=dat3[,-1]
rownames(dat3) <- dat3$symbol
dat3=dat3[,-ncol(dat3)]
dat3=log2(dat3)
library(pheatmap)
pheatmap::pheatmap(dat3)
7、下载数据集GSE24673的表达矩阵计算样本的相关性并且绘制热图,需要标记上样本分组信息
rm(list = ls())
options(stringsAsFactors = F)
library(GEOquery)
f='GSE24673_eSet.Rdata'
if(!file.exists(f)){
gset <- getGEO('GSE24673',destdir='.',
AnnotGPL = F,
getGPL=F)
save(gset,file = f)
}
load(f)
class(gset)
dat=exprs(gset[[1]])
pd=pData(gset[[1]])
group_list=c(rep('rbc',3),rep('rbn',3),rep('rbc',3),rep('normal',2))
M=cor(dat)
pheatmap::pheatmap(M)
tmp=data.frame(g=group_list)
rownames(tmp)=colnames(M)
pheatmap::pheatmap(M,annotation_col = tmp)
8、找到 GPL6244 platform of Affymetrix Human Gene 1.0 ST Array 对应的R的bioconductor注释包,并且安装它!
rm(list = ls())
options(stringsAsFactors = F)
options()$repos
options()$BioC_mirror
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
BiocManager::install("hugene10sttranscriptcluster.db",ask = F,update = F)
options()$repos
options()$BioC_mirror
9、下载数据集GSE42872的表达矩阵,并且分别挑选出 所有样本的(平均表达量/sd/mad/)最大的探针,并且找到它们对应的基因。
rm(list = ls())
options(stringsAsFactors = F)
library(GEOquery)
f='GSE42872_eSet.Rdata'
if(!file.exists(f)){
gset <- getGEO('GSE42872',destdir='.',
AnnotGPL = F,
getGPL=F)
save(gset,file = f)
}
load(f)
a=gset[[1]]
dat=exprs(a)
dim(dat)
pd=pData(a)
boxplot(dat)
sort(apply(dat, 1, mean),decreasing = T)[1]
sort(apply(dat, 1, sd),decreasing = T)[1]
sort(apply(dat, 1, mad),decreasing = T)[1]
10、下载数据集GSE42872的表达矩阵,并且根据分组使用limma做差异分析,得到差异结果矩阵
rm(list = ls())
options(stringsAsFactors = F)
library(GEOquery)
f='GSE42872_eSet.Rdata'
if(!file.exists(f)){
gset <- getGEO('GSE42872',destdir='.',
AnnotGPL = F,
getGPL=F)
save(gset,file = f)
}
load(f)
a=gset[[1]]
dat=exprs(a)
dim(dat)
pd=pData(a)
group_list=unlist(lapply(pd$title,function(x){strsplit(x,' ')[[1]][4]}))
exprSet=dat
suppressMessages(library(limma))
design <- model.matrix(~0+factor(group_list))
colnames(design)=levels(factor(group_list))
rownames(design)=colnames(exprSet)
design
contrast.matrix<-makeContrasts(paste0(unique(group_list),collapse = "-"),levels = design)
contrast.matrix
##step1
fit <- lmFit(exprSet,design)
##step2
fit2 <- contrasts.fit(fit, contrast.matrix) ##这一步很重要,大家可以自行看看效果
fit2 <- eBayes(fit2,trend=TRUE) ## default no trend !!!
##eBayes() with trend=TRUE
##step3
tempOutput = topTable(fit2, coef=1, n=Inf)
nrDEG = na.omit(tempOutput)
#write.csv(nrDEG2,"limma_notrend.results.csv",quote = F)
head(nrDEG)