-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrepare_Integration.R
310 lines (179 loc) · 10.7 KB
/
Prepare_Integration.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# 2021-12-23
# prepare to RDS has OK in material/code_record.R
# this program is used to make RDS for each sample
# and then integration for each sample
# last for cell type annotation
# 2022-2-14 remember : inteV6 is used Nature medicine data and Inte 16 is used NC data
#=============================================================================================================================================
# read all sample and normalized and integration
# library(Seurat)
# inte.list<- list()
# samplelist <- c("A20190305","A20190312","T-Bsc1_MT10","D0927","E0927","Pair_BM","Pair_LUNG","scrBT1431m","scrBT1432m","BT1296","BT1297","BT1291","BT1292")
# for(i in 1:length(samplelist)){
# tmp_dat <- readRDS(paste0("/public/workspace/lily/Lung2Brain/RDS/",samplelist[i],".rds"))
# tmp_dat = NormalizeData(object = tmp_dat)
# tmp_dat <- FindVariableFeatures(object = tmp_dat)
# # scaling
# all.genes <- rownames(x = tmp_dat)
# tmp_dat <- ScaleData(object = tmp_dat, features = all.genes)
# inte.list[[i]] <- tmp_dat
# }
# # now integration
# integration.anchors <- FindIntegrationAnchors(object.list = inte.list)
# inte <- IntegrateData(anchorset = integration.anchors)
# #FindVariableFeatures
# inte <- FindVariableFeatures(inte)
# ##Scaling the integrateda
# all.genes <- rownames(inte)
# inte <- ScaleData(inte, features = all.genes)
# #PCA
# inte <- RunPCA(inte)
# #cluster
# inte <- FindNeighbors(inte)
# inte <- FindClusters(inte)
# #TSNE
# # if Umap can not use
# inte <- RunTSNE(inte)
# inte <- RunUMAP(inte,dims=1:10)
# saveRDS(inte,file="/public/workspace/lily/Lung2Brain/Data/inte_V6.RDS")
# this program is used to make RDS for each sample
# and then integration for each sample
# last for cell type annotation
# 2021-12-30
# test found SangSung data show better result
#=============================================================================================================================================
# read all sample and normalized and integration
# scp from .3 to .5 then integration
# scp [email protected]:/public/workspace/lily/Lung2Brain/HG38_Data/RDS/\{A20190305.RDS,A20190312.RDS,D0927.RDS,E0927.RDS,Pair_BM.RDS,Pair_LUNG.RDS,T-Bsc1_MT10.RDS\} ./
library(Seurat)
inte.list<- list()
samplelist <- grep("*.RDS$",dir("~/Lung2Brain/Version6/Prepare_Data"),value=T)
for(i in 1:length(samplelist)){
tmp_dat <- readRDS(paste0("~/Lung2Brain/Version6/Prepare_Data/",samplelist[i]))
# tmp_dat = NormalizeData(object = tmp_dat)
# tmp_dat <- FindVariableFeatures(object = tmp_dat)
# # scaling
# all.genes <- rownames(x = tmp_dat)
# tmp_dat <- ScaleData(object = tmp_dat, features = all.genes)
inte.list[[i]] <- tmp_dat
}
# now integration
integration.anchors <- FindIntegrationAnchors(object.list = inte.list)
inte <- IntegrateData(anchorset = integration.anchors)
#FindVariableFeatures
inte <- FindVariableFeatures(inte)
##Scaling the integrateda
all.genes <- rownames(inte)
inte <- ScaleData(inte, features = all.genes)
#PCA
inte <- RunPCA(inte)
#cluster
inte <- FindNeighbors(inte)
inte <- FindClusters(inte)
#TSNE
# if Umap can not use
inte <- RunTSNE(inte)
inte <- RunUMAP(inte,dims=1:10)
saveRDS(inte,file="/public/workspace/lily/Lung2Brain/Version6/Data/inte_S16.RDS")
#============================================================================================================================================
# 2021-12-25
# merry Christmas !
# get data from .3 and now define cell types
#============================================================================================================================================
# library(Seurat)
# dat <- readRDS("/public/workspace/lily/Lung2Brain/Version6/Data/inte_V6.RDS")
# DefaultAssay(dat) <- "RNA"
# pdf("/public/workspace/lily/Lung2Brain/Version6/Prepare/inteV6_marker_featureplot.pdf")
# DimPlot(dat,label=T,label.size=6)
# FeaturePlot(dat,features=c('CD3D','CD3E','CD2','PTPRC'),label=T,label.size=3,order=T) # T cell
# FeaturePlot(dat,features=c('CD19','CD68','FCGR3A','LYZ'),label=T,label.size=3,order=T) # Myeloid
# FeaturePlot(dat,features=c('MS4A1',"CD79A",'PTPRC'),label=T,label.size=3,order=T) # B cell
# FeaturePlot(dat,features=c('MAG','MOG','CNDP1','PTPRC'),label=T,label.size=3,order=T) # Oligodendrocyte
# FeaturePlot(dat,features=c('COL1A1','COL1A2','DCN','CD248'),label=T,label.size=3,order=T) # Fibroblast/Vascular
# FeaturePlot(dat,features=c('CLDN5','VWF','ABCG2','CDH5'),label=T,label.size=3,order=T) # Endothelial
# FeaturePlot(dat,features=c("EGFR","EPCAM","KRAS"),label=T,label.size=3,order=T,cols=c("lightgrey", "red"))
# dev.off()
# pdf("/public/workspace/lily/Lung2Brain/Version6/Prepare/inteV6_marker_Vlnplot.pdf",width=20)
# DimPlot(dat,label=T,label.size=6)
# VlnPlot(dat,features=c('CD3D','CD3E','CD2','PTPRC'),pt.size=0) # T cell
# VlnPlot(dat,features=c('CD19','CD68','FCGR3A','LYZ'),pt.size=0) # Myeloid
# VlnPlot(dat,features=c('MS4A1',"CD79A",'PTPRC'),pt.size=0) # B cell
# VlnPlot(dat,features=c('MAG','MOG','CNDP1','PTPRC'),pt.size=0) # Oligodendrocyte
# VlnPlot(dat,features=c('COL1A1','COL1A2','DCN','CD248'),pt.size=0) # Fibroblast/Vascular
# VlnPlot(dat,features=c('CLDN5','VWF','ABCG2','CDH5'),pt.size=0) # Endothelial
# VlnPlot(dat,features=c("EGFR","EPCAM","KRAS"),pt.size=0)
# dev.off()
#============================================================================================================================================
# 2021-12-30
# define cell type and prepare for infercnv
#
#============================================================================================================================================
library(Seurat)
dat <- readRDS("/public/workspace/lily/Lung2Brain/Version6/Data/inte_S16.RDS")
DefaultAssay(dat) <- "RNA"
pdf("/public/workspace/lily/Lung2Brain/Version6/Prepare/inteS16_marker_featureplot.pdf")
DimPlot(dat,label=T,label.size=6)
FeaturePlot(dat,features=c('CD3D','CD3E','CD2','PTPRC'),label=T,label.size=3,order=T) # T cell
FeaturePlot(dat,features=c('CD19','CD68','FCGR3A','LYZ'),label=T,label.size=3,order=T) # Myeloid
FeaturePlot(dat,features=c('MS4A1',"CD79A",'PTPRC'),label=T,label.size=3,order=T) # B cell
FeaturePlot(dat,features=c('MAG','MOG','CNDP1','PTPRC'),label=T,label.size=3,order=T) # Oligodendrocyte
FeaturePlot(dat,features=c('COL1A1','COL1A2','DCN','CD248'),label=T,label.size=3,order=T) # Fibroblast/Vascular
FeaturePlot(dat,features=c('CLDN5','VWF','ABCG2','CDH5'),label=T,label.size=3,order=T) # Endothelial
FeaturePlot(dat,features=c("EGFR","EPCAM","KRAS"),label=T,label.size=3,order=T,cols=c("lightgrey", "red"))
dev.off()
pdf("/public/workspace/lily/Lung2Brain/Version6/Prepare/inteS16_marker_Vlnplot.pdf",width=20)
DimPlot(dat,label=T,label.size=6)
VlnPlot(dat,features=c('CD3D','CD3E','CD2','PTPRC'),pt.size=0) # T cell
VlnPlot(dat,features=c('CD19','CD68','FCGR3A','LYZ'),pt.size=0) # Myeloid
VlnPlot(dat,features=c('MS4A1',"CD79A",'PTPRC'),pt.size=0) # B cell
VlnPlot(dat,features=c('MAG','MOG','CNDP1','PTPRC'),pt.size=0) # Oligodendrocyte
VlnPlot(dat,features=c('COL1A1','COL1A2','DCN','CD248'),pt.size=0) # Fibroblast/Vascular
VlnPlot(dat,features=c('CLDN5','VWF','ABCG2','CDH5'),pt.size=0) # Endothelial
VlnPlot(dat,features=c("EGFR","EPCAM","KRAS"),pt.size=0)
dev.off()
#============================================================================================================================================
# set celltype and sample group
# 2021-12-27
# C4 maybe normal cells and C9 maybe mixture cell clusters
# C22 粒细胞 C24 Mast cells
#============================================================================================================================================
# library(Seurat)
# dat <- readRDS("/public/workspace/lily/Lung2Brain/Version6/Data/inte_V6.RDS")
# dat$celltype <- "unknow"
# dat$celltype[which(dat$seurat_clusters%in%c(0,1,21,23))] <- "Tcell"
# dat$celltype[which(dat$seurat_clusters%in%c(3,6,8,11,12,14,19,22,24))] <- "Myeloid"
# dat$celltype[which(dat$seurat_clusters%in%c(15,18))] <- "Bcell"
# dat$celltype[which(dat$seurat_clusters%in%c(7,10,16,9))] <- "Fibroblast"
# dat$celltype[which(dat$seurat_clusters%in%c(17))] <- "Oligo."
# dat$celltype[which(dat$seurat_clusters%in%c(20))] <- "Endothelial"
# dat$celltype[which(dat$seurat_clusters%in%c(2,5,13,4))] <- "Epithelial"
# # also add type_group information
# #============================================================================================================================================
# dat$type_group <- "unknow"
# dat$type_group[which(dat$orig.ident%in%c("A20190305","A20190312","D0927","T_Bsc1","E0927","Pair_BM"))] <- "LCBM"
# dat$type_group[which(dat$orig.ident%in%c("BT1291","BT1292","BT1296","BT1297","scrBT1431m","scrBT1432m"))] <- "nMLUAD"
# dat$type_group[which(dat$orig.ident%in%c("Pair_LUNG"))] <- "MLUAD"
# saveRDS(dat,file="/public/workspace/lily/Lung2Brain/Version6/Data/inte_V6.RDS")
#============================================================================================================================================
# set celltype and sample group
# 2021-12-30
# C18 is Mast cells
#============================================================================================================================================
library(Seurat)
dat <- readRDS("/public/workspace/lily/Lung2Brain/Version6/Data/inte_S16.RDS")
dat$celltype <- "unknow"
dat$celltype[which(dat$seurat_clusters%in%c(3,4,8,15,24))] <- "Tcell"
dat$celltype[which(dat$seurat_clusters%in%c(0,5,7,9,11,13,19,21,22,25))] <- "Myeloid"
dat$celltype[which(dat$seurat_clusters%in%c(12,17))] <- "Bcell"
dat$celltype[which(dat$seurat_clusters%in%c(1,10,14,18,27))] <- "Fibroblast"
dat$celltype[which(dat$seurat_clusters%in%c(26))] <- "Oligo."
dat$celltype[which(dat$seurat_clusters%in%c(23))] <- "Endothelial"
dat$celltype[which(dat$seurat_clusters%in%c(2,6,16,20))] <- "Epithelial"
# also add type_group information
#============================================================================================================================================
dat$orig.ident[which(dat$orig.ident=="GSE131907")] <- dat$Sample[which(dat$orig.ident=="GSE131907")]
dat$type_group <- "unknow"
dat$type_group[which(dat$orig.ident%in%c("A20190305","A20190312","D0927","T_Bsc1","E0927","Pair_BM"))] <- "LCBM"
dat$type_group[which(dat$orig.ident%in%c("LUNG_T06","LUNG_T08","LUNG_T09","LUNG_T18","LUNG_T19","LUNG_T20","LUNG_T25",'LUNG_T30','LUNG_T34'))] <- "nMLUAD"
dat$type_group[which(dat$orig.ident%in%c("Pair_Lung"))] <- "MLUAD"
saveRDS(dat,file="/public/workspace/lily/Lung2Brain/Version6/Data/inte_S16.RDS")