Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorikuicr committed Mar 31, 2022
1 parent b47dd11 commit 4326ab9
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 109 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Package: espresso
Type: Package
Title: Enhanced spatial reconstruction by stochastic self-organizing
map
Version: 1.0.0
Date: 2022-01-21
Version: 1.0.1
Date: 2022-03-04
Authors@R: person("Tomoya", "Mori", role = c("aut", "cre"), email = "[email protected]")
Description: This is a package for domain estimation of cells only from gene expression profile based on graph-structured stochastic self-organizing map (GraphSOM) and Markov chain Monte Carlo (MCMC) method.
License: GPL-3
Expand All @@ -18,6 +18,6 @@ LazyData: true
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2022-01-21 06:50:12 UTC; tmori
Packaged: 2022-03-31 07:45:12 UTC; tmori
Author: Tomoya Mori [aut, cre]
Maintainer: Tomoya Mori <[email protected]>
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import(Boruta)
import(RColorBrewer)
import(doParallel)
import(foreach)
import(grid)
import(parallel)
import(progress)
import(rFerns)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.1
* Modify the argument name from `version="0.2.17` to `version="0"` to run SOM in the previous version.
* Default output format of `plotUMAP` is changed from "pdf" to "png".
* Modify labels of legend in distance map to discrete ones.


## 1.0.0
* Add an option `version` to `graphSOM` and `rxmcmc` functions in order to enable us to perform SOM computations based on the previous version (= 0.2.17).

Expand Down
107 changes: 80 additions & 27 deletions R/distancemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @importFrom pheatmap pheatmap
#' @importFrom grDevices colorRampPalette
#' @import RColorBrewer
#' @import grid unit
#' @export
#'
plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
Expand All @@ -22,16 +23,27 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {

# Plot distance maps of domains before GraphSOM ------------------------
if (!is.null(size_d)) {
pheatmap(distmat, cluster_cols = F, cluster_rows = F,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
main = "Distance of domains",
fontsize_row = size_d, fontsize_col = size_d,
cellheight = size_d, cellwidth = size_d
)
p <- pheatmap(distmat, cluster_cols = F, cluster_rows = F,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
main = "Distance of domains",
fontsize_row = size_d, fontsize_col = size_d,
cellheight = size_d, cellwidth = size_d, silent = T,
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
)
p <- .modLabelPositions(p)
plot.new()
print(p)
} else {
pheatmap(distmat, cluster_cols = F, cluster_rows = F,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
main = "Distance of domains")
p <- pheatmap(distmat, cluster_cols = F, cluster_rows = F,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
main = "Distance of domains", silent = T,
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
)
p <- .modLabelPositions(p)
plot.new()
print(p)
}
}
if (type == "s" || type == "b") {
Expand All @@ -55,13 +67,19 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
} else {
main_title <- paste("Distance of sample cells\n(rept.", i, ")", sep ="")
}
pheatmap(sample_dist,
cluster_cols = F, cluster_rows = F,
fontsize_row = size_s, fontsize_col = size_s,
cellheight = size_s, cellwidth = size_s,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
main = main_title
p <- pheatmap(sample_dist,
cluster_cols = F, cluster_rows = F,
fontsize_row = size_s, fontsize_col = size_s,
cellheight = size_s, cellwidth = size_s,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
main = main_title, silent = T,
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
)
p <- .modLabelPositions(p)
plot.new()
print(p)

for (repl in names(obj@bmu)) {
# Plot distance maps of samples after GraphSOM -------------------------
if (!is.null(obj@bmu)) {
Expand Down Expand Up @@ -97,13 +115,18 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
}
vec <- as.vector(sample_dist2)
if (length(unique(vec[!is.na(vec)])) != 1) {
pheatmap(sample_dist2,
cluster_cols = F, cluster_rows = F,
fontsize_row = size_s, fontsize_col = size_s,
cellheight = size_s, cellwidth = size_s,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
main = main_title
p <- pheatmap(sample_dist2,
cluster_cols = F, cluster_rows = F,
fontsize_row = size_s, fontsize_col = size_s,
cellheight = size_s, cellwidth = size_s,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
main = main_title, silent = T,
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
)
p <- .modLabelPositions(p)
plot.new()
print(p)
# Plot distance maps of samples before/after GraphSOM -------------------
ds <- sample_dist
ds[upper.tri(ds)] <- sample_dist2[upper.tri(sample_dist2)]
Expand All @@ -124,13 +147,18 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
main_title <- paste("Distance of sample cells \nin original (lower) and after GraphSOM (upper)\n(rept.", i, ")", sep = "")
}
}
pheatmap(ds,
cluster_cols = F, cluster_rows = F,
fontsize_row = size_s, fontsize_col = size_s,
cellheight = size_s, cellwidth = size_s,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
main = main_title
p <- pheatmap(ds,
cluster_cols = F, cluster_rows = F,
fontsize_row = size_s, fontsize_col = size_s,
cellheight = size_s, cellwidth = size_s,
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
main = main_title, silent = T,
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
)
p <- .modLabelPositions(p)
plot.new()
print(p)
} else {
warning("Distance map after graph-SOM clustering cannot be drown since only one cluseter was generated.")
}
Expand All @@ -139,4 +167,29 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
}
}
}
}



# =============================================================================
#' @title Modify label positions.
#' @description This function modifies positions of labels
#' @param p \code{pheatmap} object.
#' @importFrom pheatmap pheatmap
#' @import grid unit
#'
.modLabelPositions <- function(p) {
N_col_areas <- length(p$gtable$grobs[[5]]$children[[1]]$y)
N_labels <- length(p$gtable$grobs[[5]]$children[[2]]$label)
yseq1 <- seq(0, 1, length.out=N_col_areas)
center <- yseq1[2]/2
yseq2 <- seq(center, 1-center, length.out=N_labels)

for (k in 1:(N_labels)) {
p$gtable$grobs[[5]]$children[[2]]$y[[k]] <-
sum(yseq2[k]*min(unit(1,"npc"), unit(150,"bigpts")),
unit(1,"npc"),
-1*min(unit(1,"npc"), unit(150,"bigpts")))
}
return(p)
}
4 changes: 2 additions & 2 deletions R/graphsom.R
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ initGraphSOM <- function(obj, nsamples = NULL, rept = 1,
#' @param gset Gene set.
#' @param seed Random seed.
#' @param verbose Whether to show messages.
#' @param version Character that specifies on which previous version GraphSOM computation should be performed. (e.g., "0.2.17")
#' @param version Character that specifies on which previous version GraphSOM computation should be performed. (e.g., "0")
#' @return \code{espresso} object
#' @export
#'
Expand All @@ -616,7 +616,7 @@ graphSOM <- function(obj, gset = NULL, seed = NULL, verbose = TRUE, version = NU
if (!is.null(seed)) {
set.seed(seed, kind = "L'Ecuyer-CMRG")
}
} else if (version == "0.2.17") {
} else if (version == "0") {
if (!is.null(seed)) {
set.seed(seed, kind = "Mersenne-Twister")
}
Expand Down
8 changes: 4 additions & 4 deletions R/rxmcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
#' @param n_repl Number of replicas (default: \code{detectCores()}).
#' @param n_ig Number of initial genes randomly selected for MCMC.
#' @param fact Scaling factor for computing selection probability.
#' @param version Character that specifies on which previous version GraphSOM computation should be performed. (e.g., "0.2.17")
#' @param version Character that specifies on which previous version GraphSOM computation should be performed. (e.g., "0")
#' @import doParallel
#' @import parallel
#' @import foreach
Expand All @@ -226,7 +226,7 @@ rxmcmc <- function(obj, gset = NULL, temp = 1.0, itr = 10, k = 1, seed = NULL,
warning("Input `gset` to be optimized.")
return(obj)
}
if (version != "0.2.17" && !is.null(version)) {
if (version != "0" && !is.null(version)) {
stop(paste("version", version, "is not available."))
return(obj)
}
Expand Down Expand Up @@ -297,9 +297,9 @@ rxmcmc <- function(obj, gset = NULL, temp = 1.0, itr = 10, k = 1, seed = NULL,
score_tmp[[l]] <- res_tmp@score
summary_tmp[[l]] <- res_tmp@summary
}
} else if (version == "0.2.17"){
} else if (version == "0"){
for (l in 1:n_sets) {
res_tmp <- graphSOM(obj, gset = cand_sets[[l]], verbose = FALSE, version = "0.2.17")
res_tmp <- graphSOM(obj, gset = cand_sets[[l]], verbose = FALSE, version = "0")
res[l, ] <- c(as.numeric(unlist(res_tmp@summary)), length(cand_sets[[l]]))
map_tmp[[l]] <- res_tmp@map
bmu_tmp[[l]] <- res_tmp@bmu
Expand Down
2 changes: 1 addition & 1 deletion R/umap.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ runUMAP <- function(obj, umap_param = NULL, gset = NULL, seed = 0) {
#' @importFrom scatterplot3d scatterplot3d
#' @importFrom tagcloud smoothPalette
#' @export
plotUMAP <- function(obj, file = "umap.pdf",
plotUMAP <- function(obj, file = "umap.png",
movie = FALSE, dir = ".",
mname = "movie",
seed = 0,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# eSPRESSO

21-Jan-2022: espresso 1.0.0 released.
31-Mar-2022: espresso 1.0.1 released.

<br/>

Expand Down
Binary file modified build/partial.rdb
Binary file not shown.
55 changes: 28 additions & 27 deletions index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions inst/doc/espresso.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ knitr::include_graphics("umap_3D_color3.png")
knitr::include_graphics("umap.all.png")

## ---- eval = FALSE------------------------------------------------------------
# graphSOM(eobj, gset = fgenes, seed = 0, version = "0.2.17")
# graphSOM(eobj, gset = fgenes, seed = 0, version = "0")

## ---- eval = FALSE------------------------------------------------------------
# rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0.2.17")
# rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0")

## ---- eval=FALSE--------------------------------------------------------------
# library(biomaRt)
Expand Down
14 changes: 8 additions & 6 deletions inst/doc/espresso.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "espresso"
date: "21-Jan-2022: espresso 1.0.0 released."
date: "31-Mar-2022: espresso 1.0.1 released."
output:
rmarkdown::html_vignette:
toc: true
Expand Down Expand Up @@ -613,7 +613,9 @@ dev.off()
__Note__

When the exported format is 'pdf' or 'eps', and `rgl = TRUE`,
the legend information is not printed due to the design of `rgl` package.
the legend information is not printed due to the design of `rgl` package.
In addition, it often takes much time to draw UMAP plot as a PDF file when
the number of samples is large. In such case, please output as a PNG file.


### Other options of UMAP plotting
Expand Down Expand Up @@ -706,15 +708,15 @@ knitr::include_graphics("umap.all.png")

## Appendix

### Run `graphSOM` and `rxmcmc` of previous version (0.2.17)
In `espresso` of version 0.2.17 or earlier, the reproducibility between the results of `graphSOM` and `rxmcmc` was not guaranteed, and a random number generation method different from version 1.0.0 or later was employed. The followings are examples of the way to run `graphSOM` and `rxmcmc` of version 0.2.17.
### Run `graphSOM` and `rxmcmc` of previous version (0)
In `espresso` of version 0, the reproducibility between the results of `graphSOM` and `rxmcmc` was not guaranteed, and a random number generation method different from version 1.0.0 or later was employed. The followings are examples of the way to run `graphSOM` and `rxmcmc` of version 0.

```{r, eval = FALSE}
graphSOM(eobj, gset = fgenes, seed = 0, version = "0.2.17")
graphSOM(eobj, gset = fgenes, seed = 0, version = "0")
```

```{r, eval = FALSE}
rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0.2.17")
rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0")
```

### Get gene description via biomaRt
Expand Down
55 changes: 28 additions & 27 deletions inst/doc/espresso.html

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions man/dot-modLabelPositions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/graphSOM.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plotUMAP.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/rxmcmc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions vignettes/espresso.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "espresso"
date: "21-Jan-2022: espresso 1.0.0 released."
date: "31-Mar-2022: espresso 1.0.1 released."
output:
rmarkdown::html_vignette:
toc: true
Expand Down Expand Up @@ -613,7 +613,9 @@ dev.off()
__Note__

When the exported format is 'pdf' or 'eps', and `rgl = TRUE`,
the legend information is not printed due to the design of `rgl` package.
the legend information is not printed due to the design of `rgl` package.
In addition, it often takes much time to draw UMAP plot as a PDF file when
the number of samples is large. In such case, please output as a PNG file.


### Other options of UMAP plotting
Expand Down Expand Up @@ -706,15 +708,15 @@ knitr::include_graphics("umap.all.png")

## Appendix

### Run `graphSOM` and `rxmcmc` of previous version (0.2.17)
In `espresso` of version 0.2.17 or earlier, the reproducibility between the results of `graphSOM` and `rxmcmc` was not guaranteed, and a random number generation method different from version 1.0.0 or later was employed. The followings are examples of the way to run `graphSOM` and `rxmcmc` of version 0.2.17.
### Run `graphSOM` and `rxmcmc` of previous version (0)
In `espresso` of version 0, the reproducibility between the results of `graphSOM` and `rxmcmc` was not guaranteed, and a random number generation method different from version 1.0.0 or later was employed. The followings are examples of the way to run `graphSOM` and `rxmcmc` of version 0.

```{r, eval = FALSE}
graphSOM(eobj, gset = fgenes, seed = 0, version = "0.2.17")
graphSOM(eobj, gset = fgenes, seed = 0, version = "0")
```

```{r, eval = FALSE}
rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0.2.17")
rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0")
```

### Get gene description via biomaRt
Expand Down

0 comments on commit 4326ab9

Please sign in to comment.