#Differential Expression Analysis # 2. load seurat object
#Load Seurat Object L7
load("../../../0-IMP-OBJECTS/Harmony_integrated_All_samples_Merged_with_PBMC10x_with_harmony_clustering.Robj")
All_samples_Merged
An object of class Seurat
64169 features across 59355 samples within 6 assays
Active assay: SCT (27417 features, 3000 variable features)
3 layers present: counts, data, scale.data
5 other assays present: RNA, ADT, prediction.score.celltype.l1, prediction.score.celltype.l2, prediction.score.celltype.l3
6 dimensional reductions calculated: integrated_dr, ref.umap, pca, umap, harmony, umap.harmony
DimPlot(All_samples_Merged, reduction = "umap.harmony", group.by = "cell_line",label = T, label.box = T)
DimPlot(All_samples_Merged, reduction = "umap.harmony", group.by = "Harmony_snn_res.0.9",label = T, label.box = T)
#Celltype tables based on cluster
# Create a contingency table of cell line vs clusters
cluster_cell_line_table <- table(All_samples_Merged$cell_line, All_samples_Merged$Harmony_snn_res.0.9)
# Print the table to check its structure
print(cluster_cell_line_table)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
L1 2 0 0 125 0 0 0 1 2012 0 3038 16 0 0 0 1 0 25 593 0 12 0 0
L2 0 1 0 4159 0 1 2 1 1722 0 9 0 0 0 0 0 0 7 22 0 11 0 0
L3 2 3472 2670 0 0 1 30 1 0 0 1 0 4 129 0 1 3 6 1 68 37 0 0
L4 0 1736 1744 0 0 3 520 3 0 0 2 7 158 1840 1 12 27 18 2 57 18 0 2
L5 1 0 1 0 1827 6 423 2998 0 272 0 0 0 0 0 0 141 12 3 320 17 0 1
L6 1 10 4 0 550 2 1535 92 0 2506 0 0 0 0 1 0 151 23 8 107 158 0 0
L7 1 2 1 0 1879 4 1249 715 0 835 0 0 0 0 0 0 538 19 2 57 29 0 0
PBMC 2694 0 1 0 0 2685 24 0 4 0 6 51 1096 0 416 744 0 428 2 3 81 3 91
PBMC_10x 3413 2 2 0 0 1199 30 0 7 0 14 2792 936 1 930 130 6 219 15 0 209 222 0
23 24
L1 0 0
L2 0 0
L3 2 0
L4 0 0
L5 0 0
L6 0 0
L7 0 0
PBMC 6 19
PBMC_10x 35 0
# Save the table as a CSV file
write.csv(cluster_cell_line_table, "cluster_cell_line_table.csv")
# Convert the table to a numeric matrix for heatmap generation
cluster_cell_line_matrix <- as.matrix(cluster_cell_line_table)
# Generate the heatmap using pheatmap
library(pheatmap)
pheatmap(cluster_cell_line_matrix,
cluster_rows = TRUE, # Cluster rows (cell lines)
cluster_cols = TRUE, # Cluster columns (clusters)
display_numbers = TRUE, # Display cell counts in the heatmap
color = colorRampPalette(c("white", "red"))(50), # Color gradient from white to red
main = "Cell Line vs Cluster Heatmap")
# Save the heatmap as a PNG (Optional)
png("cluster_cell_line_heatmap.png", width = 2200, height = 600)
pheatmap(cluster_cell_line_matrix,
cluster_rows = TRUE,
cluster_cols = TRUE,
display_numbers = TRUE,
color = colorRampPalette(c("white", "red"))(50),
main = "Cell Line vs Cluster Heatmap")
dev.off()
png
3
# Save the heatmap as a PDF (Optional)
pdf("cluster_cell_line_heatmap.pdf", width = 22, height = 8)
pheatmap(cluster_cell_line_matrix,
cluster_rows = TRUE,
cluster_cols = TRUE,
display_numbers = TRUE,
color = colorRampPalette(c("white", "red"))(50),
main = "Cell Line vs Cluster Heatmap")
dev.off()
png
3