|
a |
|
b/R/Helpers.R |
|
|
1 |
# CITE-seq data |
|
|
2 |
df_comb <- FetchData(Combined_T, vars = c("wnnUMAP_1", "wnnUMAP_2", colnames(Combined_T@meta.data))) %>% |
|
|
3 |
mutate(IdentI=factor (IdentI, levels = cluster_order)) %>% |
|
|
4 |
left_join(., df_celltypes, by = "IdentI") %>% |
|
|
5 |
mutate(CellType=factor(CellType, levels=rev(celltypes), labels = rev(labels_celltypes_pars))) |
|
|
6 |
|
|
|
7 |
# 5'scRNA and scTCR data |
|
|
8 |
DFtotal_5prime <- |
|
|
9 |
lapply(sobjs_T_5prime, function(x){ |
|
|
10 |
FetchData(x, vars = c("PatientID", "umapRNA_1", "umapRNA_2", "refUMAP_1", "refUMAP_2", |
|
|
11 |
"predicted.celltype", "predicted.celltype.score", "CD4", "CD8A")) |
|
|
12 |
}) %>% |
|
|
13 |
bind_rows() %>% |
|
|
14 |
rownames_to_column("Barcode_full") %>% |
|
|
15 |
add_entity() %>% |
|
|
16 |
rename(IdentI=predicted.celltype) %>% |
|
|
17 |
left_join(., DF_TCRrep, by=c("Barcode_full", "PatientID")) |
|
|
18 |
|
|
|
19 |
# ADT data from CITE-seq data |
|
|
20 |
df_ADT <- FetchData(Combined_T, slot = "scale.data", |
|
|
21 |
vars = c("Barcode_full", |
|
|
22 |
paste0("integratedadt_", rownames(Combined_T@assays$integratedADT)))) %>% |
|
|
23 |
left_join(df_comb %>% select(IdentI, Barcode_full, Entity, PatientID), ., by = "Barcode_full") %>% |
|
|
24 |
pivot_longer(cols = 6:ncol(.), names_to = "Epitope", values_to = "Expression") %>% |
|
|
25 |
mutate(Epitope=gsub(Epitope, pattern = "integratedadt_.", replacement = "")) %>% |
|
|
26 |
na.omit() |
|
|
27 |
|
|
|
28 |
df_ADTdenoised <- FetchData(Combined_T, slot = "data", |
|
|
29 |
vars = c("Barcode_full", |
|
|
30 |
paste0("denoisedprotein_", rownames(Combined_T@assays$denoisedProtein)))) %>% |
|
|
31 |
left_join(df_comb %>% select(IdentI, Barcode_full, Entity, PatientID), ., by = "Barcode_full") %>% |
|
|
32 |
pivot_longer(cols = 6:ncol(.), names_to = "Epitope", values_to = "Expression") %>% |
|
|
33 |
mutate(Epitope=gsub(Epitope, pattern = "denoisedprotein_", replacement = "")) %>% |
|
|
34 |
left_join(., thresh, by="Epitope") %>% |
|
|
35 |
na.omit() |
|
|
36 |
|
|
|
37 |
percentageADT <- |
|
|
38 |
df_ADTdenoised %>% |
|
|
39 |
mutate(Pos=Expression>value) %>% |
|
|
40 |
add_prop(vars = c("Pos", "Epitope", "IdentI", "PatientID"), group.vars = c(2:4)) %>% |
|
|
41 |
filter(Pos==T) %>% |
|
|
42 |
select(-Pos) %>% |
|
|
43 |
group_by(Epitope, IdentI) %>% |
|
|
44 |
summarise(Prop=mean(Prop), `.groups`="drop") |
|
|
45 |
|
|
|
46 |
meanADT <- |
|
|
47 |
df_ADT %>% group_by(IdentI, Epitope) %>% |
|
|
48 |
summarise(Expression=mean(Expression), `.groups`="drop") %>% |
|
|
49 |
group_by(Epitope) %>% |
|
|
50 |
mutate(Expression=(Expression-min(Expression))/(max(Expression)-min(Expression))) |
|
|
51 |
|
|
|
52 |
# Align FACS and CITE-seq data |
|
|
53 |
df_freq <- |
|
|
54 |
df_comb %>% |
|
|
55 |
add_prop(vars = c("IdentI", "PatientID"), group.vars = 2) %>% |
|
|
56 |
pivot_wider(names_from = "IdentI", values_from = "Prop", values_fill = 0) %>% |
|
|
57 |
mutate(TREG= `8`+`11`+`13`+`15`, |
|
|
58 |
TFH=`6`, |
|
|
59 |
`TREGCM1`=`8`, |
|
|
60 |
`TREGCM2`=`13`, |
|
|
61 |
`TREGEM1`=`15`, |
|
|
62 |
`TREGEM2`=`11`, |
|
|
63 |
`TREG/CM1`=`8`/TREG, |
|
|
64 |
`TREG/CM2`=`13`/TREG, |
|
|
65 |
`TREG/EM1`=`15`/TREG, |
|
|
66 |
`TREG/EM2`=`11`/TREG, |
|
|
67 |
THNaive=`1`, |
|
|
68 |
TTOXNaive=`12`, |
|
|
69 |
TDN=`19`, |
|
|
70 |
TTOX=`5`+`3`+`16`, |
|
|
71 |
TPR=`14`, |
|
|
72 |
`TTOXEM1`=`3`, |
|
|
73 |
`TTOXEM2`=`16`, |
|
|
74 |
`TTOXEM3`=`5`, |
|
|
75 |
`TTOX/EM1`=(`3`)/TTOX, |
|
|
76 |
`TTOX/EM2`=(`16`)/TTOX, |
|
|
77 |
`TTOX/EM3`=(`5`)/TTOX, |
|
|
78 |
THCM1=`2`, |
|
|
79 |
THCM2=`9` |
|
|
80 |
) %>% |
|
|
81 |
pivot_longer(cols = 2:ncol(.), names_to = "Population", values_to = "RNA") %>% |
|
|
82 |
mutate(RNA=100*RNA) |