-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
512 lines (512 loc) · 22.3 KB
/
.Rhistory
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
saveRDS(seu, file.path(ROOT_DIR3, "240926_5p_seu.RDS"))
DimPlot_scCustom(seu, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Query - aka Projectee Dataset")
DimPlot_scCustom(seur, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Reference - aka Projector Dataset")
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff() %>%
filter(pct_diff > 0.6)
idents(seur) <- seur$celltype
Idents(seur) <- seur$celltype
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff() %>%
filter(pct_diff > 0.6)
pct_diff
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff()
all_markers
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff() %>%
all_markers %>% filter(pct_diff > 0.6)
all_markers
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff() %>%
all_markers %>% filter(pct_diff > 0.6)
library(tidyr)
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff() %>%
all_markers %>% filter(pct_diff > 0.6)
all_markers %>% filter(pct_diff > 0.6)
all_markers
all_markers[all_markers$pct_diff > 0.6,]
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff() %>% dplyr::filter(pct_diff > 0.6)
all_markers
top_markers <- Extract_Top_Markers(marker_dataframe = all_markers, num_genes = 5, named_vector = FALSE,
make_unique = TRUE)
Clustered_DotPlot(seurat_object = seur, features = top_markers)
Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1)
seur <- seur[,!seur$celltype %in% c("Basophils", "Neutrophils")]
saveRDS(seur, file.path(ROOT_DIR1, "240926_final_object.RDS"))
seur <- readRDS(file.path(ROOT_DIR1, "240926_final_object.RDS"))
# Make some colors
cols1 <- as.character(pals::polychrome()[c(1,3:20)])
names(cols1) <- levels(factor(seur$celltype))
cols1
# Make some colors
cols1 <- as.character(pals::polychrome()[c(1,3:13)])
names(cols1) <- levels(factor(seur$celltype))
cols1
cols2 <- c("00_PROJECTOR"="grey90", cols1)
cols2
DimPlot_scCustom(seur, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Reference - aka Projector Dataset")
Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1)
Idents(seur) <- seur$celltype
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff() %>% dplyr::filter(pct_diff > 0.6)
top_markers <- Extract_Top_Markers(marker_dataframe = all_markers, num_genes = 5, named_vector = FALSE,
make_unique = TRUE)
Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1)
Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1, k=12)
Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1, k=11)
Idents(seu) <- seur$celltype
Idents(seu) <- seu$celltype
all_markers <- FindAllMarkers(object = seu) %>%
Add_Pct_Diff() %>% dplyr::filter(pct_diff > 0.6)
seu <- seu[,!seu$celltype %in% c("Basophils", "Neutrophils")]
saveRDS(seu, file.path(ROOT_DIR3, "240926_5p_seu.RDS"))
seu <-readRDS(file.path(ROOT_DIR3, "240926_5p_seu.RDS"))
DimPlot_scCustom(seu, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Query - aka Projectee Dataset")
Idents(seu) <- seu$celltype
all_markers <- FindAllMarkers(object = seu) %>%
Add_Pct_Diff() %>% dplyr::filter(pct_diff > 0.6)
top_markers <- Extract_Top_Markers(marker_dataframe = all_markers, num_genes = 5, named_vector = FALSE,
make_unique = TRUE)
Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1, k=11)
# Calculate and plot gene dispersion in query dataset
seu <- calculate_gene_dispersion(seu)
seu <- select_genes(seu, top_n = 10000, logmean_ul = -1, logmean_ll = -8)
plot_gene_dispersion(seu)
vgq <- get_selected_genes(seu)
# Repeat the process for the reference dataset
seur <- calculate_gene_dispersion(seur)
seur <- select_genes(seur, top_n = 10000, logmean_ul = -1, logmean_ll = -8)
plot_gene_dispersion(seur)
vgr <- get_selected_genes(seur)
# Find common genes
vg <- intersect(vgq, vgr)
#iterative LSI
comps <- 25 #Number of PCs for clustering
seur<-iterative_LSI(seur, num_dim = comps, num_features = length(vg), resolution = c(1e-3), verbose = T, starting_features = vg, run_umap = T)
p1 <- DimPlot(seur, group.by = "celltype", cols = cols1)+theme_void()
p1
res <- project_data(projector = seur, projectee = seu, reduced_dim = "lsi", embedding = "umap")
p2 <- plot_projection(res, seur, seu, projectee_col = "celltype")+scale_color_manual(values = cols2)+theme_void()+ guides(color = guide_legend(override.aes = list(size = 3)))
p2
cowplot::plot_grid(p1, p2)
cp <- Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1, k=11)
cp <- Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1, k=11, plot_km_elbow = F)
Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1, k=11, plot_km_elbow = F)
knitr: :opts_chunk$set(message= FALSE, warning = FALSE)
knitr::opts_chunk$set(message= FALSE, warning = FALSE)
# build -------------------------------------------------------------------
pkgdown::build_site(install=F)
rm(list=ls())
# Define dataset paths depending on your machine
if(grepl("^gizmo", Sys.info()["nodename"])){
ROOT_DIR1<-"/fh/fast/furlan_s/experiments/MB_10X_5p/cds"
ROOT_DIR2<-"/fh/fast/furlan_s/grp/data/ddata/BM_data"
ROOT_DIR3<-"/fh/fast/furlan_s/experiments/LRPBMC/cds"
} else {
ROOT_DIR1<-"/Users/sfurlan/Library/CloudStorage/OneDrive-SharedLibraries-FredHutchinsonCancerCenter/Furlan_Lab - General/experiments/MB_10X_5p/cds"
ROOT_DIR2<-"/Users/sfurlan/Library/CloudStorage/OneDrive-SharedLibraries-FredHutchinsonCancerCenter/Furlan_Lab - General/datasets/Healthy_BM_greenleaf"
ROOT_DIR3<-"/Users/sfurlan/Library/CloudStorage/OneDrive-SharedLibraries-FredHutchinsonCancerCenter/Furlan_Lab - General/experiments/LRPBMC/cds"
}
knitr::opts_chunk$set(message= FALSE, warning = FALSE)
# Load required packages
suppressPackageStartupMessages({
library(flscuts)
library(Seurat)
library(monocle3)
library(viewmastR)
library(ggplot2)
library(scCustomize)
library(tidyr)
})
seur <- readRDS(file.path(ROOT_DIR1, "240926_final_object.RDS"))
# Make some colors
cols1 <- as.character(pals::polychrome()[c(1,3:13)])
names(cols1) <- levels(factor(seur$celltype))
cols2 <- c("00_PROJECTOR"="grey90", cols1)
DimPlot_scCustom(seur, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Reference - aka Projector Dataset")
seu <-readRDS(file.path(ROOT_DIR3, "240926_5p_seu.RDS"))
DimPlot_scCustom(seu, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Query - aka Projectee Dataset")
Idents(seur) <- seur$celltype
all_markers <- FindAllMarkers(object = seur) %>%
Add_Pct_Diff() %>% dplyr::filter(pct_diff > 0.6)
top_markers <- Extract_Top_Markers(marker_dataframe = all_markers, num_genes = 5, named_vector = FALSE,
make_unique = TRUE)
Clustered_DotPlot(seurat_object = seur, features = top_markers, colors_use_idents = cols1, k=11, plot_km_elbow = F)
pkgdown::deploy_to_branch()
pkgdown::deploy_to_branch()
pkgdown::deploy_to_branch()
seu <- NormalizeData(seu)
seur <- NormalizeData(seur)
seu <- NormalizeData(seur) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA() %>% RunUMAP(dims=1:30, return.model = T)
seur <- readRDS(file.path(ROOT_DIR1, "240926_final_object.RDS"))
# Make some colors
cols1 <- as.character(pals::polychrome()[c(1,3:13)])
names(cols1) <- levels(factor(seur$celltype))
cols2 <- c("00_PROJECTOR"="grey90", cols1)
DimPlot_scCustom(seur, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Reference - aka Projector Dataset")
seur <- readRDS(file.path(ROOT_DIR1, "240926_final_object.RDS"))
# Make some colors
cols1 <- as.character(pals::polychrome()[c(1,3:13)])
names(cols1) <- levels(factor(seur$celltype))
cols2 <- c("00_PROJECTOR"="grey90", cols1)
seur <- NormalizeData(seur) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA() %>% RunUMAP(dims=1:30, return.model = T)
DimPlot_scCustom(seur, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Reference - aka Projector Dataset")
seu <-readRDS(file.path(ROOT_DIR3, "240926_5p_seu.RDS"))
seu <- NormalizeData(seu) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA() %>% RunUMAP(dims=1:30, return.model = T)
DimPlot_scCustom(seu, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Query - aka Projectee Dataset")
anchors <- FindTransferAnchors(
reference = seur,
query = seu,
reference.reduction = 'pca',
features = rownames(x = seur[["pca"]]@feature.loadings),
dims = 1:30,
nn.method = "annoy",
k.filter = NA,
verbose = TRUE
)
seu.1 <- MapQuery(
reference = seur,
query = seu,
anchorset = anchors,
refdata = list(celltype = "celltype"),
reference.reduction = "pca",
reduction.model = "umap"
)
# set embeddings
seur[["umap.new"]] <- CreateDimReducObject(embeddings = seur[["umap"]]@cell.embeddings, key = "UMAPnew_")
# set UMAP models
umap.new.model <- list()
umap.new.model$n_epochs <- 500
umap.new.model$alpha <-1
umap.new.model$method <- "umap"
umap.new.model$negative_sample_rate <- 5
umap.new.model$gamma <- 1
umap.new.model$approx_pow <- 0
umap.new.model$metric$cosine <- list()
umap.new.model$embedding <- seur[["umap.new"]]@cell.embeddings
ab_param <- uwot:::find_ab_params(spread = 1, min_dist = 0.3)
umap.new.model$a <- ab_param["a"]
umap.new.model$b <- ab_param["b"]
seur[["umap.new"]]@misc$model <- umap.new.model
seu.2 <- MapQuery(
reference = seur,
query = seu,
anchorset = anchors,
refdata = list(celltype = "celltype"),
reference.reduction = "pca",
reduction.model = "umap.new"
)
list(celltype = "celltype")
DimPlot(seur)
DimPlot(seur, reduction = "umap.new")
seur[["umap.new"]]@misc$model
umap_new_model$n_neighbors <- 30
# set UMAP models
umap.new.model <- list()
umap.new.model$n_epochs <- 500
umap.new.model$alpha <-1
umap.new.model$method <- "umap"
umap.new.model$negative_sample_rate <- 5
umap.new.model$gamma <- 1
umap.new.model$approx_pow <- 0
umap_new_model$n_neighbors <- 30
umap.new.model$metric$cosine <- list()
umap.new.model$embedding <- seur[["umap.new"]]@cell.embeddings
ab_param <- uwot:::find_ab_params(spread = 1, min_dist = 0.3)
umap.new.model$a <- ab_param["a"]
umap.new.model$b <- ab_param["b"]
seur[["umap.new"]]@misc$model <- umap.new.model
seu.2 <- MapQuery(
reference = seur,
query = seu,
anchorset = anchors,
refdata = list(celltype = "celltype"),
reference.reduction = "pca",
reduction.model = "umap.new"
)
debug(MapQuery)
seu.2 <- MapQuery(
reference = seur,
query = seu,
anchorset = anchors,
refdata = list(celltype = "celltype"),
reference.reduction = "pca",
reduction.model = "umap.new"
)
reference.dims
slot(object = anchorset,
name = "command")$dims
ProjectUMAP
pu.allarguments
ref_nn.num
Misc(object = reference[[reduction.model]],
slot = "model")$n_neighbors
reference[[reduction.model]]
# set UMAP models
umap.new.model <- list()
umap.new.model$n_epochs <- 500
umap.new.model$alpha <-1
umap.new.model$method <- "umap"
umap.new.model$negative_sample_rate <- 5
umap.new.model$gamma <- 1
umap.new.model$approx_pow <- 0
umap_new_model$n_neighbors <- 30
umap.new.model$metric$cosine <- list()
umap.new.model$embedding <- seur[["umap.new"]]@cell.embeddings
ab_param <- uwot:::find_ab_params(spread = 1, min_dist = 0.3)
umap.new.model$a <- ab_param["a"]
umap.new.model$b <- ab_param["b"]
seur[["umap.new"]]@misc$model <- umap.new.model
# set UMAP models
umap.new.model <- list()
umap.new.model$n_epochs <- 500
umap.new.model$alpha <-1
umap.new.model$method <- "umap"
umap.new.model$negative_sample_rate <- 5
umap.new.model$gamma <- 1
umap.new.model$approx_pow <- 0
umap.new_model$n_neighbors <- 30
umap.new.model$metric$cosine <- list()
umap.new.model$embedding <- seur[["umap.new"]]@cell.embeddings
ab_param <- uwot:::find_ab_params(spread = 1, min_dist = 0.3)
umap.new.model$a <- ab_param["a"]
umap.new.model$b <- ab_param["b"]
seur[["umap.new"]]@misc$model <- umap.new.model
# set UMAP models
umap.new.model <- list()
umap.new.model$n_epochs <- 500
umap.new.model$alpha <-1
umap.new.model$method <- "umap"
umap.new.model$negative_sample_rate <- 5
umap.new.model$gamma <- 1
umap.new.model$approx_pow <- 0
umap.new.model$n_neighbors <- 30
umap.new.model$metric$cosine <- list()
umap.new.model$embedding <- seur[["umap.new"]]@cell.embeddings
ab_param <- uwot:::find_ab_params(spread = 1, min_dist = 0.3)
umap.new.model$a <- ab_param["a"]
umap.new.model$b <- ab_param["b"]
seur[["umap.new"]]@misc$model <- umap.new.model
seu.2 <- MapQuery(
reference = seur,
query = seu,
anchorset = anchors,
refdata = list(celltype = "celltype"),
reference.reduction = "pca",
reduction.model = "umap.new"
)
undebug(MapQuery)
seu.2 <- MapQuery(
reference = seur,
query = seu,
anchorset = anchors,
refdata = list(celltype = "celltype"),
reference.reduction = "pca",
reduction.model = "umap.new"
)
p1 <- DimPlot(seu.1, reduction = "ref.umap",group.by = "predicted.celltype", label = T) + NoLegend() + ggtitle("return model")
p2 <- DimPlot(seu.2, reduction = "ref.umap", group.by = "predicted.celltype", label = T) + NoLegend()+ ggtitle("set model")
library(patchwork)
p1+p2
seu.1
seu.2
seur
DimPlot_scCustom(seu, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Query - aka Projectee Dataset; Pre-Projection")
p0 <- DimPlot(seur, reduction = "ref.umap", group.by = "predicted.celltype", label = T) +theme_void()+ggtitle("Reference - aka Projector Dataset")
p0 <- DimPlot(seur, group.by = "predicted.celltype", label = T) +theme_void()+ggtitle("Reference - aka Projector Dataset")
p1 <- DimPlot(seu.1, reduction = "ref.umap",group.by = "predicted.celltype", label = T) + NoLegend() +theme_void()+ggtitle("Query - ake")
p2 <- DimPlot(seu.2, reduction = "ref.umap", group.by = "predicted.celltype", label = T) + NoLegend()+ ggtitle("set model")
library(patchwork)
p1+p2+p3
p0 <- DimPlot(seur, group.by = "celltype", label = T) +theme_void()+ggtitle("Reference - aka Projector Dataset")
p1 <- DimPlot(seu.1, reduction = "ref.umap",group.by = "predicted.celltype", label = T) + NoLegend() +theme_void()+ggtitle("Query - ake")
p2 <- DimPlot(seu.2, reduction = "ref.umap", group.by = "predicted.celltype", label = T) + NoLegend()+ ggtitle("set model")
library(patchwork)
p0+p1+p2
p0 <- DimPlot(seur, reduction = "ref.umap", group.by = "celltype", label = T) +theme_void()+ggtitle("Reference - aka Projector Dataset")
# set embeddings
seur[["umap.new"]] <- CreateDimReducObject(embeddings = seur[["umap"]]@cell.embeddings, key = "UMAPnew_")
p0 <- DimPlot(seur, reduction = "ref.umap", group.by = "celltype", label = T) +theme_void()+ggtitle("Reference - aka Projector Dataset")
seur@reductions
p0 <- DimPlot(seur, reduction = "umap.new", group.by = "celltype", label = T) +theme_void()+ggtitle("Reference - aka Projector Dataset")
p0
rm(list=ls())
# Define dataset paths depending on your machine
if(grepl("^gizmo", Sys.info()["nodename"])){
ROOT_DIR1<-"/fh/fast/furlan_s/experiments/MB_10X_5p/cds"
ROOT_DIR2<-"/fh/fast/furlan_s/grp/data/ddata/BM_data"
ROOT_DIR3<-"/fh/fast/furlan_s/experiments/LRPBMC/cds"
} else {
ROOT_DIR1<-"/Users/sfurlan/Library/CloudStorage/OneDrive-SharedLibraries-FredHutchinsonCancerCenter/Furlan_Lab - General/experiments/MB_10X_5p/cds"
ROOT_DIR2<-"/Users/sfurlan/Library/CloudStorage/OneDrive-SharedLibraries-FredHutchinsonCancerCenter/Furlan_Lab - General/datasets/Healthy_BM_greenleaf"
ROOT_DIR3<-"/Users/sfurlan/Library/CloudStorage/OneDrive-SharedLibraries-FredHutchinsonCancerCenter/Furlan_Lab - General/experiments/LRPBMC/cds"
}
knitr::opts_chunk$set(message= FALSE, warning = FALSE)
# Load required packages
suppressPackageStartupMessages({
library(flscuts)
library(Seurat)
library(monocle3)
library(viewmastR)
library(ggplot2)
library(scCustomize)
library(tidyr)
})
seur <- readRDS(file.path(ROOT_DIR1, "240926_final_object.RDS"))
# Make some colors
cols1 <- as.character(pals::polychrome()[c(1,3:13)])
seur <- NormalizeData(seur) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA() %>% RunUMAP(dims=1:30, return.model = T)
DimPlot_scCustom(seur, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Reference")
seu <-readRDS(file.path(ROOT_DIR3, "240926_5p_seu.RDS"))
seu <- NormalizeData(seu) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA() %>% RunUMAP(dims=1:30, return.model = T)
DimPlot_scCustom(seu, group.by = "celltype", colors_use = cols1)+theme_void()+ggtitle("Query")
anchors <- FindTransferAnchors(
reference = seur,
query = seu,
reference.reduction = 'pca',
features = rownames(x = seur[["pca"]]@feature.loadings),
dims = 1:30,
nn.method = "annoy",
k.filter = NA,
verbose = TRUE
)
seu.1 <- MapQuery(
reference = seur,
query = seu,
anchorset = anchors,
refdata = list(celltype = "celltype"),
reference.reduction = "pca",
reduction.model = "umap"
)
p1 <- DimPlot(seu.1, reduction = "ref.umap",group.by = "predicted.celltype", label = T) + NoLegend() +theme_void()+ggtitle("Query - Unmodified model")
p1
p1 <- DimPlot_scCustom(seu.1, reduction = "ref.umap",group.by = "predicted.celltype", label = T, colors_use = cols1) + NoLegend() +theme_void()+ggtitle("Query - Mapped using Reference")
DimPlot_scCustom(seu.1, reduction = "ref.umap",group.by = "predicted.celltype", label = T, colors_use = cols1) + NoLegend() +theme_void()+ggtitle("Query - Mapped using Reference")
p0 <- DimPlot(seur, reduction = "umap.new", group.by = "celltype", label = T, colors_use = cols1) +theme_void()+ggtitle("Reference - aka Projector Dataset")
p1 <- DimPlot_scCustom(seu.1, reduction = "ref.umap",group.by = "predicted.celltype", label = T, colors_use = cols1) + NoLegend() +theme_void()+ggtitle("Query - Mapped using UMAP Projection from Reference")
p0 <- DimPlot_scCustom(seur, reduction = "umap.new", group.by = "celltype", label = T, colors_use = cols1) +theme_void()+ggtitle("Reference - aka Projector Dataset")
p0 <- DimPlot_scCustom(seur, group.by = "celltype", label = T, colors_use = cols1) +theme_void()+ggtitle("Reference - aka Projector Dataset")
p1 <- DimPlot_scCustom(seu.1, reduction = "ref.umap",group.by = "predicted.celltype", label = T, colors_use = cols1) + NoLegend() +theme_void()+ggtitle("Query - Mapped using UMAP Projection from Reference")
p0+p1
# set embeddings
seur[["umap.new"]] <- CreateDimReducObject(embeddings = seur[["umap"]]@cell.embeddings, key = "UMAPnew_")
# set embeddings
seur[["umap.new"]] <- CreateDimReducObject(embeddings = seur[["umap"]]@cell.embeddings, key = "UMAPnew_", assay = "RNA")
# set UMAP models
umap.new.model <- list()
umap.new.model$n_epochs <- 500
umap.new.model$alpha <-1
umap.new.model$method <- "umap"
umap.new.model$negative_sample_rate <- 5
umap.new.model$gamma <- 1
umap.new.model$approx_pow <- 0
umap.new.model$n_neighbors <- 30
umap.new.model$metric$cosine <- list()
umap.new.model$embedding <- seur[["umap.new"]]@cell.embeddings
ab_param <- uwot:::find_ab_params(spread = 1, min_dist = 0.3)
umap.new.model$a <- ab_param["a"]
umap.new.model$b <- ab_param["b"]
seur[["umap.new"]]@misc$model <- umap.new.model
umap.new.model$n_epochs <- 1000
# set UMAP models
umap.new.model <- list()
umap.new.model$n_epochs <- 1000
umap.new.model$alpha <-1
umap.new.model$method <- "umap"
umap.new.model$negative_sample_rate <- 5
umap.new.model$gamma <- 1
umap.new.model$approx_pow <- 0
umap.new.model$n_neighbors <- 10
umap.new.model$metric$cosine <- list()
umap.new.model$embedding <- seur[["umap.new"]]@cell.embeddings
ab_param <- uwot:::find_ab_params(spread = 1, min_dist = 0.3)
umap.new.model$a <- ab_param["a"]
umap.new.model$b <- ab_param["b"]
seur[["umap.new"]]@misc$model <- umap.new.model
seu.2 <- MapQuery(
reference = seur,
query = seu,
anchorset = anchors,
refdata = list(celltype = "celltype"),
reference.reduction = "pca",
reduction.model = "umap.new"
)
p2 <- DimPlot_scCustom(seu.2, reduction = "ref.umap", group.by = "predicted.celltype", label = T, colors_use = cols1) + NoLegend()+ ggtitle("set model")
p0+p2
p0+p1
p2 <- DimPlot_scCustom(seu.2, reduction = "ref.umap",group.by = "predicted.celltype", label = T, colors_use = cols1) + NoLegend() +theme_void()+ggtitle("Query - Mapped using Altered UMAP Projection from Reference")
p0+p2
# quick testing -----------------------------------------------------------
pkgdown::clean_site(pkg = ".")
pkgdown::build_article("ProjectDataSeuratWorkflow")
# quick testing -----------------------------------------------------------
pkgdown::clean_site(pkg = ".")
pkgdown::init_site(pkg = ".")
pkgdown::build_home_index()
pkgdown::preview_page("index.html")
pkgdown::build_article(name = "ProjectDataSeuratWorkflow")
pkgdown::preview_page('articles/ProjectDataSeuratWorkflow.html')
pkgdown::preview_page("articles/ProjectDataSeuratWorkflow")
# quick testing -----------------------------------------------------------
pkgdown::clean_site(pkg = ".")
pkgdown::init_site(pkg = ".")
pkgdown::deploy_to_branch()
rm(list=ls())
# Define dataset paths depending on your machine
if (grepl("^gizmo", Sys.info()["nodename"])) {
ROOT_DIR1 <- "NA"
} else {
ROOT_DIR1 <- "/Users/sfurlan/Library/CloudStorage/OneDrive-SharedLibraries-FredHutchinsonCancerCenter/Furlan_Lab - General/experiments"
}
stem <- "Pitt/Pitt_2"
DATA_DIR <- file.path(ROOT_DIR1, stem, "data") # SPECIFY HERE
RES_DIR <- file.path(ROOT_DIR1, stem, "res") # SPECIFY HERE
RMD_DIR <- file.path(ROOT_DIR1, stem, "rmd") # SPECIFY HERE
CDS_DIR <- file.path(ROOT_DIR1, stem, "cds")
FIG_DIR <- file.path(ROOT_DIR1, stem, "figs")
# Load required packages
suppressPackageStartupMessages({
library(flscuts)
library(viewmastR)
library(Seurat)
library(scCustomize)
library(magrittr)
library(miloR)
library(scater)
})
set.seed(1234) # Set Seed
group_cols<-c("Pre_Ifng_1_BM" = "#594286",
"Post_Ifng_1_BM" = "#bd9895",
"Pre_Ifng_1_34" = "#f76b14",
"Post_Ifng_1_34" = "#20B2AA",
"Pre_Ifng_5_BM" = "orange",
"Post_Ifng_5_BM" = "grey",
"Pre_Ifng_7_BM" = "violetred4",
"Post_Ifng_7_BM" = "lightgreen")
seu <- readRDS(file.path(CDS_DIR, "Patient_1_final_CDS.RDS"))
seu <- seu[,seu$celltype %in% c("01_HSC", "04_Myeloid_Progenitor", "02_Early_Erythroid")]
DimPlot(seu, group.by = "geno_5")
DimPlot(seu, group.by = "geno_5")
DimPlot(seu, group.by = "geno")
seu <- seu[,seu$geno %in% "1"]
seu$rx <- strsplit(colnames(seu), "_") %>% sapply("[[", 1)
DimPlot(seu, group.by="rx")
DimPlot(seu, group.by = "celltype")
seu$celltype<- factor(as.character(seu$celltype))
#roxygen2::roxygenise()
DefaultAssay(seu)<-"RNA"
seu$rx <- factor(seu$rx)
scm <- make_nhoods(seu, variable="rx", covariate1 = "celltype")
debug(make_nhoods)
scm <- make_nhoods(seu, variable="rx", covariate1 = "celltype")
miloR::plotNhoodSizeHist(sce_milo)
roxygen2::roxygenise()
scm <- make_nhoods(seu, variable="rx", covariate1 = "celltype")
scm <- make_nhoods(seu, variable="rx", covariate1 = "celltype")
roxygen2::roxygenise()
scm <- make_nhoods(seu, variable="rx", covariate1 = "celltype")
da_result <- test_nhoods(scm, "~rx+celltype")
scm$design