-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01_BarnyardIntegration.R
297 lines (229 loc) · 9.8 KB
/
01_BarnyardIntegration.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
# devtools::install_github(repo = "satijalab/seurat", ref = "develop")
library(Seurat)
library(ggplot2)
library(viridis)
library(cowplot)
library(ggplotify)
options(future.globals.maxSize = 4000 * 1024^2)
################################################################################
# Load 10X data & Create Seurat Object...
DMSO_RdI.data <- Read10X(data.dir = "CellRangerOuts/RdI_DMSO_barnyard_outs/")
NM002_RdI.data <- Read10X(data.dir = "CellRangerOuts/RdI_NM002_barnyard_outs/")
DMSO_RdII.data <- Read10X(data.dir = "CellRangerOuts/RdII_DMSO_barnyard_outs/filtered_feature_bc_matrix/")
NM002_RdII.data <- Read10X(data.dir = "CellRangerOuts/RdII_UM002_barnyard_outs/filtered_feature_bc_matrix/")
################################################################################
# DMSO
######
RdI_DMSO <- CreateSeuratObject(
counts = DMSO_RdI.data,
min.cells = 3,
min.features = 200,
project = "DMSO_RdI"
)
RdII_DMSO <- CreateSeuratObject(
counts = DMSO_RdII.data,
min.cells = 3,
min.features = 200,
project = "DMSO_RdII"
)
RdI_DMSO$Arm <- "DMSO"
RdI_DMSO <- RenameCells(
object = RdI_DMSO,
new.names = paste0("DMSO_I_", colnames(x = RdI_DMSO))
)
RdII_DMSO$Arm <- "DMSO"
RdII_DMSO <- RenameCells(
object = RdII_DMSO,
new.names = paste0("DMSO_II_", colnames(x = RdII_DMSO))
)
# Cell Filtering QC
# RdI
RdI_DMSO$percent.mt <- PercentageFeatureSet(RdI_DMSO, pattern = "^MT-")
RdI_DMSO[["percent.hg19"]] <- PercentageFeatureSet(RdI_DMSO, pattern = "^hg19-")
RdI_DMSO[["percent.mm10"]] <- PercentageFeatureSet(RdI_DMSO, pattern = "^mm10-")
pdf(
file = "01_output/RdI_DMSO_prefilterQC.pdf"
)
VlnPlot(RdI_DMSO, features = c("percent.hg19", "percent.mm10"))
FeatureScatter(object = RdI_DMSO, feature1 = "nCount_RNA", feature2 = "percent.mt")
FeatureScatter(object = RdI_DMSO, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
dev.off()
# RdII
RdII_DMSO$percent.mt <- PercentageFeatureSet(RdII_DMSO, pattern = "^MT-")
RdII_DMSO[["percent.hg19"]] <- PercentageFeatureSet(RdII_DMSO, pattern = "^hg19-")
RdII_DMSO[["percent.mm10"]] <- PercentageFeatureSet(RdII_DMSO, pattern = "^mm10-")
pdf(
file = "01_output/RdII_DMSO_prefilterQC.pdf"
)
VlnPlot(RdII_DMSO, features = c("percent.hg19", "percent.mm10"))
FeatureScatter(object = RdII_DMSO, feature1 = "nCount_RNA", feature2 = "percent.mt")
FeatureScatter(object = RdII_DMSO, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
dev.off()
################################################################################
# NM002
#######
RdI_NM002 <- CreateSeuratObject(
counts = NM002_RdI.data,
min.cells = 3,
min.features = 200,
project = "NM002_RdI"
)
RdII_NM002 <- CreateSeuratObject(
counts = NM002_RdII.data,
min.cells = 3,
min.features = 200,
project = "NM002_RdII"
)
RdI_NM002$Arm <- "NM002"
RdI_NM002 <- RenameCells(
object = RdI_NM002,
new.names = paste0("NM002_I_", colnames(x = RdI_NM002))
)
RdII_NM002$Arm <- "NM002"
RdII_NM002 <- RenameCells(
object = RdII_NM002,
new.names = paste0("NM002_II_", colnames(x = RdII_NM002))
)
# Cell Filtering QC
# RdI
RdI_NM002$percent.mt <- PercentageFeatureSet(RdI_NM002, pattern = "^MT-")
RdI_NM002[["percent.hg19"]] <- PercentageFeatureSet(RdI_NM002, pattern = "^hg19-")
RdI_NM002[["percent.mm10"]] <- PercentageFeatureSet(RdI_NM002, pattern = "^mm10-")
pdf(
file = "01_output/RdI_NM002_prefilterQC.pdf"
)
VlnPlot(RdI_NM002, features = c("percent.hg19", "percent.mm10"))
FeatureScatter(object = RdI_NM002, feature1 = "nCount_RNA", feature2 = "percent.mt")
FeatureScatter(object = RdI_NM002, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
dev.off()
# RdII
RdII_NM002$percent.mt <- PercentageFeatureSet(RdII_NM002, pattern = "^MT-")
RdII_NM002[["percent.hg19"]] <- PercentageFeatureSet(RdII_NM002, pattern = "^hg19-")
RdII_NM002[["percent.mm10"]] <- PercentageFeatureSet(RdII_NM002, pattern = "^mm10-")
pdf(
file = "01_output/RdII_NM002_prefilterQC.pdf"
)
VlnPlot(RdII_NM002, features = c("percent.hg19", "percent.mm10"))
FeatureScatter(object = RdII_NM002, feature1 = "nCount_RNA", feature2 = "percent.mt")
FeatureScatter(object = RdII_NM002, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
dev.off()
################################################################################
################################################################################
################################################################################
## INTEGRATION
################################################################################
################################################################################
################################################################################
CellTagGBM.list <- c(RdI_DMSO, RdII_DMSO, RdI_NM002, RdII_NM002)
# And uniformly filter all datasets...
for (i in 1:length(CellTagGBM.list)) {
CellTagGBM.list[[i]] <- subset(x = CellTagGBM.list[[i]],
subset = nFeature_RNA > 200 & nFeature_RNA < 6000 & percent.mt < 5)
}
# Run scTransform on all objects...
for (i in 1:length(CellTagGBM.list)) {
CellTagGBM.list[[i]] <- SCTransform(CellTagGBM.list[[i]], verbose = TRUE)
}
# Next, select features for downstream integration, and run PrepSCTIntegration,
# which ensures that all necessary Pearson residuals have been calculated.
obj.features <- SelectIntegrationFeatures(
object.list = CellTagGBM.list,
nfeatures = 3000
)
CellTagGBM.list <- PrepSCTIntegration(
object.list = CellTagGBM.list,
anchor.features = obj.features,
verbose = TRUE)
# Next, identify anchors and integrate the datasets. Commands are identical to
# the standard workflow, but make sure to set normalization.method = "SCT":
obj.anchors <- FindIntegrationAnchors(
object.list = CellTagGBM.list,
normalization.method = "SCT",
anchor.features = obj.features,
verbose = TRUE
)
to_integrate <- Reduce(intersect, lapply([email protected], rownames))
print("Preview of genes to integrate... ")
head(to_integrate)
obj <- IntegrateData(
anchorset = obj.anchors,
# features.to.integrate = to_integrate,
normalization.method = "SCT",
verbose = TRUE
)
rm(obj.anchors)
rm(obj.features)
rm(CellTagGBM.list)
rm(to_integrate)
saveRDS(obj, file = "01_output/CellTagInt.RDS")
obj1 <- readRDS(file = "01_output/CellTagInt.RDS")
dim(obj1)
table(obj1$Arm)
rm(obj1)
# Now proceed with downstream analysis (i.e. visualization, clustering) on the
# integrated dataset. Commands are identical to the standard workflow, but do
# not run the ScaleData function after integration. This should have helped to
# remove any variation caused by technical batch effect.
################################################################################
################################################################################
################################################################################
obj <- RunPCA(obj, verbose = FALSE)
pdf(
file = "01_output/CellTagInt_ElbowPlot.pdf"
)
ElbowPlot(obj)
dev.off()
obj <- FindNeighbors(obj, dims = 1:15)
obj <- FindClusters(obj, dims = 1:15)
obj <- RunUMAP(
obj,
dims = 1:15,
min.dist = 0.5,
n_neighbors = 30,
umap.method = "uwot",
metric = "correlation",
assay = "SCT"
)
pdf(
file = "01_output/CellTagIntUMAP.pdf"
)
DimPlot(obj, group.by = c("Arm"), cols = c("azure4", "chartreuse3"))#, combine = FALSE)
DimPlot(obj, group.by = "ident", label = TRUE)#, combine = FALSE)
FeaturePlot(obj, features = "percent.hg19", cols = viridis(100, option = "D"))
FeaturePlot(obj, features = "percent.mm10", cols = viridis(100, option = "D"))
dev.off()
saveRDS(obj, file = "01_output/CellTagInt_Barnyard_UMAP.Rds")
################################################################################
# Generate supplemental figure showing seperation of pdx and mouse cells.
saveRDS(obj, file = "01_output/barnyardObj.RDS")
snnUMAP <- as.ggplot(DimPlot(obj, group.by = "ident", label = TRUE, cols = DiscretePalette(20, palette = "alphabet2"), pt.size = 0.01))
hg19UMAP <- as.ggplot(FeaturePlot(obj, features = "percent.hg19", cols = viridis(100, option = "D"), pt.size = 0.01))# + ggtitle(label = "Percent alignment to hg19"))
mm10UMAP <- as.ggplot(FeaturePlot(obj, features = "percent.mm10", cols = viridis(100, option = "D"), pt.size = 0.01))# + ggtitle(label = "Percent alignment to mm10"))
armUMAP <- as.ggplot(DimPlot(obj, group.by = "Arm", label = F, cols = c("Azure4", "Chartreuse"), pt.size = 0.001, shuffle = TRUE))
sample10xUMAP <- as.ggplot(DimPlot(obj, group.by = "orig.ident", label = F, cols = c("yellow", "blue", "red", "violet"), pt.size = 0.01, shuffle = TRUE))
# pl <- as.ggplot(DimPlot(obj, group.by = "orig.ident", label = F, cols = DiscretePalette(2, "alphabet"), pt.size = 0.05))
sample10xUMAP
# Add PieChart of proportions of cells from each treatment arm.
armdf <- as.data.frame(table(int$Arm))
armdf$perc <- armdf$Freq / sum(armdf$Freq) * 100
armtab <- armdf$perc
names(armtab) <- armdf$Var1
lbls <- lbls <- paste(names(armtab), "\n", armtab, sep = "")
pdf(file = "01_output/arm_proportionPie.pdf")
pie3D(armtab, explode = 0.1, labels = lbls, main="Treatment", start = 2, col = c("lightgrey", "chartreuse"))
dev.off()
dev.off()
pdf(file = "01_output/mm10_hg19_seperation.pdf", width = 14, height = 14)
plot_grid(plotlist = list(armUMAP,
sample10xUMAP,
hg19UMAP,
mm10UMAP
), ncol = 2, labels = "AUTO")
dev.off()
################################################################################
################################################################################
################################################################################
print("Pipeline successfully completed...")
################################################################################
################################################################################
################################################################################