jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.29k stars 224 forks source link

enrichedheatmap #1070

Open feanaros opened 1 year ago

feanaros commented 1 year ago

HI, I was trying to plot my enriched heatmap using a normalized matrix. Unfortunately, when I try to plot it, I can see only half of the heatmap plotted. Could you help me to see where the error comes from?


library(Seurat)
try = RegionMatrix(obj, regions = hub_df_cluster_3_module_4_TSS_gr, assay="ATAC", group.by = "treatment_timepoint_cluster", idents = c("3_KO_d8", "3_WT_d8", "3_KO_d6", "3_WT_d6"), key = "p", upstream = 1000, downstream = 1000, verbose = TRUE)

c=try@assays$ATAC@positionEnrichment$picchi$`3_KO_d8`
rownames(c) <- hub_df_cluster_3_module_4_TSS$gene_name

mat_kod8= as.normalizedMatrix(c, k_upstream = 1001, k_downstream = 1000, k_target = 0, extend = 1000, smooth = TRUE, keep = c(0, 0.95))
EnrichedHeatmap(mat_kod8, name = "fragment ko", column_title = "Enrichment KO_d8", use_raster= T)

jokergoo_try

If I remove rows with a tot of zero from matrix, I GET THIS


c_df= as.data.frame(c)
c_df$tot = rowSums(c_df)
c_mat = c_df[c_df$tot != 0, ]
c_mat= as.matrix(c_mat[,-2002])
mat_kod8= as.normalizedMatrix(c_mat, k_upstream = 1001, k_downstream = 1000, k_target = 0, extend = 1000, smooth = TRUE, keep = c(0, 0.95))
EnrichedHeatmap(mat_kod8, name = "fragment ko", column_title = "Enrichment KO_d8", use_raster= T)

REMOVE-ZERO

But if I do manually the coverage of some genes that have the total nr=0, get this


c_zero= as.data.frame(c_df[c_df$tot == 0, ])
c_zero$name= rownames(c_zero)
rownames(c_zero)
 [1] "Cdh11"         "Pbx1"          "Grid2"         "Tmtc1"         "Emilin1"       "Lima1"         "Klf12"         "Slc2a13"      
 [9] "Mfap4"         "Astn2"         "Mrc2"          "Eda"           "Adgrl3"        "Trps1"         "Stat3"         "Pdgfrb"       
[17] "Ptprd"         "Lhfpl2"        "Col25a1"       "Pcolce"        "Col13a1"       "Tmem131l"      "Lpp"           "Junb"         
[25] "Ghr"           "Tbx1"          "Sncaip"        "Fbn1"          "Dock1"         "Gab2"          "Ppm1l"         "Zeb1"         
[33] "Lix1"          "Nrg1"          "Egr1"          "Arhgap28"      "Basp1"         "Hmcn1"         "Sobp"          "Colec12"      
[41] "Kalrn"         "Fosb"          "Foxn3"         "Boc"           "2610307P16Rik" "Arhgap26"      "Ror1"          "4930438E09Rik"
[49] "Cntln"         "Six1"          "Prickle1"      "Gas2"          "Edil3"         "Tle4"          "Kcnq5"        

 DefaultAssay(prova) <-"ATAC"
 cI= CoveragePlot(
  object = try,
  region =  hub_df_cluster_3_module_4_TSS[hub_df_cluster_3_module_4_TSS$gene_name == c_zero$name[1],]$region,
  extend.upstream = 10000,
  extend.downstream = 10000,
  group.by = "treatment_timepoint_cluster",
  idents = c("3_KO_d8", "3_WT_d8"),
  features =  hub_df_cluster_3_module_4_TSS[hub_df_cluster_3_module_4_TSS$gene_name == c_zero$name[1],]$gene_name,
  peaks = T,
  annotation = T)
cI 

ci

To generate the matrix, I used Seurat Regionmatrix()

jokergoo commented 1 year ago

You need to check the matrix mat_kod8 since it is not generated by EnrichmentHeatmap. EnrichedHeatmap() is basically a wrapper on Heatmap() but with a customized column ordering. It does not modify the original data.

feanaros commented 1 year ago

Ok, thank you. So I need to check why this is happening. With other regions, however, it works fine.

feanaros commented 1 year ago

Hello @jokergoo I checked my Matrix. Mat_kod8 was converted into a Matrix readable in enrichedHeatmap using your function as.normalizedMatrix(). It does a kind of normalization, but I suppose that It doesnt normalize for Number of cells. Can you explain me which normalization It used for the conversione?