forked from winstonbecker/scColonHuBMAP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3d_scRNA_duodenum.R
More file actions
248 lines (216 loc) · 14 KB
/
3d_scRNA_duodenum.R
File metadata and controls
248 lines (216 loc) · 14 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
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
# Script to analyze stromal scRNA cells from ENCODE colon data
# WRB 2022
# Import libraries
library(dplyr)
library(Seurat)
library(ggplot2)
library(RColorBrewer)
library(patchwork)
library(ArchR)
library(viridis)
library(DoubletFinder)
library(Rcpp)
library(harmony)
library(future)
library(Matrix)
library(wesanderson)
library(MAST)
library(ggpubr)
library(harmony)
library(SingleR)
library(celldex)
set.seed(1)
# Define variables
parent_directory <- "/hubmap_single_cell/" #folder for the project
sample_name <- "all_samples" # used as label for saving plots
analysis_parent_folder <- paste0(parent_folder, "scRNA_reproduce/epithelial/duodenum/decontx_sctransform_cca/") # folder for this analysis
setwd(analysis_parent_folder)
# load helper functions
source(paste0(parent_folder, "scRNA_reproduce/scripts/single_cell_rna_helper_functions.R"))
###############################################################################################################################
###############################################################################################################################
# load the seurat object with only the duodenum data
duodenum <- readRDS(paste0(parent_folder, "scRNA_reproduce/all_cells/decontx_norm_scale_harmony/duodenum_epithelial_samples_initial.rds"))
sample_name <- "duodenum"
# Markers from Regev Lab paper
RNA_markers_epithelial <- read.csv(file = paste0(parent_folder, "RegevLabMarkers/S2_Regev_Cell_epithelial.csv"))
RNA_markers_immune <- read.csv(file = paste0(parent_folder, "RegevLabMarkers/S2_Regev_Cell_immune.csv"))
RNA_markers_stromal <- read.csv(file = paste0(parent_folder, "RegevLabMarkers/S2_Regev_Cell_stromal.csv"))
RNA_markers <- rbind(RNA_markers_epithelial, RNA_markers_immune, RNA_markers_stromal)
##############################################################################################################################
#............................................................................................................................#
##############################################################################################################################
# Make sure pecent ribo present
duodenum[["percent.ribo"]] <- PercentageFeatureSet(duodenum, pattern = "^RP[SL]")
# split into different objects for each sample and run sctransform
rna.list <- SplitObject(object = duodenum , split.by = "orig.ident")
for (i in names(rna.list)){
rna.list[[i]] <- SCTransform(rna.list[[i]], assay = "decontXcounts", method = "glmGamPoi", vars.to.regress = c("percent.mt", "percent.ribo"), verbose = TRUE)
}
# Integrate the datasets
features <- SelectIntegrationFeatures(object.list = rna.list, nfeatures = 3000)
rna.list <- PrepSCTIntegration(object.list = rna.list, anchor.features = features)
rna.list <- lapply(X = rna.list, FUN = RunPCA, features = features)
rna.anchors <- FindIntegrationAnchors(object.list = rna.list, normalization.method = "SCT",
anchor.features = features, dims = 1:30, reference = c(1,3,8)) #reduction = "rpca", k.anchor = 20,
rna.combined.sct <- IntegrateData(anchorset = rna.anchors, normalization.method = "SCT", dims = 1:30)
# Run PCA and make UMAP
rna.combined.sct <- RunPCA(rna.combined.sct, verbose = TRUE)
rna.combined.sct <- RunUMAP(rna.combined.sct, reduction = "pca", dims = 1:30)
plotUMAP(rna.combined.sct, reduction = "umap", save_name = "rna_combined_sct_ref1_15")
# Cluster
DefaultAssay(rna.combined.sct) <- "integrated"
set.seed(1)
rna.combined.sct <- FindNeighbors(rna.combined.sct, reduction = "pca", dims = 1:30)
rna.combined.sct <- FindClusters(rna.combined.sct, resolution = 2.0)
plotUMAP(rna.combined.sct, reduction = "umap", save_name = "rna_combined_sct_ref1_new_clust")
# Plot markers by RNA expression
DefaultAssay(rna.combined.sct) <- "RNA"
reductions_to_plot <- c("umap")
for (reduction in reductions_to_plot){
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Enterocytes", c("CA1", "RAB6B"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "EnterocytesIleum", c("MEP1A", "FGF19", "CLEC2H", "MPTX2"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Enterocytes2", c("ELF3", "GADD45GIP1", "HNF1A", "HNF1B"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Enterocytes3", c("SI", "FABP2", "ANPEP", "PRAP1", "RBP2"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Colonocytes", c("CA2", "SLC26A2", "FABP1"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "CyclingTA", c("TICRR","CDC25C","SAPCD2","MT3","LINC00669","SERPINA6"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "ImmatureEnterocytes", c("SLC26A2","CA1", "KIAA1239","GLRA4","CELA3A","CELA3B","C8G"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Mcells", c("SOX8","NTRK2","CCL23","CCL20","CTSE","SLC2A6","TNFAIP2","POLD1","GJB3","KCNE2","TNFRSF11A","AKR1C2","SPINK5","ATP11B","NOXO1","SDC4"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Tuft", c("GNG13","SH2D7","SH2D6","TRPM5","AZGP1","KRT18","BMX","PSTPIP2","LRMP","PTGS1","IL17RB","HCK","PLCG2","ANXA13"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Best4posEnterocytes", c("BEST4", "CA7","OTOP2","OTOP3", "MYOM1","MT1G","MT1H"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "General_Epithelial", c("EPCAM", "KRT8","KRT18"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Immature_Goblet", c("KLK1","ITLN1","WFDC2","CLCA1","LRRC26","RETNLB","SPINK4","AGR2"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Goblet", c("MUC2", "TFF1", "FCGBP","FFAR4","SYTL2","LGALS9B","BCAS1"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Stem", c("SMOC2", "RGMB", "LGR5", "ASCL2", "SOX9", "CD34", "BMI1"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Enteroendocrine", c("CRYBA2","SCGN","FEV","CHGA","GCG","SCG5","PCSK1N","PYY","NEUROD1","MS4A8","DDC"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Paneth", c("LYZ", "DEFA5", "DEFA6", "REG3A", "PRSS2", "PLA2G2A", "ITLN2", "GUCA2A", "TFF3", "IFI6"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "M cells", c("GP2", "KRT7", "NTRK2","CCL23","CCL20","POLD1","GJB3","KCNE2","RNF207","TNFRSF11A","AKR1C2","SPINK5","NOXO1"))
seurat_feature_plot(rna.combined.sct, sample_name, reduction, "Other cells", c("CD3", "CD4", "CD8", "CD14", "MS4A4", "PLVAP", "VWF"))
}
# Examine marker expression
duodenum.markers <- FindAllMarkers(rna.combined.sct, only.pos = TRUE, min.pct = 0.2, logfc.threshold = 0.25, max.cells.per.ident = 250)
RNA_markers_spec <- RNA_markers[RNA_markers$either,]
RNA_markers_spec[RNA_markers_spec$gene %in% duodenum.markers[duodenum.markers$cluster == 9,]$gene,"ident"]
# Plot percent mitochondrial and percent ribosomal RNA
pdf(paste0("./UMAP_pMT.pdf"), width = 12, onefile=F)
print(FeaturePlot(rna.combined.sct, reduction = "umap", features = "percent.mt"))#, cols = (ArchRPalettes$stallion))
dev.off()
pdf(paste0("./UMAP_pRIBO.pdf"), width = 12, onefile=F)
print(FeaturePlot(rna.combined.sct, reduction = "umap", features = "percent.ribo"))#, cols = (ArchRPalettes$stallion))
dev.off()
# Remove two clusters and redo PCA, UMAP, and clustering
# remove 26 based on CD96 expression
# remove 9 based on maily mitochondrial marker genes and high ribosomal RNA expression
DefaultAssay(rna.combined.sct) <- "integrated"
bad_clusters <- c(9,26)
set.seed(1)
# Subset
rna.combined.sct.new <- subset(rna.combined.sct, subset = seurat_clusters %ni% bad_clusters)
rna.combined.sct.new <- RunPCA(rna.combined.sct.new, verbose = TRUE)
rna.combined.sct.new <- RunUMAP(rna.combined.sct.new, reduction = "pca", dims = 1:30)
plotUMAP(rna.combined.sct.new, reduction = "umap", save_name = "rna_combined_sct_post_filter1")
set.seed(1)
rna.combined.sct.new <- FindNeighbors(rna.combined.sct.new, reduction = "pca", dims = 1:30)
rna.combined.sct.new <- FindClusters(rna.combined.sct.new, resolution = 2.0)
plotUMAP(rna.combined.sct.new, reduction = "umap", save_name = "rna_combined_sct_ref1_new_clust_post_filter1")
DefaultAssay(rna.combined.sct.new) <- "decontXcounts"
reductions_to_plot <- c("umap")
for (reduction in reductions_to_plot){
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "SpecialGoblet", c("MUC6", "MUC5B"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Nerve", c("MAP2", "RBFOX3", "DLG4", "SYP"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Cholangiocytes", c("GGT1", "SPP1", "KRT7", "KRT19", "KRT18", "SCTR", "CFTR"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "EnterocytesDuodenum", c("TMPRSS15"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "CyclingTA", c("TICRR","CDC25C","SAPCD2","MT3","LINC00669","SERPINA6"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "ImmatureEnterocytes", c("SLC26A2","CA1", "KIAA1239","GLRA4","CELA3A","CELA3B","C8G"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Mcells", c("SOX8","NTRK2","CCL23","CCL20","CTSE","SLC2A6","TNFAIP2","POLD1","GJB3","KCNE2","TNFRSF11A","AKR1C2","SPINK5","ATP11B","NOXO1","SDC4"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Tuft", c("GNG13","SH2D7","SH2D6","TRPM5","AZGP1","KRT18","BMX","PSTPIP2","LRMP","PTGS1","IL17RB","HCK","PLCG2","ANXA13"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Enterocytes", c("CA1", "RAB6B"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "EnterocytesIleum", c("MEP1A", "FGF19", "CLEC2H", "MPTX2"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Enterocytes2", c("ELF3", "GADD45GIP1", "HNF1A", "HNF1B"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Enterocytes3", c("SI", "FABP2", "ANPEP", "PRAP1", "RBP2"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Colonocytes", c("CA2", "SLC26A2", "FABP1"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Best4posEnterocytes", c("BEST4", "CA7","OTOP2","OTOP3", "MYOM1","MT1G","MT1H"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "General_Epithelial", c("EPCAM", "KRT8","KRT18"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Immature_Goblet", c("KLK1","ITLN1","WFDC2","CLCA1","LRRC26","RETNLB","SPINK4","AGR2"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Goblet", c("MUC2", "TFF1", "FCGBP","FFAR4","SYTL2","LGALS9B","BCAS1"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Stem", c("SMOC2", "RGMB", "LGR5", "ASCL2", "SOX9", "CD34", "BMI1"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Enteroendocrine", c("CRYBA2","SCGN","FEV","CHGA","GCG","SCG5","PCSK1N","PYY","NEUROD1","MS4A8","DDC"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Paneth", c("LYZ", "DEFA5", "DEFA6", "REG3A", "PRSS2", "PLA2G2A", "ITLN2", "GUCA2A", "TFF3", "IFI6"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "M cells", c("GP2", "KRT7", "NTRK2","CCL23","CCL20","POLD1","GJB3","KCNE2","RNF207","TNFRSF11A","AKR1C2","SPINK5","NOXO1"))
seurat_feature_plot(rna.combined.sct.new, sample_name, reduction, "Other cells", c("CD3", "CD4", "CD8", "CD14", "MS4A4", "PLVAP", "VWF"))
}
rna.combined.sct.markers <- FindAllMarkers(rna.combined.sct.new, only.pos = TRUE, min.pct = 0.2, logfc.threshold = 0.25, max.cells.per.ident = 250)
RNA_markers_spec <- RNA_markers[RNA_markers$either,]
RNA_markers_spec[RNA_markers_spec$gene %in% rna.combined.sct.markers[rna.combined.sct.markers$cluster == 1,]$gene,"ident"]
pdf(paste0("./UMAP_pMT.pdf"), width = 12, onefile=F)
print(FeaturePlot(rna.combined.sct.new, reduction = "umap", features = "percent.mt"))#, cols = (ArchRPalettes$stallion))
dev.off()
pdf(paste0("./UMAP_pRIBO.pdf"), width = 12, onefile=F)
print(FeaturePlot(rna.combined.sct.new, reduction = "umap", features = "percent.ribo"))#, cols = (ArchRPalettes$stallion))
dev.off()
DefaultAssay(rna.combined.sct.new) <- "integrated"
new.cluster.ids <- c("Immature Enterocytes",
"TA2",
"TA1",
"Immature Enterocytes",
"Immature Enterocytes", #4
"Epithelial",
"Immature Enterocytes",
"Enterocytes",
"Enterocytes",
"Immature Enterocytes", #9
"CyclingTA 1",
"Immature Enterocytes",#11
"TA2",
"Epithelial",
"Immature Enterocytes",
"Secretory Specialized MUC6+",
"Goblet",
"Enterocytes",
"Secretory Specialized MUC6+",
"Stem",
"Best4+ Enterocytes",
"Immature Enterocytes", #21
"Epithelial", #22
"Enteroendocrine",
"Epithelial",
"Immature Goblet",
"Enteroendocrine",
"Paneth",
"TA2",
"Tuft",
"Unknown")#30
# Set the cell types in the project
identities <- data.frame(rna.combined.sct.new[['seurat_clusters']])
identities$seurat_clusters <- as.character(rna.combined.sct.new[['seurat_clusters']]$seurat_clusters)
for (i in 0:(length(new.cluster.ids)-1)){
identities[identities$seurat_clusters==as.character(i),] <- new.cluster.ids[i+1]
}
rna.combined.sct.new <- AddMetaData(rna.combined.sct.new, identities$seurat_clusters, col.name = "CellType")
pal <- c("#371377")
names(pal) <- "Best4+ Enterocytes"
pal["CyclingTA 1"] <- "grey35"
#pal["CyclingTA 2"] <- "#cccccc"
pal["Enterocytes"] <- "#9E0142"
pal["Enteroendocrine"] <- "#FF0080"
#pal["Enteroendocrine2"] <- "#F59899"
#pal["Enteroendocrine3"] <- "#E11E26"
pal["Epithelial"] <- "#238B45"
pal["Goblet"] <- "#DC494C"
pal["Immature Enterocytes"] <- "#7700FF"
pal["Immature Goblet"] <- "#FAD510"
pal["Paneth"] <- "#F88D51"
#pal["Secretory TA"] <- "#88CFA4"
pal["Secretory Specialized MUC6+"] <- "#88CCEE"
#pal["Secretory Unknown 2"] <- "#2a7185"
pal["Stem"] <- "#02401B"
pal["TA1"] <- "#079290"
pal["TA2"] <- "#A2A475"
pal["Tuft"] <- "#0AD7D3"
pal["Unknown"] <- "#046C9A"
# plot
pdf(paste0("./UMAP_cell_type_id.pdf"), width = 6, onefile = FALSE)
DimPlot(rna.combined.sct.new, group.by = "CellType", reduction = "umap", cols = pal) + theme_ArchR()
dev.off()
DefaultAssay(rna.combined.sct.new) <- "integrated"
saveRDS(rna.combined.sct.new, file = "duodenum_clustered.rds")