jokergoo / EnrichedHeatmap

make enriched heatmap which visualizes the enrichment of genomic signals to specific target regions.
http://jokergoo.github.io/EnrichedHeatmap/
Other
187 stars 25 forks source link

Strandness information of signal and targte GRanges seems ignored in the calculation of normalizeToMatrix #76

Open SoManyPepople opened 1 year ago

SoManyPepople commented 1 year ago

Hi, Thanks for development of this nice tool. I found no parameter to set strandness in the function "normalizeToMatrix", so I try a test to know whether the strandness of the input GRange objects were adopted in the calculation.

Briefly, I switch the strandness of target GRanges object (GR.utr3), and found the results seem just reversed (window 1 = window20, window2 = window18).

save the original GR

GR.utr3_back <- GR.utr3

set the strand of GR to the opposite

strand(GR.utr3) <- if_else(as.character(strand(GR.utr3))=="+","-","+")

obtain the normalized matrix for new GR

mat <- normalizeToMatrix(GRL.m6A_peaks[[s]], GR.utr3, value_column = "EnrichFold",mean_mode = "w0",extend = 0,k=20,background = 0, smooth=FALSE, target_ratio = 1)
mat.dt <- as.data.table(mat,keep.rownames = "tx") %>% group_by(tx) %>% mutate_at(paste0("t",1:20), mean) %>% distinct() %>% as.data.table()
mat.dt[tx == "ENST00000395764.5",]

tx t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 1: ENST00000395764.5 7.047711 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795

obtain the normalized matrix for original GR

mat <- normalizeToMatrix(GRL.m6A_peaks[[s]], GR.utr3_back, value_column = "EnrichFold",mean_mode = "w0",extend = 0,k=20,background = 0, smooth=FALSE, target_ratio = 1)
mat.dt <- as.data.table(mat,keep.rownames = "tx") %>% group_by(tx) %>% mutate_at(paste0("t",1:20), mean) %>% distinct() %>% as.data.table()
mat.dt[tx == "ENST00000395764.5",]

tx t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20 1: ENST00000395764.5 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 9.866795 7.047711

The only solution seems to seperate the signal and target GRanges by their strandness and perform normalizeToMatrix speperately and merged together.

jokergoo commented 1 year ago

The strands of the "target regions" are taken into consideration. The strands of "signal regions" are ignored.

See the following examples:

load(system.file("extdata", "chr21_test_data.RData", package = "EnrichedHeatmap"))
tss = promoters(genes, upstream = 0, downstream = 1)

mat1 = normalizeToMatrix(H3K4me3, tss, value_column = "coverage", 
    extend = 5000, mean_mode = "w0", w = 50)

ht1 = EnrichedHeatmap(mat1, col = c("white", "red"), name = "H3K4me3", column_title = "normal strand")

tss2 = tss
strand(tss2) = ifelse(strand(tss) == "-", "+", "-")

mat2 = normalizeToMatrix(H3K4me3, tss2, value_column = "coverage", 
    extend = 5000, mean_mode = "w0", w = 50)

ht2 = EnrichedHeatmap(mat2, col = c("white", "red"), name = "H3K4me3", column_title = "reversed strand")

tss3 = tss
strand(tss3) = "*"

mat3 = normalizeToMatrix(H3K4me3, tss3, value_column = "coverage", 
    extend = 5000, mean_mode = "w0", w = 50)

ht3 = EnrichedHeatmap(mat3, col = c("white", "red"), name = "H3K4me3", column_title = "ignore strand")

ht1 + ht2 + ht3
image