-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path泛癌临床相关性分析
54 lines (48 loc) · 1.8 KB
/
泛癌临床相关性分析
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#BiocManager::install("limma")
#install.packages("ggpubr")
library(limma)
library(ggpubr)
library(dplyr)
setwd("H:\\BaiduNetdiskDownload\\pan-cancer\\panCancer\\13.cliCor") #修改工作目录
file="singleGeneExp.txt" #输入文件
rt=read.table(file,sep="\t",header=T,check.names=F,row.names=1) #读取表达数据文件
cli1=read.table("clinical.txt",sep="\t",header=T,check.names=F,row.names=1)
cli<-select(cli1,4)
cli<-filter(cli,!(cli[,1]==''))
#读取临床数据文件
gene=colnames(rt)[1]
clinical=colnames(cli)[1]
#对肿瘤类型循环,进行临床相关性分析
outTab=data.frame()
for(i in levels(as.factor(rt$CancerType))){
rt1=rt[(rt[,"CancerType"]==i),]
#交集样品
data=cbind(rt1,gene=rt1[,gene])
data=as.matrix(data[,c(gene,"gene")])
if(nchar(row.names(data)[1])!=nchar(row.names(cli)[1])){
row.names(data)=gsub(".$","",row.names(data))}
data=avereps(data)
sameSample=intersect(row.names(data),row.names(cli))
sameData=data[sameSample,]
sameClinical=cli[sameSample,]
cliExpData=cbind(as.data.frame(sameClinical),sameData)
if(nrow(cliExpData)==0){next}
#设置比较组
group=levels(factor(cliExpData$sameClinical))
comp=combn(group,2)
my_comparisons=list()
for(j in 1:ncol(comp)){my_comparisons[[j]]<-comp[,j]}
#绘制boxplot
boxplot=ggboxplot(cliExpData, x="sameClinical", y="gene", color="sameClinical",
xlab=clinical,
ylab=paste(gene,"expression"),
legend.title=clinical,
title=paste0("Cancer: ",i),
add = "jitter")+
stat_compare_means(comparisons = my_comparisons)
pdf(file=paste0(clinical,".",i,".pdf"),width=5.5,height=5)
print(boxplot)
dev.off()
}