-
Notifications
You must be signed in to change notification settings - Fork 0
/
014.2.TCGA.LineageSpecific.R
228 lines (217 loc) · 9.71 KB
/
014.2.TCGA.LineageSpecific.R
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
rm(list = ls());gc();rm(list = ls())
Num = "014.2."
all = c(
"ACC",
"BLCA",
"BRCA",
"CESC",
"CHOL",
"COAD",
"DLBC",
"ESCA",
"GBM",
"HNSC",
"KICH",
"KIRC",
"KIRP",
#"LAML",
"LGG",
"LIHC",
"LUAD",
"LUSC",
"MESO",
"OV",
"PAAD",
"PCPG",
"PRAD",
"READ",
"SARC",
"SKCM",
"STAD",
"TGCT",
"THCA",
"THYM",
"UCEC",
"UCS",
"UVM"
)
i = 1
focal.cancer = paste0("TCGA-",all[i])
a = fread(paste0("~/Pseudo/Data/Seqdata/TCGA/MergeCount/",focal.cancer,".mergecount.csv")) %>% as.data.frame()
row.names(a) = a$V1
a = a[,-1]
a %<>% dplyr::select(.,ends_with("TP"))
cpm = apply(a, 2, function(x)x/sum(x) * 10^6) %>% as.data.frame()
cpm$mean = apply(cpm,1,mean)
mtx = cpm[,"mean",drop=FALSE]
colnames(mtx) = paste0(focal.cancer,"(",ncol(a),")")
rm(a);rm(cpm)
for (i in 2:length(all)) {
focal.cancer = paste0("TCGA-",all[i])
a = fread(paste0("~/Pseudo/Data/Seqdata/TCGA/MergeCount/",focal.cancer,".mergecount.csv")) %>% as.data.frame()
row.names(a) = a$V1
a = a[,-1]
a %<>% dplyr::select(.,ends_with("TP"))
cpm = apply(a, 2, function(x)x/sum(x) * 10^6) %>% as.data.frame()
cpm$mean = apply(cpm,1,mean)
cpm = cpm[,"mean",drop=FALSE]
#colnames(cpm) = paste0(focal.cancer,"(",ncol(a),")")
mtx[,paste0(focal.cancer,"(",ncol(a),")")] = cpm[match(row.names(mtx),row.names(cpm)),1]
}
colnames(mtx) %<>% gsub("TCGA-","",.) %>% gsub("("," (",.,fixed = TRUE)
#1.use tau for filter lineage-specific genes
if (FALSE) {
#tau <- function(x){
# x <- x[apply(x, 1, function(y)sum(y >0.1 ) >=1),]
# x <- as.data.frame(t(apply(x, 1,function(y){1-y/max(y)})))
# x$tau <- apply(x,1,function(y)sum(y)/(length(y)-1))
# return(as.data.frame(x))
#}
tmp <- tau(mtx)
x = mtx
x = x[apply(x, 1, sum)>0,]
x$tau = tmp[match(row.names(x),row.names(tmp)),"tau"]
x = x[x$tau>0.8,] %>% na.omit()
pheatmap(x[,-ncol(x)],scale = "row",
colorRampPalette(c("#f4f4c8", "#fd0c06"))(50),
#annotation_colors = ann_colors,
#annotation_row = row,
annotation_legend = T,
border_color = 'black',#设定每个格子边框的颜色,border=F则无边框
cluster_rows = F, #对行聚类
cluster_cols = F, #队列聚类
show_colnames = T, #是否显示列名
show_rownames = F, #是否显示行名
main = "TCGA"
)
}
#2.use expression level
lineage = mtx
lineage = lineage[apply(lineage, 1, sum)>0,]
lineage = apply(lineage, 1, function(x)x/sum(x)*100) %>% t() %>% as.data.frame()
lineage = lineage[apply(lineage, 1, max) >15,]
lineage = lineage[apply(lineage, 1, function(x)sort(x,decreasing = TRUE)[2]) < 5,]
lineage$dis = colnames(lineage)[apply(lineage,1, which.max)]
lineage$max = apply(lineage[,-ncol(lineage)],1,max)
lineage = lineage[order(lineage$dis,-lineage$max),]
b = read.csv("~/Pseudo/Data/Ref/Human/geneHuman.bed",header = FALSE,sep = "\t")
write.table(lineage[intersect(row.names(lineage) ,b[grepl("pseu",b$V5),4]),],
file = "~/Pseudo/Data/Seqdata/TCGA/Expressbreadth/LineageSpcific.pseudo.csv",
quote = FALSE,sep = "\t")
write.table(lineage,
file = "~/Pseudo/Data/Seqdata/TCGA/Expressbreadth/LineageSpcific.all.csv",
quote = FALSE,sep = "\t")
#colnames(lineage) %<>% gsub("TCGA-","",.) %>% gsub("("," (",.,fixed = TRUE)
# (All, Pseudo) + (Lineage, Ubiquitous) -----------------------------------
#* All + Lineage -----------------------------------
p1 = pheatmap(lineage[,-c(ncol(lineage),ncol(lineage)-1)],#scale = "row",
colorRampPalette(c("#f4f4c8", "#ae1e1e"))(50),
#annotation_colors = ann_colors,
#annotation_row = row,
annotation_legend = T,
border_color = 'black',#设定每个格子边框的颜色,border=F则无边框
cluster_rows = F, #对行聚类
cluster_cols = F, #队列聚类
show_colnames = T, #是否显示列名
show_rownames = F, #是否显示行名
main = "All genes"
)
ggsave(p1,filename = file.path("~/Pseudo/Result/TCGA/Picture",paste0(Num,"Allgene.LineageSpecific.pdf")),
device = "pdf",width = 5,height = 4)
#* Pseudo + Lineage -----------------------------------
p2 = pheatmap(lineage[intersect(row.names(lineage) ,b[grepl("pseu",b$V5),4]),-c(ncol(lineage),ncol(lineage)-1)],#scale = "row",
colorRampPalette(c("#f4f4c8", "#ae1e1e"))(50),
#annotation_colors = ann_colors,
#annotation_row = row,
annotation_legend = T,
border_color = 'black',#设定每个格子边框的颜色,border=F则无边框
cluster_rows = F, #对行聚类
cluster_cols = F, #对列聚类
show_colnames = T, #是否显示列名
show_rownames = F #是否显示行名
)
ggsave(p2,filename = file.path("~/Pseudo/Result/TCGA/Picture",paste0(Num,"Pseudogene.LineageSpecific.pdf")),
device = "pdf",width = 5,height = 4)
#* All + Ubiquitous -----------------------------------
ubiquitous = mtx
ubiquitous = ubiquitous[apply(ubiquitous, 1, sum)>0,]
ubiquitous = apply(ubiquitous, 1, function(x)x/sum(x)*100) %>% t() %>% as.data.frame()
ubiquitous = ubiquitous[apply(ubiquitous, 1, max) <= 30,]
ubiquitous = ubiquitous[apply(ubiquitous, 1, function(x)sort(x,decreasing = TRUE)[5]) > 5,]
write.table(ubiquitous[intersect(row.names(ubiquitous) ,b[grepl("pseu",b$V5),4]),],
file = "~/Pseudo/Data/Seqdata/TCGA/Expressbreadth/Ubiquitous.pseudo.csv",
quote = FALSE,sep = "\t")
write.table(lineage,
file = "~/Pseudo/Data/Seqdata/TCGA/Expressbreadth/Ubiquitous.all.csv",
quote = FALSE,sep = "\t")
#ubiquitous = ubiquitous[apply(ubiquitous, 1, function(x)sort(x,decreasing = TRUE)[10]) > 3,]
#ubiquitous = ubiquitous[apply(ubiquitous, 1, function(x)sort(x,decreasing = TRUE)[2]) < 5,]
#ubiquitous$dis = colnames(ubiquitous)[apply(ubiquitous,1, which.max)]
#ubiquitous$max = apply(ubiquitous[,-ncol(ubiquitous)],1,max)
#ubiquitous = ubiquitous[order(ubiquitous$dis,-ubiquitous$max),]
p3 = pheatmap(ubiquitous,#scale = "row",
colorRampPalette(c("#f4f4c8", "#fd0c06"))(50),
#annotation_colors = ann_colors,
#annotation_row = row,
annotation_legend = T,
border_color = 'black',#设定每个格子边框的颜色,border=F则无边框
cluster_rows = F, #对行聚类
cluster_cols = F, #队列聚类
show_colnames = T, #是否显示列名
show_rownames = F, #是否显示行名
main = "All gene"
)
ggsave(p3,filename = file.path("~/Pseudo/Result/TCGA/Picture",paste0(Num,"All.Ubiquitous.pdf")),
device = "pdf",width = 5,height = 4)
#* Pseudogene + Ubiquitous -----------------------------------
p4 = pheatmap(ubiquitous[intersect(row.names(ubiquitous) ,b[grepl("pseu",b$V5),4]),-c(ncol(ubiquitous),ncol(ubiquitous)-1)],#scale = "row",
colorRampPalette(c("#f4f4c8", "#ae1e1e"))(50),
#annotation_colors = ann_colors,
#annotation_row = row,
annotation_legend = T,
border_color = 'black',#设定每个格子边框的颜色,border=F则无边框
cluster_rows = F, #对行聚类
cluster_cols = F, #队列聚类
show_colnames = T, #是否显示列名
show_rownames = F #是否显示行名
)
ggsave(p4,filename = file.path("~/Pseudo/Result/TCGA/Picture",paste0(Num,"Pseudogene.Ubiquitous.pdf")),
device = "pdf",width = 5,height = 4)
# Intersect with DDG -----------------------------------
ddg = fread("~/Pseudo/Result/Human/Savedata/DDG/all.ddg.csv",header = FALSE) %>% as.data.frame()
#for lineage-specific pseudo
fisher.test(matrix(c(sum(row.names(lineage) %in% ddg$V1), #N of ddg
sum(row.names(lineage) %in% b[grepl("pseu",b$V5),4]), #N of pseudo
length(unique(ddg$V1)), #all ddg
length(b[grepl("pseu",b$V5),4])), #all pseudo
nrow = 2)) #p = 9e-04
#for ubiquitous pseudo
fisher.test(matrix(c(sum(row.names(ubiquitous) %in% ddg$V1), #N of ddg
sum(row.names(ubiquitous) %in% b[grepl("pseu",b$V5),4]), #N of pseudo
length(unique(ddg$V1)), #all ddg
length(b[grepl("pseu",b$V5),4])), #all pseudo
nrow = 2))
fish = data.frame("Specific"=sum(row.names(lineage) %in% ddg$V1)/
sum(row.names(lineage) %in% b[grepl("pseu",b$V5),4])*100,
"Ubiquitous"=sum(row.names(ubiquitous) %in% ddg$V1)/
sum(row.names(ubiquitous) %in% b[grepl("pseu",b$V5),4])*100) %>% t() %>% as.data.frame()
fish$type = row.names(fish)
p5 = ggplot(fish,aes(type,V1,fill=type))+geom_bar(stat = "identity")+
scale_fill_manual(values=c("#ae1e1e","#D08671"))+
theme_classic()+ylab("(%) DDPs")+
theme(panel.grid.major =element_blank(),
panel.grid.minor = element_blank(),
axis.text.x = element_text(size=12),axis.title.x = element_blank(),
axis.text.y = element_text(size=12),axis.title.y = element_text(size=14))+
guides(fill=FALSE)+
scale_y_continuous(expand = c(0, 0),limits = c(0,40))+
#geom_hline(yintercept = length(unique(ddg$V1))/length(b[grepl("pseu",b$V5),4])*100,color="black",linetype = "dashed",size=0.8)+
geom_segment(aes(x=1, y=37.5, xend=2, yend=37.5))+
annotate("text", x=1.5, y=38, label="**",size=7) #p=0.004
ggsave(p5,filename = file.path("~/Pseudo/Result/TCGA/Picture",paste0(Num,"PropDynamic.PseudoType.pdf")),
device = "pdf",width = 3,height = 4.5)
fisher.test(matrix(c(sum(row.names(lineage) %in% ddg$V1), #N of ddg
sum(row.names(lineage) %in% b[grepl("pseu",b$V5),4]), #N of pseudo
sum(row.names(ubiquitous) %in% ddg$V1), #N of ddg
sum(row.names(ubiquitous) %in% b[grepl("pseu",b$V5),4])), #all pseudo
nrow = 2)) #p=0.004