forked from TimCoorens/EarlyEmbryo_scRNA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscRNA_embryo_logistic_regression.R
362 lines (292 loc) · 15.8 KB
/
scRNA_embryo_logistic_regression.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#----------------------------------------------------------------------------
# Compare with other data sets and perform logistic regressions
# Tim Coorens
# August 2020
options(stringsAsFactors = F)
library(Seurat)
library(dplyr)
library(magrittr)
library(ggplot2)
library(cowplot)
library(patchwork)
library(viridis)
library(data.table)
source("logisticRegression.R")
source("similarity.R")
#Read in data
embryo.integrated=readRDS("embryo_integrated_allembryos_filtered.Rdata")
#------------------------------
# Compare with Zhou et al.
library(data.table)
fuchou_tpm=fread("GSE109555_All_Embryo_TPM.txt.gz",data.table = F) #Data available at GEO GSE109555
rownames(fuchou_tpm)=fuchou_tpm$V1
sampleInfo=read.csv("Supplementary Table 2 Sample Information.csv") #Available as part of the Zhou et al. paper
#Select the good embryos
include_zhou=c("hm_D8_E2", "hm_D8_E3", "hm_D8_E5", "ha_D8_E1", "hv_D8_E1", "hv_D8_E2", "hv_D8_E3", "hv_D10_E6", "ha_D10_E1", "ha_D10_E2", "hm_D10_E4", "hm_D10_E9", "hv_D10_E7", "hv_D10_E8", "ha_D12_E1", "hv_D12_E1", "hv_D12_E2")
fuchou_tpm=fuchou_tpm[,-1]
#Set up seurat objet
embryo_fuchou=CreateSeuratObject(counts = fuchou_tpm[,sampleInfo$Sample[sampleInfo$Ori_Day_Emb%in%include_zhou]])
embryo_fuchou <- NormalizeData(object = embryo_fuchou)
embryo_fuchou <- ScaleData(object = embryo_fuchou)
#Merge with own data - note: no batch correction as logistic regression doesn't rely on it
embryo_integrated_zhou=merge(x = embryo.integrated, y = embryo_fuchou,
add.cell.ids=c("Own","Zhou"),merge.data = TRUE)
#Annotate clusters
[email protected]$Cell_Type[[email protected]$seurat_clusters==0]="TE"
[email protected]$Cell_Type[[email protected]$seurat_clusters==1]="TE"
[email protected]$Cell_Type[[email protected]$seurat_clusters==2]="Epi"
[email protected]$Cell_Type[[email protected]$seurat_clusters==3]="Hypo"
[email protected]$Cell_Type[rownames([email protected])%in%paste0("Zhou_",sampleInfo$Sample[sampleInfo$Lineage=="PE"])]="Zhou_Hypo"
[email protected]$Cell_Type[rownames([email protected])%in%paste0("Zhou_",sampleInfo$Sample[sampleInfo$Lineage=="TE"])]="Zhou_TE"
[email protected]$Cell_Type[rownames([email protected])%in%paste0("Zhou_",sampleInfo$Sample[sampleInfo$Lineage=="EPI"])]="Zhou_Epi"
dat=embryo_integrated_zhou@assays$RNA@counts
select=rownames([email protected])[grepl("Own",rownames([email protected]))]
zhou_select=rownames([email protected])[grepl("Zhou",rownames([email protected]))]
#Own data is training data for the logistic regression, data from Zhou et al is regressed into it as test data
training_dat=dat[,select]
test_dat=dat[,zhou_select]
[email protected][select,"Cell_Type"]
fit=trainModel(refMat=training_dat,classes=classes)
saveRDS(fit,"logistic_regression_own_data_fit_zhou.Rdata")
preds=predictSimilarity(fit=fit,tgtData=test_dat,[email protected][zhou_select,"Cell_Type"],logits=F)
wilcox.test(preds[classes=="Zhou_Epi","Epi"],preds[classes=="Zhou_Epi","Hypo"])
wilcox.test(preds[classes=="Zhou_Epi","Epi"],preds[classes=="Zhou_Epi","TE"])
wilcox.test(preds[classes=="Zhou_Hypo","Hypo"],preds[classes=="Zhou_Hypo","Epi"])
wilcox.test(preds[classes=="Zhou_Hypo","Hypo"],preds[classes=="Zhou_Hypo","TE"])
wilcox.test(preds[classes=="Zhou_TE","TE"],preds[classes=="Zhou_TE","Epi"])
wilcox.test(preds[classes=="Zhou_TE","TE"],preds[classes=="Zhou_TE","Hypo"])
preds=preds[,c("Epi","Hypo","TE")]
note_color=rep('black',9)
note_color[t(preds)>0.5]="white"
pdf("zhou_own_logistic_regression.pdf")
heatmap.2(t(as.matrix(preds)),
density.info="none", # turns off density plot inside color legend
trace="none", # turns off trace lines inside the heat map
dendrogram="none",
notecol = "black",
col=colorRampPalette(brewer.pal(9,"Blues")[2:9])(100),
Rowv = F,
Colv = F,
scale='none',
key=F,
cellnote=round(t(as.matrix(preds)),digits=2),
cexRow=1.5,
cexCol=1.5,
notecex=1.0,
mar=c(10,6.5))
dev.off()
#---------------------------------
# Compare with Xiang et al.
xiang_fpkm=fread("GSE136447_555-samples-fpkm.txt.gz",data.table = F) #Get from GEO
xiang_genes=xiang_fpkm$"Gene Name"
xiang_genes[duplicated(xiang_genes)]=xiang_fpkm$"Gene ID"[duplicated(xiang_genes)]
xiang_genes[duplicated(xiang_genes)]=xiang_fpkm$"Gene_ID"[duplicated(xiang_genes)]
rownames(xiang_fpkm)=xiang_genes
xiang_fpkm=xiang_fpkm[,-c(1:7)]
sampleInfo=read.table("xiang_sampleinfo.txt",header=T)
include_xiang=c("D8_8", "D9A4", "D10A2", "D10A6", "D12A3", "D12A5", "D14A1")
#Set up seurat objet
embryo_xiang=CreateSeuratObject(counts = xiang_fpkm[,sampleInfo$Sample.ID[sampleInfo$Embryo.ID%in%include_xiang]])
embryo_xiang <- NormalizeData(object = embryo_xiang)
embryo_xiang <- ScaleData(object = embryo_xiang)
#Merge with own data - note: no batch correction as logistic regression doesn't rely on it
embryo_integrated_xiang=merge(x = embryo.integrated, y = embryo_xiang,
add.cell.ids=c("Own","Xiang"),merge.data = TRUE)
#Annotate own data into the four clusters
[email protected]$Cell_Type[[email protected]$seurat_clusters==0]="STB"
[email protected]$Cell_Type[[email protected]$seurat_clusters==1]="CTB"
[email protected]$Cell_Type[[email protected]$seurat_clusters==2]="Epi"
[email protected]$Cell_Type[[email protected]$seurat_clusters==3]="Hypo"
#
[email protected]$Cell_Type[rownames([email protected])%in%paste0("Xiang_",sampleInfo$Sample.ID[sampleInfo$Group=="PE"])]="Xiang_PrE"
#[email protected]$Cell_Type[rownames([email protected])%in%paste0("Xiang_",sampleInfo$Sample.ID[sampleInfo$Group=="ICM"])]="Xiang_ICM"
[email protected]$Cell_Type[rownames([email protected])%in%paste0("Xiang_",sampleInfo$Sample.ID[sampleInfo$Group=="EPI"])]="Xiang_Epi"
[email protected]$Cell_Type[rownames([email protected])%in%paste0("Xiang_",sampleInfo$Sample.ID[sampleInfo$Group=="STB"])]="Xiang_STB"
[email protected]$Cell_Type[rownames([email protected])%in%paste0("Xiang_",sampleInfo$Sample.ID[sampleInfo$Group=="CTB"])]="Xiang_CTB"
#[email protected]$Cell_Type[rownames([email protected])%in%paste0("Xiang_",sampleInfo$Sample.ID[sampleInfo$Group=="EVT"])]="Xiang_EVT"
[email protected]$Cell_Type[rownames([email protected])%in%paste0("Xiang_",sampleInfo$Sample.ID[sampleInfo$Group=="PSA-EPI"])]="Xiang_PSA-EPI"
dat=embryo_integrated_xiang@assays$RNA@counts
select=rownames([email protected])[grepl("Own",rownames([email protected]))]
xiang_select=rownames([email protected])[grepl("Xiang",rownames([email protected]))&!is.na([email protected]$Cell_Type)]
training_dat=dat[,select]
test_dat=dat[,xiang_select]
[email protected][select,"Cell_Type"]
fit=trainModel(refMat=training_dat,classes=classes)
saveRDS(fit,"logistic_regression_own_data_fit_xiang.Rdata")
preds=predictSimilarity(fit=fit,tgtData=test_dat,[email protected][xiang_select,"Cell_Type"],logits=F)
wilcox.test(preds[xiang_classes=="Xiang_Epi","Epi"],preds[xiang_classes=="Xiang_Epi","Hypo"])
wilcox.test(preds[xiang_classes=="Xiang_Epi","Epi"],preds[xiang_classes=="Xiang_Epi","CTB"])
wilcox.test(preds[xiang_classes=="Xiang_Epi","Epi"],preds[xiang_classes=="Xiang_Epi","STB"])
wilcox.test(preds[xiang_classes=="Xiang_PrE","Hypo"],preds[xiang_classes=="Xiang_PrE","Epi"])
wilcox.test(preds[xiang_classes=="Xiang_PrE","Hypo"],preds[xiang_classes=="Xiang_PrE","CTB"])
wilcox.test(preds[xiang_classes=="Xiang_PrE","Hypo"],preds[xiang_classes=="Xiang_PrE","STB"])
wilcox.test(preds[xiang_classes=="Xiang_CTB","CTB"],preds[xiang_classes=="Xiang_CTB","Epi"])
wilcox.test(preds[xiang_classes=="Xiang_CTB","CTB"],preds[xiang_classes=="Xiang_CTB","Hypo"])
wilcox.test(preds[xiang_classes=="Xiang_CTB","CTB"],preds[xiang_classes=="Xiang_CTB","STB"])
wilcox.test(preds[xiang_classes=="Xiang_STB","STB"],preds[xiang_classes=="Xiang_STB","Epi"])
wilcox.test(preds[xiang_classes=="Xiang_STB","STB"],preds[xiang_classes=="Xiang_STB","Hypo"])
wilcox.test(preds[xiang_classes=="Xiang_STB","STB"],preds[xiang_classes=="Xiang_STB","CTB"])
wilcox.test(preds[xiang_classes=="Xiang_PSA-EPI","Epi"],preds[xiang_classes=="Xiang_PSA-EPI","STB"])
wilcox.test(preds[xiang_classes=="Xiang_PSA-EPI","Epi"],preds[xiang_classes=="Xiang_PSA-EPI","Hypo"])
wilcox.test(preds[xiang_classes=="Xiang_PSA-EPI","Epi"],preds[xiang_classes=="Xiang_PSA-EPI","CTB"])
write.table(preds,"preds_xiang.txt")
rownames(preds)=c("Xiang_STB","Xiang_Epi","Xiang_PSA-EPI","Xiang_CTB")
preds=preds[c("Xiang_PSA-EPI","Xiang_Epi","Xiang_CTB","Xiang_STB"),]
pdf("xiang_own_logistic_regression.pdf")
heatmap.2(t(as.matrix(preds)),
density.info="none", # turns off density plot inside color legend
trace="none", # turns off trace lines inside the heat map
dendrogram="none",
notecol = "black",
col=colorRampPalette(brewer.pal(9,"Blues")[2:9])(100),
Rowv = F,
Colv = F,
scale='none',
key=F,
cellnote=round(t(as.matrix(preds)),digits=2),
cexRow=1.5,
cexCol=1.5,
notecex=1.0,
mar=c(10,6.5))
dev.off()
#----------------------
# Compare integrated epiblast dataset to cell lines
embryo_integrated_stirparo=readRDS("embryo_integrated_stirparo.Rdata")
epi_cells=rownames([email protected])[[email protected]$Epi!="0"]
[email protected]$Epi[[email protected]$Epi!="0"]
embryo_epi=subset(embryo_integrated_stirparo,cells = epi_cells)
training_dat=embryo_epi@assays$RNA@counts
classes=epi_state
fit=trainModel(refMat=training_dat,classes=classes)
saveRDS(fit,"logistic_regression_epiblast_fit.Rdata")
#Data from Takashima et al, 2014
cell_lines_raw = read.table("Abundance_CellLine.txt")
cell_lines_ensembl=rownames(cell_lines_raw)
#Read in ensembl annotation for gene name conversion
ensembl_geneid=read.table("ensembl_geneid.txt",header=T,sep="\t")
ensembl_geneid=ensembl_geneid[ensembl_geneid$Ensembl.gene.ID!="",]
genes=ensembl_geneid$Approved.symbol
names(genes)=ensembl_geneid$Ensembl.gene.ID
genes_cell_line=genes[cell_lines_ensembl]
genes_cell_line[duplicated(genes_cell_line)] = cell_lines_ensembl[duplicated(genes_cell_line)]
cell_lines_raw=cell_lines_raw[!is.na(genes_cell_line),]
genes_cell_line=genes_cell_line[!is.na(genes_cell_line)]
rownames(cell_lines_raw)=genes_cell_line
test_dat=cell_lines_raw
preds=predictSimilarity(fit=fit,tgtData=test_dat,logits=F,minGeneMatch=0.1)
write.table(preds,"preds_cell_lines_takashima.txt")
sample_names=c("H9_reset_R2","H9_reset_R3","H9_reset_R1","H9_R3","H9_R1","H9_R2")
rownames(preds)=sample_names
preds=preds[order(rownames(preds)),c("ICM","Pre-Epi","Post-Epi")]
note_color=rep('black',24)
note_color[preds>0.5]="white"
#Fig. 1g
pdf("Logistic_regression_cell_line_takashima.pdf",useDingbats = F,height=4.2,width=6)
heatmap.2(t(as.matrix(preds)),
density.info="none", # turns off density plot inside color legend
trace="none", # turns off trace lines inside the heat map
dendrogram="none",
notecol = rev(note_color),
col=colorRampPalette(brewer.pal(9,"Blues")[2:9])(100),
Rowv = F,
Colv = F,
scale='none',
key=F,
cellnote=round(t(as.matrix(preds)),digits=2),
cexRow=1.5,
notecex=1.0,
ColSideColors=c(rep('firebrick',3),rep('steelblue',3)),
mar=c(10,6.5))
dev.off()
#Theunissen et al.
#Get data from GEO
theunissen=matrix(0,nrow=63682,ncol=5)
n=1
for(x in paste0("GSM22186",c(60,68:71))){
data=fread(paste0(x,".pileup.gz"),sep="\t",data.table=F)
theunissen[,n]=data[,2]
n=n+1
}
rownames(theunissen)=data[,1]
colnames(theunissen)=c("Male Primed ES - WIBR1 (XY)","Male Naive ES - WIN1 (XY)","Male Naive ES - WIN1 (XY) - 2","Naive - WIBR2","Naive - WIBR3")
theunissen=theunissen[rownames(theunissen)%in%ensembl_convert$Gene.stable.ID,]
gene_meta=read.table("../../Hypoblast/May_2020/GTEX_BulkGenes.tsv",sep="\t",header=T)
gene_names=gene_meta$geneID
gene_names[duplicated(gene_names)]=gene_meta$geneID[duplicated(gene_names)]
gene_length=gene_meta$bp_length
names(gene_length)=gene_names
gene_length=gene_length[!is.na(gene_length)]
tpm3 <- function(counts,len=gene_length){
x <- counts/len
return(t(t(x)*1e6/colSums(x)))
}
theunissen=theunissen[rownames(theunissen)%in%names(gene_length),]
theunissen_tpm=tpm3(theunissen,len=gene_length[rownames(theunissen)])
rownames(theunissen)=ensembl[rownames(theunissen)]
rownames(theunissen_tpm)=ensembl[rownames(theunissen_tpm)]
preds=predictSimilarity(fit=fit,tgtData=theunissen,logits=F,minGeneMatch=0.1)
preds=preds[,c("ICM","Pre-Epi","Peri-Epi","Post-Epi")]
note_color=rep('black',nrow(preds)*ncol(preds))
note_color[preds>0.5]="white"
#Extended data Fig 5a
pdf("Logistic_regression_theunissen_4stg.pdf",useDingbats = F,height=6,width=5)
heatmap.2(t(as.matrix(preds)),
density.info="none", # turns off density plot inside color legend
trace="none", # turns off trace lines inside the heat map
dendrogram="none",
notecol = rev(note_color),
col=colorRampPalette(brewer.pal(9,"Blues")[2:9])(100),
Rowv = F,
Colv = F,
scale='none',
key=F,
breaks=col_breaks,
cellnote=round(t(as.matrix(preds)),digits=3),
cexRow=1,
notecex=0.7,
#ColSideColors=c(rep('firebrick',3),rep('steelblue',3)),
mar=c(20,6.5))
dev.off()
write.csv(preds,"Logistic_regression_theunissen_4stg.csv")
#Rostovskaya et al.
rostovskaya=fread("GSE123055_counts.txt.gz",sep="\t",data.table = F)
rownames(rostovskaya)=rostovskaya$ID
rostovskaya=rostovskaya[,-1]
rostovskaya=rostovskaya[,colnames(rostovskaya)!="V53"]
rostovskaya=rostovskaya[rownames(rostovskaya)%in%ensembl_convert$Gene.stable.ID,]
gene_length=gene_length[1:(length(gene_length)-2)]
gene_length=gene_length[!is.na(gene_length)]
tpm3 <- function(counts,len=gene_length){
x <- counts/len
return(t(t(x)*1e6/colSums(x)))
}
rostovskaya=rostovskaya[rownames(rostovskaya)%in%names(gene_length),]
rostovskaya_tpm=tpm3(rostovskaya,len=gene_length[rownames(rostovskaya)])
rownames(rostovskaya)=ensembl[rownames(rostovskaya)]
rownames(rostovskaya_tpm)=ensembl[rownames(rostovskaya_tpm)]
preds=predictSimilarity(fit=fit,tgtData=rostovskaya_tpm,logits=F,minGeneMatch=0.1)
preds=preds[order(rownames(preds)),c("ICM","Pre-Epi","Peri-Epi","Post-Epi")]
note_color=rep('black',nrow(preds)*ncol(preds))
note_color[preds>0.5]="white"
#Extended data Fig 5b
pdf("Logistic_regression_rostovskaya_4stg.pdf",useDingbats = F,height=6.2,width=25)
heatmap.2(t(as.matrix(preds)),
density.info="none", # turns off density plot inside color legend
trace="none", # turns off trace lines inside the heat map
dendrogram="none",
notecol = rev(note_color),
col=colorRampPalette(brewer.pal(9,"Blues")[2:9])(100),
Rowv = F,
Colv = F,
scale='none',
key=F,
cellnote=round(t(as.matrix(preds)),digits=3),
cexRow=1.5,
notecex=0.7,
breaks=col_breaks,
#ColSideColors=c(rep('firebrick',3),rep('steelblue',3)),
mar=c(20,6.5))
dev.off()
write.csv(preds,"Logistic_regression_rostovskaya_4stg.csv")
#