Skip to content

Commit 7e48225

Browse files
authored
Update seurat_loom_subset_velocity.md
1 parent 9c18459 commit 7e48225

File tree

1 file changed

+25
-43
lines changed

1 file changed

+25
-43
lines changed

scRNAseq/scRNAseq_analysis_tutorial/lessons/seurat_loom_subset_velocity.md

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# Subset loom file to cells of interest
22

33
```r
4+
# Use devtools to install hdf5r and loomR from GitHub
5+
# devtools::install_github(repo = "hhoeflin/hdf5r")
6+
# devtools::install_github(repo = "mojaveazure/loomR"
7+
# library(devtools)
8+
# install_github("velocyto-team/velocyto.R")
9+
# remotes::install_github('satijalab/seurat-wrappers')
10+
# remotes::install_github("mojaveazure/seurat-disk")
11+
12+
library(Seurat)
13+
library(SeuratDisk)
14+
library(SeuratWrappers)
15+
library(loomR)
16+
17+
418
# Get loom data
519
ldat <- ReadVelocity(file = "data/merged_loom_files/all_merged.loom")
620

@@ -45,11 +59,20 @@ bm@reductions[["umap"]] <- seurat_object@reductions[["umap"]]
4559
bm@assays$integrated <- seurat_object@assays$integrated
4660
bm@assays$SCT <- seurat_object@assays$SCT
4761

62+
# Save object and convert to h5ad format for scvelo
4863

49-
# Split into individual and merged objects
64+
DefaultAssay(bm) <- "RNA"
65+
SaveH5Seurat(bm, filename = "all_samples.h5Seurat")
66+
Convert("all_samples.h5Seurat", dest = "h5ad")
5067

51-
# Save object and convert to h5ad format for scvelo
5268

69+
# Split into individual objects
70+
bm_cre <- subset(bm, subset = sample_simple == "re")
71+
DefaultAssay(bm_cre) <- "RNA"
72+
SaveH5Seurat(bm_cre, filename = "cre_samples.h5Seurat")
73+
Convert("cre_samples.h5Seurat", dest = "h5ad")
74+
75+
bm_ko <- subset(bm, subset = sample_simple == "KO")
5376
DefaultAssay(bm) <- "RNA"
5477
SaveH5Seurat(bm, filename = "all_samples.h5Seurat")
5578
Convert("all_samples.h5Seurat", dest = "h5ad")
@@ -87,45 +110,4 @@ DimPlot(object = ko,
87110
label = TRUE) + NoLegend()
88111
```
89112

90-
3. Bring in loom files for ctrl and ko samples
91-
92-
```
93-
# Use devtools to install hdf5r and loomR from GitHub
94-
# devtools::install_github(repo = "hhoeflin/hdf5r")
95-
# devtools::install_github(repo = "mojaveazure/loomR"
96-
# library(devtools)
97-
# install_github("velocyto-team/velocyto.R")
98-
# remotes::install_github('satijalab/seurat-wrappers')
99-
# remotes::install_github("mojaveazure/seurat-disk")
100-
101-
library(Seurat)
102-
library(SeuratDisk)
103-
library(SeuratWrappers)
104-
library(loomR)
105-
106-
### Load filtered Seurat object and loom file
107-
seurat_object <- readRDS('/Location/of/seurat_object.rds')
108-
ldat <- ReadVelocity(file = "/Location/of/loom_file.loom")
109-
110-
for (i in names(x = ldat)) {
111-
### Store assay in a new variable
112-
assay <- ldat[[i]]
113-
114-
### Rename cell names in loom file to match cell names in Seurat object
115-
116-
colnames(assay)[str_detect(colnames(assay), pattern = "A1_")] <- colnames(assay)[str_detect(colnames(assay), pattern = "A1_")] %>% str_replace("x$", "-1_1")
117-
colnames(assay)[str_detect(colnames(assay), pattern = "A2_")] <- colnames(assay)[str_detect(colnames(assay), pattern = "A2_")] %>% str_replace("x$", "-1_2")
118-
colnames(assay) <- gsub('A1_CKDL210009739-1a-SI_TT_B3_HC2W5DSX2:', '', colnames(assay))
119-
colnames(assay) <- gsub('A2_CKDL210009740-1a-SI_TT_B6_HC2W5DSX2:', '', colnames(assay))
120-
121-
### Subset to filtered cells in Seurat object
122-
assay <- assay[,colnames(seurat_object)]
123-
124-
### Add assay to Seurat object
125-
seurat_object[[i]] <- CreateAssayObject(counts = assay)
126-
}
127-
128-
DefaultAssay(seurat_object) <- "RNA"
129-
SaveH5Seurat(seurat_object, filename = "cre.h5Seurat")
130-
Convert("cre.h5Seurat", dest = "h5ad")
131113

0 commit comments

Comments
 (0)