|
a |
|
b/analysis/MapTcells_5scRNA.Rmd |
|
|
1 |
--- |
|
|
2 |
title: "Map 5 prime single cell RNA data" |
|
|
3 |
author: Tobias Roider |
|
|
4 |
date: "Last compiled on `r format(Sys.time(), '%d %B, %Y, %X')`" |
|
|
5 |
output: |
|
|
6 |
|
|
|
7 |
rmdformats::readthedown |
|
|
8 |
editor_options: |
|
|
9 |
chunk_output_type: inline |
|
|
10 |
--- |
|
|
11 |
|
|
|
12 |
```{r options, include=FALSE, warning = FALSE} |
|
|
13 |
|
|
|
14 |
library(knitr) |
|
|
15 |
opts_chunk$set(echo=TRUE, tidy=FALSE, include=TRUE, message=FALSE, |
|
|
16 |
dpi = 100, cache = FALSE, warning = FALSE) |
|
|
17 |
opts_knit$set(root.dir = "../") |
|
|
18 |
options(bitmapType = "cairo") |
|
|
19 |
|
|
|
20 |
``` |
|
|
21 |
|
|
|
22 |
# Load packages and functions |
|
|
23 |
```{r Load packages and functions} |
|
|
24 |
|
|
|
25 |
library(Seurat) |
|
|
26 |
library(tidyverse) |
|
|
27 |
library(readxl) |
|
|
28 |
|
|
|
29 |
source("R/ReadPackages.R") |
|
|
30 |
source("R/Functions.R") |
|
|
31 |
source("R/ThemesColors.R") |
|
|
32 |
|
|
|
33 |
mytheme <- |
|
|
34 |
theme_bw()+ |
|
|
35 |
theme(legend.position = "none", |
|
|
36 |
plot.title = element_text(hjust = 0.5), |
|
|
37 |
panel.grid = element_blank()) |
|
|
38 |
|
|
|
39 |
``` |
|
|
40 |
|
|
|
41 |
# Read data |
|
|
42 |
```{r read data} |
|
|
43 |
|
|
|
44 |
Combined_T <- readRDS("output/Tcells_Integrated.rds") |
|
|
45 |
|
|
|
46 |
``` |
|
|
47 |
|
|
|
48 |
# Read and Process 5' scRNA data |
|
|
49 |
```{r Read and Process} |
|
|
50 |
|
|
|
51 |
files <- list.files(path = "countMatrices", pattern = "_Tcells_5'RNA.txt", full.names = T) |
|
|
52 |
names(files) <- strsplit(files, split = "_") %>% sapply("[[", 1) %>% strsplit(split = "/") %>% sapply("[[", 2) |
|
|
53 |
|
|
|
54 |
sobjs_T <- lapply(1:length(files), function(x) { |
|
|
55 |
|
|
|
56 |
# Read count tables |
|
|
57 |
rna <- read.delim(files[x], sep = " ") |
|
|
58 |
|
|
|
59 |
# Create Seurat Object |
|
|
60 |
sobj <- CreateSeuratObject(counts = rna) |
|
|
61 |
|
|
|
62 |
# Add Percentage of mitochondrial genes and PatientID |
|
|
63 |
sobj[["percent.mt"]] <- PercentageFeatureSet(sobj, pattern = "^MT-") |
|
|
64 |
sobj$PatientID <- names(files)[x] |
|
|
65 |
|
|
|
66 |
# Normalize data |
|
|
67 |
sobj <- NormalizeData(sobj, normalization.method = "LogNormalize", scale.factor = 10000) |
|
|
68 |
|
|
|
69 |
# Run Seurat Processing |
|
|
70 |
sobj <- SeuratProc_T(sobj, verbose=FALSE, |
|
|
71 |
dims.clustering=1:14, |
|
|
72 |
resolution.clustering = 0.4, |
|
|
73 |
dims.umap=1:13) |
|
|
74 |
|
|
|
75 |
return(sobj) |
|
|
76 |
|
|
|
77 |
}) |
|
|
78 |
|
|
|
79 |
names(sobjs_T) <- names(files) |
|
|
80 |
|
|
|
81 |
``` |
|
|
82 |
|
|
|
83 |
# Map individual samples to CITE-seq reference |
|
|
84 |
```{r mapping} |
|
|
85 |
|
|
|
86 |
sobjs_T_mapped <- lapply(sobjs_T, function(sobj) { |
|
|
87 |
|
|
|
88 |
anchors <- FindTransferAnchors(reference = Combined_T, query = sobj, |
|
|
89 |
reference.reduction = "pcaRNA") |
|
|
90 |
|
|
|
91 |
sobj <- MapQuery(anchorset = anchors, reference = Combined_T, |
|
|
92 |
query = sobj, reduction.model = "wnn.umap", |
|
|
93 |
refdata = list(celltype = "IdentI"), |
|
|
94 |
reference.reduction = "pcaRNA") |
|
|
95 |
|
|
|
96 |
return(sobj) |
|
|
97 |
|
|
|
98 |
}) |
|
|
99 |
|
|
|
100 |
names(sobjs_T_mapped) <- names(sobjs_T) |
|
|
101 |
|
|
|
102 |
|
|
|
103 |
``` |
|
|
104 |
|
|
|
105 |
# Plots |
|
|
106 |
```{r generate plots} |
|
|
107 |
|
|
|
108 |
p1 <- |
|
|
109 |
DimPlot(Combined_T, group.by = "IdentI", raster = TRUE, raster.dpi = c(500,500), |
|
|
110 |
reduction = "wnn.umap", label = TRUE)+ |
|
|
111 |
scale_color_manual(values = colors_umap_cl)+ |
|
|
112 |
xlim(-10, 13)+ylim(-10, 10)+ |
|
|
113 |
coord_fixed()+ |
|
|
114 |
mytheme |
|
|
115 |
|
|
|
116 |
p2 <- lapply(names(sobjs_T), function(sample){ |
|
|
117 |
DimPlot(subset(Combined_T, subset=PatientID==sample), raster.dpi = c(500,500), raster = TRUE, |
|
|
118 |
reduction = "wnn.umap", group.by = "IdentI", label = TRUE)+ |
|
|
119 |
scale_color_manual(values = colors_umap_cl)+ |
|
|
120 |
xlim(-10, 13)+ylim(-10, 10)+ |
|
|
121 |
coord_fixed()+ |
|
|
122 |
mytheme |
|
|
123 |
}) %>% `names<-`(names(sobjs_T)) |
|
|
124 |
|
|
|
125 |
p3 <- lapply(sobjs_T_mapped, function(sample){ |
|
|
126 |
DimPlot(sample, label = TRUE, raster.dpi = c(500,500), raster = TRUE, |
|
|
127 |
group.by = "predicted.celltype", reduction = "ref.umap")+ |
|
|
128 |
scale_color_manual(values = colors_umap_cl)+ |
|
|
129 |
xlim(-10, 13)+ylim(-10, 10)+ |
|
|
130 |
coord_fixed()+ |
|
|
131 |
mytheme |
|
|
132 |
}) %>% `names<-`(names(sobjs_T_mapped)) |
|
|
133 |
|
|
|
134 |
``` |
|
|
135 |
|
|
|
136 |
## LN0078 |
|
|
137 |
```{r LN0078, fig.height=4, fig.width=10} |
|
|
138 |
|
|
|
139 |
p1+p2$LN0078+p3$LN0078 |
|
|
140 |
|
|
|
141 |
``` |
|
|
142 |
|
|
|
143 |
## LN0132 |
|
|
144 |
```{r LN0132, fig.height=4, fig.width=10} |
|
|
145 |
|
|
|
146 |
p1+p2$LN0132+p3$LN0132 |
|
|
147 |
|
|
|
148 |
``` |
|
|
149 |
|
|
|
150 |
## LN0144 |
|
|
151 |
```{r LN0144, fig.height=4, fig.width=10} |
|
|
152 |
|
|
|
153 |
p1+p2$LN0144+p3$LN0144 |
|
|
154 |
|
|
|
155 |
``` |
|
|
156 |
|
|
|
157 |
## LN0178 |
|
|
158 |
```{r LN0178, fig.height=4, fig.width=10} |
|
|
159 |
|
|
|
160 |
p1+p2$LN0178+p3$LN0178 |
|
|
161 |
|
|
|
162 |
``` |
|
|
163 |
|
|
|
164 |
## LN0193 |
|
|
165 |
```{r LN0193, fig.height=4, fig.width=10} |
|
|
166 |
|
|
|
167 |
p1+p2$LN0193+p3$LN0193 |
|
|
168 |
|
|
|
169 |
``` |
|
|
170 |
|
|
|
171 |
## LN0217 |
|
|
172 |
```{r LN0217, fig.height=4, fig.width=10} |
|
|
173 |
|
|
|
174 |
p1+p2$LN0217+p3$LN0217 |
|
|
175 |
|
|
|
176 |
``` |
|
|
177 |
|
|
|
178 |
## LN0302 |
|
|
179 |
```{r LN0302, fig.height=4, fig.width=10} |
|
|
180 |
|
|
|
181 |
p1+p2$LN0302+p3$LN0302 |
|
|
182 |
|
|
|
183 |
``` |
|
|
184 |
|
|
|
185 |
## LN0110 |
|
|
186 |
```{r LN0110, fig.height=4, fig.width=10} |
|
|
187 |
|
|
|
188 |
p1+p2$LN0110+p3$LN0110 |
|
|
189 |
|
|
|
190 |
``` |
|
|
191 |
|
|
|
192 |
## LN0198 |
|
|
193 |
```{r LN0198, fig.height=4, fig.width=10} |
|
|
194 |
|
|
|
195 |
p1+p2$LN0198+p3$LN0198 |
|
|
196 |
|
|
|
197 |
``` |
|
|
198 |
|
|
|
199 |
## LN0259 |
|
|
200 |
```{r LN0259, fig.height=4, fig.width=10} |
|
|
201 |
|
|
|
202 |
p1+p2$LN0259+p3$LN0259 |
|
|
203 |
|
|
|
204 |
``` |
|
|
205 |
|
|
|
206 |
## LN0278 |
|
|
207 |
```{r LN0278, fig.height=4, fig.width=10} |
|
|
208 |
|
|
|
209 |
p1+p2$LN0278+p3$LN0278 |
|
|
210 |
|
|
|
211 |
``` |
|
|
212 |
|
|
|
213 |
# Save object |
|
|
214 |
```{r save, eval=FALSE} |
|
|
215 |
|
|
|
216 |
saveRDS(sobjs_T_mapped, file = "output/List_SeuratObjects_T_5prime.rds") |
|
|
217 |
|
|
|
218 |
``` |
|
|
219 |
|
|
|
220 |
# Session Info |
|
|
221 |
```{r session info} |
|
|
222 |
|
|
|
223 |
sessionInfo() |
|
|
224 |
|
|
|
225 |
``` |
|
|
226 |
|