Switch to unified view

a b/Statistical_analysis_Szabo_TCell_analysis.R
1
GIT_HOME="/research/users/ppolonen/git_home/ImmunogenomicLandscape-BloodCancers/"
2
source(file.path(GIT_HOME, "common_scripts/scRNA/functions.scRNA.analysis.R"))
3
source(file.path(GIT_HOME, "common_scripts/visualisation/plotting_functions.R"))
4
5
library(Matrix)
6
library(Seurat)
7
library(data.table)
8
library(ComplexHeatmap)
9
library(circlize)
10
library(parallel)
11
library(ggplot2)
12
13
setwd("/research/groups/sysgen/PROJECTS/HEMAP_IMMUNOLOGY/petri_work/HEMAP_IMMUNOLOGY/Published_data_figures")
14
15
#****************************** plot Szabo scores and immunoscores, singleR etc ******************************
16
17
a=fread("Szabo_Tcell_markers.txt", data.table = F)
18
rownames(a)=make.unique(a[,1])
19
dat=data.matrix(a[,-1])
20
dat[is.na(dat)]=0
21
# plot markers in
22
23
# compare NK cells
24
geneset=data.frame("genes"=a[,1], "name"=NA, stringsAsFactors = F)
25
geneset$name[1:70]="Treg"
26
geneset$name[71:140]="CD4 Tn / Tcm resting"
27
geneset$name[141:210]="CD4 / CD8 resting"
28
geneset$name[211:280]="IFN response"
29
geneset$name[281:350]="Proliferation"
30
geneset$name[351:420]="CD8 Cytotoxic"
31
geneset$name[421:490]="CD8 Cytokine"
32
33
geneset2=data.frame("genes"=a[,1], "name"=NA, stringsAsFactors = F)
34
geneset2$name[1:70]="Resting"
35
geneset2$name[71:140]="Resting"
36
geneset2$name[141:210]="Resting"
37
geneset2$name[211:280]="Activated"
38
geneset2$name[281:350]="Activated"
39
geneset2$name[351:420]="Activated"
40
geneset2$name[421:490]="Activated"
41
42
geneset.l=lapply(unique(geneset[,2]), function(g)geneset[geneset[,2]%in%g,1])
43
names(geneset.l)=unique(geneset[,2])
44
45
geneset.l2=lapply(unique(geneset2[,2]), function(g)geneset2[geneset2[,2]%in%g,1])
46
names(geneset.l2)=unique(geneset2[,2])
47
48
geneset.exhaustion=c("PDCD1", "CTLA4", "LAYN", "LAG3", "HAVCR2", "CD244", "CD160")
49
geneset.cytokine=c("CCL3", "CCL4", "XCL1", "XCL2", "IFNG", "CSF2", "IL10","TNFRSF9")
50
geneset.cytotoxic=c("CCL5", "GZMK", "GNLY", "EOMES", "ZEB2", "ZNF683", "KLRG1", "NKG7")
51
52
geneset.l3=list("Exhaustion"=geneset.exhaustion, "Cytokine"=geneset.cytokine, "Cytotoxic"=geneset.cytotoxic)
53
54
# add gm based score:
55
add.scores=list(HLAIScore=c("B2M", "HLA-A", "HLA-B","HLA-C"), HLAIIScore=c("HLA-DMA","HLA-DMB","HLA-DPA1","HLA-DPB1","HLA-DRA","HLA-DRB1"), CytolyticScore=c("GZMA", "PRF1", "GNLY", "GZMH", "GZMM"))
56
add.scores=append(append(geneset.l, append(geneset.l2, add.scores)), geneset.l3)
57
58
59
60
load("Szabo_Tcell_BM_scRNA.Rdata")
61
szabo=scmat
62
szabo <- NormalizeData(szabo, assay = "RNA", normalization.method = "LogNormalize", scale.factor = 10000)
63
fm.szabo <- data.matrix(GetAssayData(szabo, assay = "RNA", slot="data"))
64
65
# same in FIMM data:
66
load("FIMM_AML_HCA_T_scRNA.Rdata")
67
68
scmat=FindClusters(scmat, resolution = 0.5)
69
70
# make sure that using logNormalized data and scaled to 10000:
71
scmat <- NormalizeData(scmat, assay = "RNA", normalization.method = "LogNormalize", scale.factor = 10000)
72
fm.f <- data.matrix(GetAssayData(scmat, assay = "RNA", slot="data"))
73
74
sample=gsub("_.*.", "", colnames(scmat))
75
sample[grepl("Manton", sample)]="HCA BM"
76
sample[!grepl("3667|5249|5897", sample)&!grepl("HCA", sample)]="AML other"
77
scmat[["sample"]]=sample
78
79
# take cluster assignment for AML cells:
80
scmat2=FindNeighbors(scmat[,grepl("3667|5897|5249", sample)], dims = 1:25, reduction = "mnnCorrect")
81
scmat2=FindClusters(scmat2, resolution = 0.5, algorithm = 1)
82
83
AML_cluster_Tcell=Idents(scmat2)
84
save(AML_cluster_Tcell, file="Szabo_HCA_AML_cluster_cell.Rdata")
85
86
pdf("Figure_S3M_FIMM_AML_reclustered_Tcell.pdf", width = 6, height = 5)
87
DimPlot(scmat, pt.size = 0.1, cells.highlight = colnames(scmat2)[Idents(scmat2)%in%0], cols.highlight = "#006f00") # cytotoxic
88
DimPlot(scmat, pt.size = 0.1, cells.highlight = colnames(scmat2)[Idents(scmat2)%in%3], cols.highlight = "#006f00") # Cytokine
89
DimPlot(scmat2, label = T) # all clusters
90
dev.off()
91
92
geneset.l=lapply(unique(geneset[,2]), function(g){
93
  genes=geneset[geneset[,2]%in%g,1]
94
  
95
  #take only significant:
96
  genes=genes[genes%in%markers.all$gene[grepl("CD|Treg", markers.all$cluster)]]
97
})
98
names(geneset.l)=paste(unique(geneset[,2]), "filtered")
99
100
# add.scores=append(add.scores, geneset.l)
101
102
# add gm based score:
103
gm.objects=do.call(rbind, lapply(seq(add.scores), function(i){
104
  dat3=fm.f[rownames(fm.f)%in%add.scores[[i]],]
105
  gm=log2(t(apply(dat3, 2, gm_mean))) # done to normalized values
106
  rownames(gm)=names(add.scores)[i]
107
  return(gm)
108
}))
109
110
# also add to seurat object:
111
for(i in seq(add.scores)){
112
  scmat[[names(add.scores)[i]]] <- gm.objects[i,]
113
}
114
115
# add gm based score:
116
gm.objects=do.call(rbind, lapply(seq(add.scores), function(i){
117
  dat3=fm.szabo[rownames(fm.szabo)%in%add.scores[[i]],]
118
  gm=log2(t(apply(dat3, 2, gm_mean))) # done to normalized values
119
  rownames(gm)=names(add.scores)[i]
120
  return(gm)
121
}))
122
123
# also add to seurat object:
124
for(i in seq(add.scores)){
125
  szabo[[names(add.scores)[i]]] <- gm.objects[i,]
126
}
127
128
# pdf("FigureS3M_Szabo_markers_FIMM_AML_HCA_Tcells_Scores.pdf", width=16, height=10)
129
# FeaturePlot(scmat, features = names(add.scores), cols=c("grey75", "red"), min.cutoff = 0.1)
130
# FeaturePlot(szabo, features = names(add.scores), cols=c("grey75", "red"), min.cutoff = 0.1)
131
# dev.off()
132
133
pdf("Figure3M_Szabo_markers_FIMM_AML_HCA_Tcells_Scores_scaled.pdf", width=16, height=14)
134
p1=FeaturePlot(scmat, features = names(add.scores), combine = F, min.cutoff = 0.2, max.cutoff = 1)
135
fix.sc <- scale_color_gradientn( colours = c('grey75', 'red'),  limits = c(0.2, 1))
136
p2 <- lapply(p1, function (x) x + fix.sc)
137
CombinePlots(p2)
138
139
p1=FeaturePlot(szabo, features = names(add.scores), combine = F, min.cutoff = 0.2, max.cutoff = 1)
140
fix.sc <- scale_color_gradientn( colours = c('grey75', 'red'),  limits = c(0.2, 1))
141
p2 <- lapply(p1, function (x) x + fix.sc)
142
CombinePlots(p2)
143
dev.off()
144
145
pdf("Figure3I_FigureS3M_Szabo_markers_FIMM_AML_HCA_Tcells_Scores_blend.pdf", width=20, height=5)
146
FeaturePlot(scmat, features = names(add.scores)[c(14,15)], blend.threshold = 0, blend = T,cols = c("grey74", "darkblue", "red"))
147
FeaturePlot(scmat, features = names(add.scores)[c(8,9)], blend = T, blend.threshold = 0.6, cols = c("grey74", "darkblue", "red"))
148
dev.off()
149
150
colors.group=data.table::fread("colors_lineage.txt", data.table = F, header = F)
151
colors.group=colors.group[grepl("CD|Treg", colors.group$V1),]
152
plot.multi.scatter.scRNA(data.frame("Sample"="T cells HCA AML", "Data"="FIMM_AML_HCA_T_scRNA.Rdata", "Clusters"="", "Type"="", stringsAsFactors = F), colors.group = colors.group, seurat.feature = "SingleR.label", name="FigureS3M_singleR", cores=9, SIZE = 0.1, rasterize=F, width = 77*4, height = 74*4, text.size = 10*4)
153
154
# plot MDS-like samples to map:
155
scmat[["MDSlike"]]=ifelse(grepl("5897|3667|5249", scmat[["batch"]][,1]), "MDS-like", "other")
156
scmat[["MDSlike"]][grepl("BM", scmat[["batch"]][,1]),1]="normal BM"
157
158
lv = scmat[["MDSlike"]][,1]%in%c("MDS-like", "other")
159
# plot.scatter.seurat(scmat = scmat, colors.group = data.frame("V1"=c("normal BM", "other", "MDS-like"), "V2"=c("grey75", "orange", "#21a366"), stringsAsFactors = F), seurat.feature = "MDSlike", name="T cells (AML, HCA)",lv = lv, cores=1, add.density = T, add.proportions = T, SIZE = 1, rasterize=F, width = 64*4, height = 74*4, text.size=10*4)
160
161
xy=data.frame(Embeddings(scmat, "umap"))
162
163
pdf("Figure3I_Density_MDSlike_Tcell.pdf", width = 5, height = 4)
164
ggplot(xy[lv,], aes(x=UMAP_1, y=UMAP_2) ) +
165
stat_density2d(aes(fill = ..density..), contour = F, geom = 'tile') +
166
  viridis::scale_fill_viridis()
167
ggplot(xy[scmat[["MDSlike"]]=="normal BM",], aes(x=UMAP_1, y=UMAP_2) ) +
168
  stat_density2d(aes(fill = ..density..), contour = F, geom = 'tile') +
169
  viridis::scale_fill_viridis()
170
dev.off()