-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFig7.correlation.R
64 lines (42 loc) · 1.96 KB
/
Fig7.correlation.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
library(Seurat)
library(pheatmap)
library(ggplot2)
ihlca = readRDS(file=".Data/HLCA_v1.rds")
hlcellref = readRDS(file=".Data/LungMAP_HumanLung_CellRef.v1.rds")
# Create pseudobulk profiles
DefaultAssay(ihlca) = "RNA"
DefaultAssay(hlcellref) = "RNA"
ihlca = SetIdent(ihlca, [email protected]$ann_finest_level)
ihlca.avg = AverageExpression(ihlca, assay="RNA", return.seurat = T)
ihlca.avg = FindVariableFeatures(ihlca.avg, nfeatures = 2000)
hlcellref = SetIdent(hlcellref, [email protected]$celltype_level3)
cellref.avg = AverageExpression(hlcellref, assay="RNA", return.seurat = T)
cellref.avg = FindVariableFeatures(cellref.avg, nfeatures = 2000)
# identify highly variable genes (HVG)
hvg.common = union(ihlca.avg@[email protected],
cellref.avg@[email protected])
hvg.common = hvg.common[which(hvg.common %in% rownames(cellref.avg@assays$RNA@data))]
hvg.common = hvg.common[which(hvg.common %in% rownames(ihlca.avg@assays$RNA@data))]
# scale the expression of HVG
ihlca.avg = ScaleData(ihlca.avg, features = hvg.common)
cellref.avg = ScaleData(cellref.avg, features = hvg.common)
ihlca.data = ihlca.avg@[email protected]
cellref.data = cellref.avg@[email protected]
colnames(ihlca.data) = paste0(colnames(ihlca.data), ".iHLCA")
colnames(cellref.data) = paste0(colnames(cellref.data), ".CellRef")
tmp = cbind(ihlca.data, cellref.data[rownames(ihlca.data), ])
any(is.na(tmp))
# calcualte correlations
viz = cor(tmp)
# visualize correlations and hierarchical clustering of pseudobulk profiles
pheatmap::pheatmap(viz, clustering_method = "average",
filename = "Figure_7A.tiff", width=20, height=19)
# save source data
sourcedata = list(hvg.common=hvg.common, correlations=viz)
save(sourcedata, file="Figure_7A.sourcedata.rda")
viz = sourcedata$correlations
write.table(viz, file="Figure_7A.correlations.txt", sep=",", col.names = T, row.names = T, quote = F)
#sessionInfo
sink("sessionInfo.txt")
sessionInfo()
sink()