renozao / NMF

NMF: A Flexible R package for Nonnegative Matrix Factorization
139 stars 41 forks source link

Combination of breaks and colors does not work #125

Open mhlinder opened 6 years ago

mhlinder commented 6 years ago

Often, I calculate a set of breaks, and a custom color palette.

Just as often, it works to use only the breaks, or only the color palette.

But, when I use both together, aheatmap seems to run out of colors, and recycles them—definitely not working!

Code below and image attached.

aheatmap-colors

mhl:~/$ R

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(NMF)
Loading required package: pkgmaker
Loading required package: registry

Attaching package: ‘pkgmaker’

The following object is masked from ‘package:base’:

    isFALSE

Loading required package: rngtools
Loading required package: cluster
NMF - BioConductor layer [NO: missing Biobase] | Shared memory capabilities [NO: bigmemory] | Cores 7/8
  To enable the Bioconductor layer, try: install.extras('
NMF
') [with Bioconductor repository enabled]
  To enable shared memory capabilities, try: install.extras('
NMF
')
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux buster/sid

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] NMF_0.21.0      cluster_2.0.7-1 rngtools_1.3.1  pkgmaker_0.27
[5] registry_0.5    colorout_1.2-0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18       compiler_3.5.1     pillar_1.3.0       RColorBrewer_1.1-2
 [5] plyr_1.8.4         bindr_0.1.1        iterators_1.0.10   tools_3.5.1
 [9] digest_0.6.17      gridBase_0.4-7     tibble_1.4.2       gtable_0.2.0
[13] pkgconfig_2.0.2    rlang_0.2.2        foreach_1.4.4      bibtex_0.4.2
[17] parallel_3.5.1     bindrcpp_0.2.2     withr_2.1.2        stringr_1.3.1
[21] dplyr_0.7.6        grid_3.5.1         tidyselect_0.2.4   glue_1.3.0
[25] R6_2.2.2           reshape2_1.4.3     purrr_0.2.5        ggplot2_3.0.0
[29] magrittr_1.5       scales_1.0.0       codetools_0.2-15   assertthat_0.2.0
[33] xtable_1.8-3       colorspace_1.3-2   stringi_1.2.4      lazyeval_0.2.1
[37] doParallel_1.0.14  munsell_0.5.0      crayon_1.3.4
> set.seed(20181003)
> x <- matrix(rnorm(400), 20)
> range(x)
[1] -3.128249  4.092170
> breaks <- seq(-4, 4, length.out=101)
> cols <- colorRampPalette(c("white", "red"))(100)
> par(mfrow=c(1,3))
> aheatmap(x, Rowv=NA, Colv=NA, color=cols)
> aheatmap(x, Rowv=NA, Colv=NA, breaks=breaks)
> aheatmap(x, Rowv=NA, Colv=NA, breaks=breaks, color=cols)
toddknutson commented 6 years ago

I am also having this problem.

toddknutson commented 6 years ago

I think something happened when the commits from April 16, 2018, or Aug 19, 2018 (bfbe67e2e8c5198ccf77892e381304f8bae96e10 29e165e31eb23c546c47db34e419fab500ad6970 b33a5ba5d1c4bbb00b07b9436a7fe8956dcc51e0 0791ac23c5f7d40af2769d396de4b7ed54e3e200) were applied to the master branch. I restarted a new R session, and installed an older version of NMF before those commits:

library(devtools)
install_github("renozao/NMF#61")

Then your code works correctly:

library(NMF)
set.seed(20181003)
x <- matrix(rnorm(400), 20)
range(x)
breaks <- seq(-4, 4, length.out=101)
cols <- colorRampPalette(c("white", "red"))(100)
pdf("heatmap.pdf", width = 12, height = 4, onefile = FALSE)
par(mfrow=c(1,3))
aheatmap(x, Rowv=NA, Colv=NA, color=cols)
aheatmap(x, Rowv=NA, Colv=NA, breaks=breaks)
aheatmap(x, Rowv=NA, Colv=NA, breaks=breaks, color=cols)
dev.off()

121_hierarchical3

toddknutson commented 5 years ago

However, please note that if you install the GitHub version #61 (see my comment above), the ward clustering method is wrong, as described here: https://github.com/renozao/NMF/issues/117

toddknutson commented 3 years ago

The color breaks problem appears to be solved. I'm not sure when this got resolved.

# Install the latest version from GitHub
# remotes::install_github("renozao/NMF@d02eba9")
library(NMF)
set.seed(20181003)
x <- matrix(rnorm(400), 20)
range(x)
breaks <- seq(-4, 4, length.out=101)
cols <- colorRampPalette(c("white", "red"))(100)
pdf("heatmap.pdf", width = 12, height = 4, onefile = FALSE)
par(mfrow=c(1,3))
aheatmap(x, Rowv=NA, Colv=NA, color=cols)
aheatmap(x, Rowv=NA, Colv=NA, breaks=breaks)
aheatmap(x, Rowv=NA, Colv=NA, breaks=breaks, color=cols)
dev.off()

heatmap heatmap.pdf

R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /panfs/roc/groups/0/lmnp/knut0297/software/modules/openblas/0.3.13/build/lib/libopenblas_zenp-r0.3.13.dev.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods
[8] base

other attached packages:
[1] RColorBrewer_1.1-2  NMF_0.30.1          Biobase_2.50.0
[4] BiocGenerics_0.36.0 cluster_2.1.0       rngtools_1.5
[7] pkgmaker_0.32.2     registry_0.5-1

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0  remotes_2.2.0     purrr_0.3.4       reshape2_1.4.4
 [5] colorspace_2.0-0  vctrs_0.3.6       generics_0.1.0    viridisLite_0.3.0
 [9] rlang_0.4.10      pkgbuild_1.2.0    pillar_1.4.7      glue_1.4.2
[13] withr_2.3.0       DBI_1.1.0         foreach_1.5.1     lifecycle_0.2.0
[17] plyr_1.8.6        stringr_1.4.0     munsell_0.5.0     gtable_0.3.0
[21] codetools_0.2-16  callr_3.5.1       doParallel_1.0.16 ps_1.5.0
[25] curl_4.3          fansi_0.4.2       Rcpp_1.0.6        xtable_1.8-4
[29] scales_1.1.1      gridExtra_2.3     ggplot2_3.3.3     digest_0.6.27
[33] stringi_1.5.3     processx_3.4.5    dplyr_1.0.3       rprojroot_2.0.2
[37] grid_4.0.3        cli_2.2.0         tools_4.0.3       magrittr_2.0.1
[41] tibble_3.0.5      crayon_1.3.4      pkgconfig_2.0.3   dendextend_1.14.0
[45] ellipsis_0.3.1    gridBase_0.4-7    prettyunits_1.1.1 assertthat_0.2.1
[49] viridis_0.5.1     iterators_1.0.13  R6_2.5.0          compiler_4.0.3