Comments (5)
It is possible to separate clusters by adding white space when you specify some larger number under "change data options" - "Number of clusters in rows" or "Number of clusters in columns".
from clustvis.
Thank you for getting back to me. I am using r to generate heatmaps. I am using no cluster option for columns (clustDistCols = NA) but I was wondering if it is possible to add a gap manually between columns in the heatmap to separate groups similar to (gaps_col) or (gaps_row) in pheatmap.
Thanks again appreciate your help
from clustvis.
Thanks for the clarification. This is not possible indeed at the moment.
I will think a bit what would be the best solution here.
from clustvis.
Thanks for your response. Actually, I was able to add the row/column gap option by modifying your original code as below.
Thanks for the amazing package!
Regards
createHeatmap2 = function(clust, nbrClustersRows, nbrClustersCols, colorAnnoRow, colorAnnoCol, legendColorScheme, plotWidth, plotRatio, colorRangeMin, colorRangeMax, matrixColorScheme, revScheme, cellBorder, fontSizeGeneral, showNumbers, fontSizeNumbers, precisionNumbers, showRownames, fontSizeRownames, showColnames, fontSizeColnames, showAnnoTitlesRow, showAnnoTitlesCol, maxAnnoLevels,gapscol,gapsrow,cellwidth , cellheight,legend ,annotation_legend ){
matFinal = clust$matFinal
annoCol = clust$annoCol
annoRow = clust$annoRow
hcRows = clust$hcRows
hcCols = clust$hcCols
captionInfo = clust$captionInfo
#filter row annotations:
if(!is.null(annoRow) && (length(colorAnnoRow) == 1) && all(is.na(colorAnnoRow))){
colorAnnoRow = 1:ncol(annoRow) #keep all
}
if(!is.null(annoRow) && length(colorAnnoRow) > 0){
if(is.numeric(colorAnnoRow)) colorAnnoRow = colnames(annoRow)[colorAnnoRow]
if(!all(colorAnnoRow %in% colnames(annoRow))) return(frame())
annoRow2 = annoRow[, colorAnnoRow, drop = FALSE]
} else {
annoRow2 = NA
}
#filter column annotations:
if(!is.null(annoCol) && (length(colorAnnoCol) == 1) && is.na(colorAnnoCol)){
colorAnnoCol = 1:ncol(annoCol) #keep all
}
if(!is.null(annoCol) && length(colorAnnoCol) > 0){
if(is.numeric(colorAnnoCol)) colorAnnoCol = colnames(annoCol)[colorAnnoCol]
if(!all(colorAnnoCol %in% colnames(annoCol))) return(frame())
annoCol2 = annoCol[, colorAnnoCol, drop = FALSE]
} else {
annoCol2 = NA
}
#calculate default values if needed:
hmOptions = calculateHmOptions(matFinal)
if(is.na(colorRangeMin)) colorRangeMin = hmOptions$colorRangeMin
if(is.na(colorRangeMax)) colorRangeMax = hmOptions$colorRangeMax
if(is.na(fontSizeRownames)) fontSizeRownames = hmOptions$fontSizeRownames
if(is.na(fontSizeColnames)) fontSizeColnames = hmOptions$fontSizeColnames
#remove annotations with large number of levels:
alr = annoLevels(annoRow2, maxAnnoLevels)
alc = annoLevels(annoCol2, maxAnnoLevels)
annoRow2 = alr$anno
annoCol2 = alc$anno
removed = c(alr$removed, alc$removed)
if(!is.null(removed)){
message = paste0("The following annotations have more than ", maxAnnoLevels, " levels and were removed from the plot: '", paste0(removed, collapse = "', '"), "'.")
} else {
message = NULL
}
#image dimensions:
picwIn = plotWidth / 2.54
pichIn = picwIn * plotRatio
dotsPerCm = 96 / 2.54 #how many points per cm
picw = picwIn * 2.54 * dotsPerCm
pich = pichIn * 2.54 * dotsPerCm
#color scheme:
colScheme = RColorBrewer::brewer.pal(n = 7, name = matrixColorScheme)
if(revScheme) colScheme = rev(colScheme)
nbrColors = 100
colVec = colorRampPalette(colScheme)(nbrColors)
colBreaks = seq(colorRangeMin, colorRangeMax, length.out = nbrColors + 1)
#outside the specified range, set color to respective min/max color:
if(colorRangeMin != hmOptions$colorRangeMin){
colVec = c(head(colVec, 1), colVec)
colBreaks = c(hmOptions$colorRangeMin, colBreaks)
}
if(colorRangeMax != hmOptions$colorRangeMax){
colVec = c(colVec, tail(colVec, 1))
colBreaks = c(colBreaks, hmOptions$colorRangeMax)
}
#current implementation of pheatmap reverses the annotations:
annoRow2 = rev(annoRow2)
annoCol2 = rev(annoCol2)
#calculate annotation colors, default ones are sometimes strange
legendColors = c(lapply(annoRow2, calcAnnoLegendColors, legendColorScheme), lapply(annoCol2, calcAnnoLegendColors, legendColorScheme))
legendColors = legendColors[sapply(legendColors, length) > 0] #default colors if not factor or character
q = pheatmap::pheatmap(matFinal,
annotation_row = annoRow2, annotation_col = annoCol2, annotation_colors = legendColors,
cluster_rows = hcRows, cluster_cols = hcCols,
cutree_rows = nbrClustersRows, cutree_cols = nbrClustersCols,
color = colVec, breaks = colBreaks,
border_color = cellBorder,
show_rownames = showRownames, fontsize_row = fontSizeRownames,
show_colnames = showColnames, fontsize_col = fontSizeColnames,
annotation_names_row = showAnnoTitlesRow, annotation_names_col = showAnnoTitlesCol,
display_numbers = showNumbers, number_format = paste0("%.", precisionNumbers, "f"),
fontsize = fontSizeGeneral, fontsize_number = fontSizeNumbers,
width = picwIn, height = pichIn, silent = TRUE,gaps_col=gapscol,gaps_row=gapsrow,cellwidth = cellwidth, cellheight = cellwidth,legend = legend,annotation_legend=annotation_legend
)
graphics.off()
caption = createCaption(type = "hm", info = captionInfo)
if(class(hcRows) != "hclust"){
wr = 1:nrow(matFinal)
} else {
wr = q$tree_row$order
}
if(class(hcCols) != "hclust"){
wc = 1:ncol(matFinal)
} else {
wc = q$tree_col$order
}
cells = matFinal[wr, wc, drop = FALSE]
list(q = q, pich = pich, picw = picw, pichIn = pichIn, picwIn = picwIn, message = message, caption = caption, cells = cells)
}
generateHeatmapedited = function(proc, showImputed = TRUE, transpose = FALSE, clustDistRows = "correlation", clustMethodRows = "average", treeOrderingRows = NA, nbrClustersRows = 1, clustDistCols = "correlation", clustMethodCols = "average", treeOrderingCols = NA, nbrClustersCols = 1, colorAnnoRow = NA, colorAnnoCol = NA, legendColorScheme = "Set1", plotWidth = 25, plotRatio = 0.8, colorRangeMin = NA, colorRangeMax = NA, matrixColorScheme = "RdBu", revScheme = TRUE, cellBorder = "grey60", fontSizeGeneral = 10, showNumbers = FALSE, fontSizeNumbers = 12, precisionNumbers = 2, showRownames = TRUE, fontSizeRownames = NA, showColnames = TRUE, fontSizeColnames = NA, showAnnoTitlesRow = TRUE, showAnnoTitlesCol = TRUE, maxAnnoLevels = 50,gapscol=NULL,gapsrow=NULL,cellwidth = NA, cellheight = NA,legend = TRUE,annotation_legend=TRUE){
if(!(class(proc) %in% c("proc", "NULL"))){
stop("class of the proc parameter is incorrect!")
}
trans = transposeMatrix(proc, showImputed = showImputed, transpose = transpose)
clust = clusterMatrix(trans, clustDistRows = clustDistRows, clustMethodRows = clustMethodRows, treeOrderingRows = treeOrderingRows, clustDistCols = clustDistCols, clustMethodCols = clustMethodCols, treeOrderingCols = treeOrderingCols)
l = createHeatmap2(clust = clust, nbrClustersRows = nbrClustersRows, nbrClustersCols = nbrClustersCols, colorAnnoRow = colorAnnoRow, colorAnnoCol = colorAnnoCol, legendColorScheme = legendColorScheme, plotWidth = plotWidth, plotRatio = plotRatio, colorRangeMin = colorRangeMin, colorRangeMax = colorRangeMax, matrixColorScheme = matrixColorScheme, revScheme = revScheme, cellBorder = cellBorder, fontSizeGeneral = fontSizeGeneral, showNumbers = showNumbers, fontSizeNumbers = fontSizeNumbers, precisionNumbers = precisionNumbers, showRownames = showRownames, fontSizeRownames = fontSizeRownames, showColnames = showColnames, fontSizeColnames = fontSizeColnames, showAnnoTitlesRow = showAnnoTitlesRow, showAnnoTitlesCol = showAnnoTitlesCol, maxAnnoLevels = maxAnnoLevels,gapscol=gapscol,gapsrow=gapsrow,cellwidth = cellwidth, cellheight = cellheight,legend = legend,annotation_legend=annotation_legend)
structure(l, class = "hm")
}
from clustvis.
I added ellipsis to make it possible to pass custom parameters to pheatmap function: 73e8d66
This is a more general solution and it is now possible to call generateHeatmap function like this:
generateHeatmap(proc, clustDistRows = NA, gaps_row = c(5, 10, 15))
from clustvis.
Related Issues (17)
- Gene-based annotations HOT 1
- Disconnected from server HOT 4
- Browser open sample welcome page HOT 3
- better examples when using straight from R HOT 2
- clustvis HOT 1
- problem with clustvis HOT 1
- Help with running from Docker image install HOT 3
- Getting PC variance percents HOT 1
- Provide missing annotation and pathway files HOT 1
- Application failed to start HOT 5
- Command line or api-like automation? HOT 3
- Cannot access http://biit.cs.ut.ee/clustvis/ HOT 4
- Need new function to pull out list of entries HOT 1
- http://biit.cs.ut.ee/clustvis/ not working HOT 4
- Too many open devices error HOT 1
- Disconnect from the server after uploading HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clustvis.