|
1 | 1 | # Subset loom file to cells of interest |
2 | 2 |
|
3 | 3 | ```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 | + |
4 | 18 | # Get loom data |
5 | 19 | ldat <- ReadVelocity(file = "data/merged_loom_files/all_merged.loom") |
6 | 20 |
|
@@ -45,11 +59,20 @@ bm@reductions[["umap"]] <- seurat_object@reductions[["umap"]] |
45 | 59 | bm@assays$integrated <- seurat_object@assays$integrated |
46 | 60 | bm@assays$SCT <- seurat_object@assays$SCT |
47 | 61 |
|
| 62 | +# Save object and convert to h5ad format for scvelo |
48 | 63 |
|
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") |
50 | 67 |
|
51 | | -# Save object and convert to h5ad format for scvelo |
52 | 68 |
|
| 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") |
53 | 76 | DefaultAssay(bm) <- "RNA" |
54 | 77 | SaveH5Seurat(bm, filename = "all_samples.h5Seurat") |
55 | 78 | Convert("all_samples.h5Seurat", dest = "h5ad") |
@@ -87,45 +110,4 @@ DimPlot(object = ko, |
87 | 110 | label = TRUE) + NoLegend() |
88 | 111 | ``` |
89 | 112 |
|
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") |
131 | 113 |
|
0 commit comments