jianhong / ChIPpeakAnno

11 stars 4 forks source link

anno gene in heatmap #43

Open li1311139481 opened 1 week ago

li1311139481 commented 1 week ago

Hello, thank you for your work. I used the featureAlignedExtendSignal function to process differential peaks. Then I used featureAlignedHeatmap to create a heatmap.

sig <- featureAlignedExtendSignal(bamfiles = totalbamfiles, 
                                  feature.gr = reCenterPeaks(dbObj.report[1:1500], width=1), 
                                  upstream = upstream,
                                  downstream = downstream,
                                  n.tile=n.tile, 
                                  fragmentLength=fragmentLength,
                                  librarySize=librarySize)
peaks <- reCenterPeaks(dbObj.report[1:1500], width=1010)
peaks_Anno <- annotatePeak(peaks,
    TxDb = TxDb.Mmusculus.UCSC.mm10.knownGene,
    annoDb = "org.Mm.eg.db"
)
featureAlignedHeatmap(sig, peaks_Anno@anno, upper.extreme = maxvalue,
                      zeroAt=0.5, n.tile=n.tile,#annoMcols=c("anno_gene"),
                      color = colorRampPalette(rev(brewer.pal(n=7, name = "RdBu")))(100))

image

I get the result. but i want anno the heatmap using some gene. As you can see, my input is differential peaks, and i annotate the peaks to gene. If I only want to annotate the positions of Pdcd1 and Havcr2 genes in the heatmap, and if I use the annoMcols parameter to specify the SYMBOL column in peaks_Anno@anno, it will annotate all genes. This does not meet my needs. How can I clearly annotate the genes I want? just like this image

hukai916 commented 1 week ago

Have you tried to mask the unwanted genes with "":

peaks_Anno@anno$anno_gene[!(peaks_Anno@anno$anno_gene %in% c("Pdcd1", "Havcr2"))] <- ""
li1311139481 commented 1 week ago

Have you tried to mask the unwanted genes with "":

peaks_Anno@anno$anno_gene[!(peaks_Anno@anno$anno_gene %in% c("Pdcd1", "Havcr2"))] <- ""

Thanks for your help If I use "" to hide genes, I am actually grouping all the genes I don't need to annotate into one category. This would result in a huge anno_block. I don't know how to describe it, but in ComplexHeatmap it's called anno_block. While I want the genes I want to annotate to form a separate anno_block, its position is always squeezed to the top or bottom edge by the "" anno_block. And since a gene only represents one row, it is difficult to see where the annotated genes are located in the anno_block.

hukai916 commented 1 week ago

The anno_block was caused by the sortBy argument in the featureAlignedHeatmap function, where it first sorts by annoMcols followed by the signals of the samples. That means, if you set sortBy = NULL, it won't create anno_block, but you will lose the ordering by signals too. You can input a pre-sorted feature.gr while setting sortBy = NULL to keep the ordering.

li1311139481 commented 5 days ago

Thank you for your reply. I tried to use sortby=NULL, and understand how do you sorted. But featureAlignedSignal gave me a headache. I try to sort using the rowMeans of the first sample.

cvglists <- lapply(cvglists, function(x) {
    x <- x[names(sort(rowMeans(cvglists[[1]]),decreasing = T)),]
    return(x)
})
feature.gr <- peaks_Anno@anno[match(names(sort(rowMeans(cvglists[[1]]),decreasing = T)), peaks_Anno@anno$SYMBOL),]
featureAlignedHeatmap(cvglists, feature.gr, upper.extreme = maxvalue,
                      zeroAt=0.5, n.tile=n.tile,sortBy=NULL,annoMcols=c("anno_gene"),
                      color = colorRampPalette(rev(brewer.pal(n=7, name = "RdBu")))(100))

However. My order is so simple that it doesn't match the graph you drew this is my image This is yours

featureAlignedHeatmap(cvglists, feature.gr, upper.extreme = maxvalue,
                      zeroAt=0.5, n.tile=n.tile,annoMcols=c("anno_gene"),
                      color = colorRampPalette(rev(brewer.pal(n=7, name = "RdBu")))(100))

image

In addition, anno_block is still created after I specify sortby=NULL