-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#_Cachexia_DR_Without_Batch_Correction.R
208 lines (177 loc) · 11.3 KB
/
#_Cachexia_DR_Without_Batch_Correction.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
## 00_Cachexia_Dimension_Reduction_Without_Batch_Correction.R
##### Version information ######
# _
# platform x86_64-w64-mingw32
# arch x86_64
# os mingw32
# system x86_64, mingw32
# status
# major 4
# minor 1.1
# year 2021
# month 08
# day 10
# svn rev 80725
# language R
# version.string R version 4.1.1 (2021-08-10)
# nickname Kick Things
##### Presetting ######
rm(list = ls()) # Clean variable
memory.limit(150000)
##### Current path and new folder setting #####
Version = "20220225_BatchEffect"
Save.Path = paste0(getwd(),"/",Version)
dir.create(Save.Path)
##### Load Packages #####
library(Seurat)
library(ggplot2)
library("dplyr")
##### Function setting #####
## Call function
source("FUN_Beautify_ggplot.R")
#####-------------- SC --------------#####
##### Load datasets #####
SC.data.TN136 <- Read10X(data.dir = paste0(getwd(),"/TN136/monocle/outs/filtered_gene_bc_matrices/mm10"))
SC.TN136 <- CreateSeuratObject(counts = SC.data.TN136, project = "EO.M", min.cells = 3, min.features = 200)
SC.TN136
[email protected][["sample"]] <- rep(c("EO.M"), times=length([email protected][["orig.ident"]]))
[email protected][["ID"]] <- rep(c("TN136"), times=length([email protected][["orig.ident"]]))
[email protected][["Cachexia"]] <- rep(c("EO"), times=length([email protected][["orig.ident"]])) #EO: Early_Onset
[email protected][["Sex"]] <- rep(c("Male"), times=length([email protected][["orig.ident"]]))
SC.data.TN137 <- Read10X(data.dir = paste0(getwd(),"/TN137/monocle/outs/filtered_gene_bc_matrices/mm10"))
SC.TN137 <- CreateSeuratObject(counts = SC.data.TN137, project = "LO.M", min.cells = 3, min.features = 200)
SC.TN137
[email protected][["sample"]] <- rep(c("LO.M"), times=length([email protected][["orig.ident"]]))
[email protected][["ID"]] <- rep(c("TN137"), times=length([email protected][["orig.ident"]]))
[email protected][["Cachexia"]] <- rep(c("LO"), times=length([email protected][["orig.ident"]])) #LO: Late_Onset
[email protected][["Sex"]] <- rep(c("Male"), times=length([email protected][["orig.ident"]]))
SC.data.TN145 <- Read10X(data.dir = paste0(getwd(),"/TN145/monocle/outs/filtered_gene_bc_matrices/mm10"))
SC.TN145 <- CreateSeuratObject(counts = SC.data.TN145, project = "LO.F", min.cells = 3, min.features = 200)
SC.TN145
[email protected][["sample"]] <- rep(c("LO.F"), times=length([email protected][["orig.ident"]]))
[email protected][["ID"]] <- rep(c("TN145"), times=length([email protected][["orig.ident"]]))
[email protected][["Cachexia"]] <- rep(c("LO"), times=length([email protected][["orig.ident"]]))
[email protected][["Sex"]] <- rep(c("Female"), times=length([email protected][["orig.ident"]]))
SC.data.TN147 <- Read10X(data.dir = paste0(getwd(),"/TN147/monocle/outs/filtered_gene_bc_matrices/mm10"))
SC.TN147 <- CreateSeuratObject(counts = SC.data.TN147, project = "EO.F", min.cells = 3, min.features = 200)
SC.TN147
[email protected][["sample"]] <- rep(c("EO.F"), times=length([email protected][["orig.ident"]]))
[email protected][["ID"]] <- rep(c("TN147"), times=length([email protected][["orig.ident"]]))
[email protected][["Cachexia"]] <- rep(c("EO"), times=length([email protected][["orig.ident"]]))
[email protected][["Sex"]] <- rep(c("Female"), times=length([email protected][["orig.ident"]]))
##### Merging More Than Two Seurat Objects #####
## Merging More Than Two Seurat Objects
## https://satijalab.org/seurat/articles/merge_vignette.html
SC.combined <- merge(SC.TN136, y = c(SC.TN137, SC.TN145, SC.TN147),
add.cell.ids = c("TN136", "TN137", "TN145","TN147"),
project = "SC")
SC.combined
# ##### Perform integration #####
# # this command creates an 'integrated' data assay
# SC.combined <- IntegrateData(anchorset = SC.combined)
# # specify that we will perform downstream analysis on the corrected data note that the
# # original unmodified data still resides in the 'RNA' assay
# DefaultAssay(SC.combined) <- "integrated"
## Perform an integrated analysis
# https://satijalab.org/seurat/articles/integration_introduction.html
##
# Run the standard workflow for visualization and clustering
set.seed(1) # Fix the seed
SC.combined <- ScaleData(SC.combined, verbose = FALSE)
# RunPCA error
# https://github.com/satijalab/seurat/issues/1788
set.seed(1) # Fix the seed
SC.combined <- FindVariableFeatures(object = SC.combined)
set.seed(1) # Fix the seed
SC.combined <- RunPCA(SC.combined, npcs = 30, verbose = FALSE)
set.seed(1) # Fix the seed
SC.combined <- RunUMAP(SC.combined, reduction = "pca", dims = 1:30)
set.seed(1) # Fix the seed
SC.combined <- FindNeighbors(SC.combined, reduction = "pca", dims = 1:30)
set.seed(1) # Fix the seed
SC.combined <- FindClusters(SC.combined, resolution = 0.5)
# Visualization
p1 <- DimPlot(SC.combined, reduction = "umap", group.by = "sample")
p2 <- DimPlot(SC.combined, reduction = "umap", label = TRUE, repel = TRUE)
p1 + p2
DimPlot(SC.combined, reduction = "umap", group.by = "sample") %>% BeautifyggPlot(.,LegPos = c(0.85, 0.15),AxisTitleSize=1.1)
#####-------------- PBMC --------------#####
##### Load datasets #####
PBMC.data.TN138 <- Read10X(data.dir = paste0(getwd(),"/TN138/monocle/outs/filtered_gene_bc_matrices/mm10"))
PBMC.TN138 <- CreateSeuratObject(counts = PBMC.data.TN138, project = "EO.M", min.cells = 3, min.features = 200)
PBMC.TN138
[email protected][["sample"]] <- rep(c("EO.M"), times=length([email protected][["orig.ident"]]))
[email protected][["ID"]] <- rep(c("TN138"), times=length([email protected][["orig.ident"]]))
[email protected][["Cachexia"]] <- rep(c("EO"), times=length([email protected][["orig.ident"]])) #EO: Early_Onset
[email protected][["Sex"]] <- rep(c("Male"), times=length([email protected][["orig.ident"]]))
PBMC.data.TN139 <- Read10X(data.dir = paste0(getwd(),"/TN139/monocle/outs/filtered_gene_bc_matrices/mm10"))
PBMC.TN139 <- CreateSeuratObject(counts = PBMC.data.TN139, project = "LO.M", min.cells = 3, min.features = 200)
PBMC.TN139
[email protected][["sample"]] <- rep(c("LO.M"), times=length([email protected][["orig.ident"]]))
[email protected][["ID"]] <- rep(c("TN139"), times=length([email protected][["orig.ident"]]))
[email protected][["Cachexia"]] <- rep(c("LO"), times=length([email protected][["orig.ident"]])) #LO: Late_Onset
[email protected][["Sex"]] <- rep(c("Male"), times=length([email protected][["orig.ident"]]))
PBMC.data.TN146 <- Read10X(data.dir = paste0(getwd(),"/TN146/monocle/outs/filtered_gene_bc_matrices/mm10"))
PBMC.TN146 <- CreateSeuratObject(counts = PBMC.data.TN146, project = "LO.F", min.cells = 3, min.features = 200)
PBMC.TN146
[email protected][["sample"]] <- rep(c("LO.F"), times=length([email protected][["orig.ident"]]))
[email protected][["ID"]] <- rep(c("TN146"), times=length([email protected][["orig.ident"]]))
[email protected][["Cachexia"]] <- rep(c("LO"), times=length([email protected][["orig.ident"]]))
[email protected][["Sex"]] <- rep(c("Female"), times=length([email protected][["orig.ident"]]))
PBMC.data.TN148 <- Read10X(data.dir = paste0(getwd(),"/TN148/monocle/outs/filtered_gene_bc_matrices/mm10"))
PBMC.TN148 <- CreateSeuratObject(counts = PBMC.data.TN148, project = "EO.F", min.cells = 3, min.features = 200)
PBMC.TN148
[email protected][["sample"]] <- rep(c("EO.F"), times=length([email protected][["orig.ident"]]))
[email protected][["ID"]] <- rep(c("TN148"), times=length([email protected][["orig.ident"]]))
[email protected][["Cachexia"]] <- rep(c("EO"), times=length([email protected][["orig.ident"]]))
[email protected][["Sex"]] <- rep(c("Female"), times=length([email protected][["orig.ident"]]))
##### Merging More Than Two Seurat Objects #####
## Merging More Than Two Seurat Objects
## https://satijalab.org/seurat/articles/merge_vignette.html
PBMC.combined <- merge(PBMC.TN138, y = c(PBMC.TN139, PBMC.TN146, PBMC.TN148),
add.cell.ids = c("TN138", "TN139", "TN146","TN148"),
project = "SC")
PBMC.combined
# ##### Perform integration #####
# # this command creates an 'integrated' data assay
# PBMC.combined <- IntegrateData(anchorset = PBMC.combined)
# # specify that we will perform downstream analysis on the corrected data note that the
# # original unmodified data still resides in the 'RNA' assay
# DefaultAssay(PBMC.combined) <- "integrated"
## Perform an integrated analysis
# https://satijalab.org/seurat/articles/integration_introduction.html
##
# Run the standard workflow for visualization and clustering
set.seed(1) # Fix the seed
PBMC.combined <- ScaleData(PBMC.combined, verbose = FALSE)
# RunPCA error
# https://github.com/satijalab/seurat/issues/1788
set.seed(1) # Fix the seed
PBMC.combined <- FindVariableFeatures(object = PBMC.combined)
set.seed(1) # Fix the seed
PBMC.combined <- RunPCA(PBMC.combined, npcs = 30, verbose = FALSE)
set.seed(1) # Fix the seed
PBMC.combined <- RunUMAP(PBMC.combined, reduction = "pca", dims = 1:30)
set.seed(1) # Fix the seed
PBMC.combined <- FindNeighbors(PBMC.combined, reduction = "pca", dims = 1:30)
set.seed(1) # Fix the seed
PBMC.combined <- FindClusters(PBMC.combined, resolution = 0.5)
# Visualization
p1 <- DimPlot(PBMC.combined, reduction = "umap", group.by = "sample")
p2 <- DimPlot(PBMC.combined, reduction = "umap", label = TRUE, repel = TRUE)
p1 + p2
DimPlot(PBMC.combined, reduction = "umap", group.by = "sample") %>% BeautifyggPlot(.,LegPos = c(0.85, 0.15),AxisTitleSize=1.1)
##### Export PDF #####
pdf(
file = paste0(setwd(getwd()),"/",Version,"/nlDR_Without_Batch_Correction.pdf"),
width = 10, height = 8
)
DimPlot(PBMC.combined, reduction = "umap", group.by = "sample") %>% BeautifyggPlot(.,LegPos = c(0.80, 0.15),AxisTitleSize=1.1)
DimPlot(SC.combined, reduction = "umap", group.by = "sample") %>% BeautifyggPlot(.,LegPos = c(0.80, 0.15),AxisTitleSize=1.1)
DimPlot(PBMC.combined, reduction = "umap", group.by = "sample") %>%
BeautifyggPlot(.,TV= -5,TitleSize = 25,LegPos = c(0.85, 0.15),AxisTitleSize=1.2, LegTextSize = 18)
DimPlot(SC.combined, reduction = "umap", group.by = "sample") %>%
BeautifyggPlot(.,TV= -5,TitleSize = 25,LegPos = c(0.85, 0.15),AxisTitleSize=1.2, LegTextSize = 18)
dev.off()
#####
save.image(paste0(Save.Path,"/00_Cachexia_Dimension_Reduction_Without_Batch_Correction.RData"))