Open Yijia-Jiang opened 1 year ago
Hi,
I am not a developer of this tool. But I used following code to reproduce heatmap using ComplexHeatmap
package. it is easier to work with ComplexHeatmap
than working with heatmap.3
. It would be nice if developers consider incorporating ComplexHeatmap
instead.
library(copykat)
library(ComplexHeatmap)
library(circlize)
pid <- "PatientX"
copykat.test <- copykat(rawmat=exp.rawdata, id.type="S", ngene.chr=5, win.size=25, KS.cut=0.1, sam.name=(paste0(pid)), distance="euclidean", norm.cell.names="",output.seg="TRUE", plot.genes="FALSE", genome="hg20",n.cores=16)
pred.test <- data.frame(copykat.test$prediction)
pred.test <- pred.test[-which(pred.test$copykat.pred=="not.defined"),] ##remove undefined cells
CNA.test <- data.frame(copykat.test$CNAmat)
mat <- t(CNA.test[,4:ncol(CNA.test)])
com.preN <- pred.test$copykat.pred
hcc <- hclust(parallelDist::parDist(t(mat),threads =8, method = "euclidean"), method = "ward.D2")
hc.umap <- cutree(hcc,2)
roworder = hcc$order
hc.cut <- cutree(hcc,2)
CNA.testX <- CNA.test
CNA.testX$chrom <- paste0("chr",CNA.testX$chrom)
chr_cols <- c("chr1" = "black", "chr2" = "grey", "chr3" = "black", "chr4" = "grey", "chr5" = "black", "chr6" = "grey", "chr7" = "black", "chr8" = "grey", "chr9" = "black", "chr10" = "grey", "chr11" = "black", "chr12" = "grey", "chr13" = "black", "chr14" = "grey", "chr15" = "black", "chr16" = "grey", "chr17" = "black", "chr18" = "grey", "chr19" = "black", "chr20" = "grey", "chr21" = "black", "chr22" = "grey", "chr23" = "black", "chrX" = "grey", "chrY" = "black", "chrMT" = "grey")
topAnnotation <- HeatmapAnnotation(chromosomes = CNA.testX$chrom, col = list(chromosomes = chr_cols))
leftAnnotation <- rowAnnotation(cluster = paste0("c",hc.cut), pred=com.preN, col = list(cluster = c("c1" = "#088A85", "c2" = "#DBA901"), pred = c("diploid" = "#088A68", "aneuploid" = "#DF013A") ) )
col_fun = colorRamp2(c(min(mat), 0, max(mat)), c("#08088A", "white", "#B40431"))
ht1 <- Heatmap(mat, left_annotation = leftAnnotation, row_order = roworder, top_annotation=topAnnotation, col=col_fun, show_row_names=F, show_column_names=F, cluster_columns=F,clustering_distance_columns = "euclidean",clustering_method_columns = "ward.D2")
pdf(paste0(pid,"_CNA.test_heatmap_complexHeatmap_ward.D2.pdf"))
draw(ht1)
dev.off()
Thanks for sharing the code
@decodebiology
But
col_fun
is missing
Thanks for sharing the code @decodebiology But
col_fun
is missing
Now added col_fun
Hi, I am using the code provided in the tutorial and cannot to generate both heatmaps using the following code
The error shows:
Error in heatmap.3(t(as.matrix(CNA.test[, 4:ncol(CNA.test)])), dendrogram = "r", : `x' must be a numeric matrix
I also tried code to plot tumor heatmap:
Another error occurs: Error in plot.new() : figure margins too large
Can you help?