Skip to content

Commit 4326ab9

Browse files
committed
Updated
1 parent b47dd11 commit 4326ab9

18 files changed

+189
-109
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Package: espresso
22
Type: Package
33
Title: Enhanced spatial reconstruction by stochastic self-organizing
44
map
5-
Version: 1.0.0
6-
Date: 2022-01-21
5+
Version: 1.0.1
6+
Date: 2022-03-04
77
Authors@R: person("Tomoya", "Mori", role = c("aut", "cre"), email = "[email protected]")
88
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.
99
License: GPL-3
@@ -18,6 +18,6 @@ LazyData: true
1818
Suggests: knitr, rmarkdown
1919
VignetteBuilder: knitr
2020
NeedsCompilation: no
21-
Packaged: 2022-01-21 06:50:12 UTC; tmori
21+
Packaged: 2022-03-31 07:45:12 UTC; tmori
2222
Author: Tomoya Mori [aut, cre]
2323
Maintainer: Tomoya Mori <[email protected]>

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import(Boruta)
1818
import(RColorBrewer)
1919
import(doParallel)
2020
import(foreach)
21+
import(grid)
2122
import(parallel)
2223
import(progress)
2324
import(rFerns)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.0.1
2+
* Modify the argument name from `version="0.2.17` to `version="0"` to run SOM in the previous version.
3+
* Default output format of `plotUMAP` is changed from "pdf" to "png".
4+
* Modify labels of legend in distance map to discrete ones.
5+
6+
17
## 1.0.0
28
* 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).
39

R/distancemap.R

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' @importFrom pheatmap pheatmap
1111
#' @importFrom grDevices colorRampPalette
1212
#' @import RColorBrewer
13+
#' @import grid unit
1314
#' @export
1415
#'
1516
plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
@@ -22,16 +23,27 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
2223

2324
# Plot distance maps of domains before GraphSOM ------------------------
2425
if (!is.null(size_d)) {
25-
pheatmap(distmat, cluster_cols = F, cluster_rows = F,
26-
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
27-
main = "Distance of domains",
28-
fontsize_row = size_d, fontsize_col = size_d,
29-
cellheight = size_d, cellwidth = size_d
30-
)
26+
p <- pheatmap(distmat, cluster_cols = F, cluster_rows = F,
27+
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
28+
main = "Distance of domains",
29+
fontsize_row = size_d, fontsize_col = size_d,
30+
cellheight = size_d, cellwidth = size_d, silent = T,
31+
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
32+
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
33+
)
34+
p <- .modLabelPositions(p)
35+
plot.new()
36+
print(p)
3137
} else {
32-
pheatmap(distmat, cluster_cols = F, cluster_rows = F,
33-
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
34-
main = "Distance of domains")
38+
p <- pheatmap(distmat, cluster_cols = F, cluster_rows = F,
39+
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
40+
main = "Distance of domains", silent = T,
41+
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
42+
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
43+
)
44+
p <- .modLabelPositions(p)
45+
plot.new()
46+
print(p)
3547
}
3648
}
3749
if (type == "s" || type == "b") {
@@ -55,13 +67,19 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
5567
} else {
5668
main_title <- paste("Distance of sample cells\n(rept.", i, ")", sep ="")
5769
}
58-
pheatmap(sample_dist,
59-
cluster_cols = F, cluster_rows = F,
60-
fontsize_row = size_s, fontsize_col = size_s,
61-
cellheight = size_s, cellwidth = size_s,
62-
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
63-
main = main_title
70+
p <- pheatmap(sample_dist,
71+
cluster_cols = F, cluster_rows = F,
72+
fontsize_row = size_s, fontsize_col = size_s,
73+
cellheight = size_s, cellwidth = size_s,
74+
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
75+
main = main_title, silent = T,
76+
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
77+
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
6478
)
79+
p <- .modLabelPositions(p)
80+
plot.new()
81+
print(p)
82+
6583
for (repl in names(obj@bmu)) {
6684
# Plot distance maps of samples after GraphSOM -------------------------
6785
if (!is.null(obj@bmu)) {
@@ -97,13 +115,18 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
97115
}
98116
vec <- as.vector(sample_dist2)
99117
if (length(unique(vec[!is.na(vec)])) != 1) {
100-
pheatmap(sample_dist2,
101-
cluster_cols = F, cluster_rows = F,
102-
fontsize_row = size_s, fontsize_col = size_s,
103-
cellheight = size_s, cellwidth = size_s,
104-
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
105-
main = main_title
118+
p <- pheatmap(sample_dist2,
119+
cluster_cols = F, cluster_rows = F,
120+
fontsize_row = size_s, fontsize_col = size_s,
121+
cellheight = size_s, cellwidth = size_s,
122+
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
123+
main = main_title, silent = T,
124+
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
125+
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
106126
)
127+
p <- .modLabelPositions(p)
128+
plot.new()
129+
print(p)
107130
# Plot distance maps of samples before/after GraphSOM -------------------
108131
ds <- sample_dist
109132
ds[upper.tri(ds)] <- sample_dist2[upper.tri(sample_dist2)]
@@ -124,13 +147,18 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
124147
main_title <- paste("Distance of sample cells \nin original (lower) and after GraphSOM (upper)\n(rept.", i, ")", sep = "")
125148
}
126149
}
127-
pheatmap(ds,
128-
cluster_cols = F, cluster_rows = F,
129-
fontsize_row = size_s, fontsize_col = size_s,
130-
cellheight = size_s, cellwidth = size_s,
131-
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(100), na_col = "black",
132-
main = main_title
150+
p <- pheatmap(ds,
151+
cluster_cols = F, cluster_rows = F,
152+
fontsize_row = size_s, fontsize_col = size_s,
153+
cellheight = size_s, cellwidth = size_s,
154+
color = colorRampPalette(brewer.pal(n = 7, name = "Blues"))(max(eobj@dist[eobj@dist != Inf]) + 1), na_col = "black",
155+
main = main_title, silent = T,
156+
legend_breaks = 0:max(eobj@dist[eobj@dist != Inf]),
157+
legend_labels = 0:max(eobj@dist[eobj@dist != Inf])
133158
)
159+
p <- .modLabelPositions(p)
160+
plot.new()
161+
print(p)
134162
} else {
135163
warning("Distance map after graph-SOM clustering cannot be drown since only one cluseter was generated.")
136164
}
@@ -139,4 +167,29 @@ plotDistMap <- function(obj, type = "b", size_d = NULL, size_s = 5) {
139167
}
140168
}
141169
}
170+
}
171+
172+
173+
174+
# =============================================================================
175+
#' @title Modify label positions.
176+
#' @description This function modifies positions of labels
177+
#' @param p \code{pheatmap} object.
178+
#' @importFrom pheatmap pheatmap
179+
#' @import grid unit
180+
#'
181+
.modLabelPositions <- function(p) {
182+
N_col_areas <- length(p$gtable$grobs[[5]]$children[[1]]$y)
183+
N_labels <- length(p$gtable$grobs[[5]]$children[[2]]$label)
184+
yseq1 <- seq(0, 1, length.out=N_col_areas)
185+
center <- yseq1[2]/2
186+
yseq2 <- seq(center, 1-center, length.out=N_labels)
187+
188+
for (k in 1:(N_labels)) {
189+
p$gtable$grobs[[5]]$children[[2]]$y[[k]] <-
190+
sum(yseq2[k]*min(unit(1,"npc"), unit(150,"bigpts")),
191+
unit(1,"npc"),
192+
-1*min(unit(1,"npc"), unit(150,"bigpts")))
193+
}
194+
return(p)
142195
}

R/graphsom.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ initGraphSOM <- function(obj, nsamples = NULL, rept = 1,
607607
#' @param gset Gene set.
608608
#' @param seed Random seed.
609609
#' @param verbose Whether to show messages.
610-
#' @param version Character that specifies on which previous version GraphSOM computation should be performed. (e.g., "0.2.17")
610+
#' @param version Character that specifies on which previous version GraphSOM computation should be performed. (e.g., "0")
611611
#' @return \code{espresso} object
612612
#' @export
613613
#'
@@ -616,7 +616,7 @@ graphSOM <- function(obj, gset = NULL, seed = NULL, verbose = TRUE, version = NU
616616
if (!is.null(seed)) {
617617
set.seed(seed, kind = "L'Ecuyer-CMRG")
618618
}
619-
} else if (version == "0.2.17") {
619+
} else if (version == "0") {
620620
if (!is.null(seed)) {
621621
set.seed(seed, kind = "Mersenne-Twister")
622622
}

R/rxmcmc.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
#' @param n_repl Number of replicas (default: \code{detectCores()}).
208208
#' @param n_ig Number of initial genes randomly selected for MCMC.
209209
#' @param fact Scaling factor for computing selection probability.
210-
#' @param version Character that specifies on which previous version GraphSOM computation should be performed. (e.g., "0.2.17")
210+
#' @param version Character that specifies on which previous version GraphSOM computation should be performed. (e.g., "0")
211211
#' @import doParallel
212212
#' @import parallel
213213
#' @import foreach
@@ -226,7 +226,7 @@ rxmcmc <- function(obj, gset = NULL, temp = 1.0, itr = 10, k = 1, seed = NULL,
226226
warning("Input `gset` to be optimized.")
227227
return(obj)
228228
}
229-
if (version != "0.2.17" && !is.null(version)) {
229+
if (version != "0" && !is.null(version)) {
230230
stop(paste("version", version, "is not available."))
231231
return(obj)
232232
}
@@ -297,9 +297,9 @@ rxmcmc <- function(obj, gset = NULL, temp = 1.0, itr = 10, k = 1, seed = NULL,
297297
score_tmp[[l]] <- res_tmp@score
298298
summary_tmp[[l]] <- res_tmp@summary
299299
}
300-
} else if (version == "0.2.17"){
300+
} else if (version == "0"){
301301
for (l in 1:n_sets) {
302-
res_tmp <- graphSOM(obj, gset = cand_sets[[l]], verbose = FALSE, version = "0.2.17")
302+
res_tmp <- graphSOM(obj, gset = cand_sets[[l]], verbose = FALSE, version = "0")
303303
res[l, ] <- c(as.numeric(unlist(res_tmp@summary)), length(cand_sets[[l]]))
304304
map_tmp[[l]] <- res_tmp@map
305305
bmu_tmp[[l]] <- res_tmp@bmu

R/umap.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ runUMAP <- function(obj, umap_param = NULL, gset = NULL, seed = 0) {
149149
#' @importFrom scatterplot3d scatterplot3d
150150
#' @importFrom tagcloud smoothPalette
151151
#' @export
152-
plotUMAP <- function(obj, file = "umap.pdf",
152+
plotUMAP <- function(obj, file = "umap.png",
153153
movie = FALSE, dir = ".",
154154
mname = "movie",
155155
seed = 0,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# eSPRESSO
22

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

55
<br/>
66

build/partial.rdb

30 Bytes
Binary file not shown.

index.html

Lines changed: 28 additions & 27 deletions
Large diffs are not rendered by default.

inst/doc/espresso.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ knitr::include_graphics("umap_3D_color3.png")
276276
knitr::include_graphics("umap.all.png")
277277

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

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

284284
## ---- eval=FALSE--------------------------------------------------------------
285285
# library(biomaRt)

inst/doc/espresso.Rmd

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "espresso"
3-
date: "21-Jan-2022: espresso 1.0.0 released."
3+
date: "31-Mar-2022: espresso 1.0.1 released."
44
output:
55
rmarkdown::html_vignette:
66
toc: true
@@ -613,7 +613,9 @@ dev.off()
613613
__Note__
614614

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

618620

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

707709
## Appendix
708710

709-
### Run `graphSOM` and `rxmcmc` of previous version (0.2.17)
710-
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.
711+
### Run `graphSOM` and `rxmcmc` of previous version (0)
712+
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.
711713

712714
```{r, eval = FALSE}
713-
graphSOM(eobj, gset = fgenes, seed = 0, version = "0.2.17")
715+
graphSOM(eobj, gset = fgenes, seed = 0, version = "0")
714716
```
715717

716718
```{r, eval = FALSE}
717-
rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0.2.17")
719+
rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0")
718720
```
719721

720722
### Get gene description via biomaRt

inst/doc/espresso.html

Lines changed: 28 additions & 27 deletions
Large diffs are not rendered by default.

man/dot-modLabelPositions.Rd

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/graphSOM.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotUMAP.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rxmcmc.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/espresso.Rmd

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "espresso"
3-
date: "21-Jan-2022: espresso 1.0.0 released."
3+
date: "31-Mar-2022: espresso 1.0.1 released."
44
output:
55
rmarkdown::html_vignette:
66
toc: true
@@ -613,7 +613,9 @@ dev.off()
613613
__Note__
614614

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

618620

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

707709
## Appendix
708710

709-
### Run `graphSOM` and `rxmcmc` of previous version (0.2.17)
710-
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.
711+
### Run `graphSOM` and `rxmcmc` of previous version (0)
712+
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.
711713

712714
```{r, eval = FALSE}
713-
graphSOM(eobj, gset = fgenes, seed = 0, version = "0.2.17")
715+
graphSOM(eobj, gset = fgenes, seed = 0, version = "0")
714716
```
715717

716718
```{r, eval = FALSE}
717-
rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0.2.17")
719+
rxmcmc(eobj, gset = fgenes, itr = 2, n_ex = 5, n_repl = 4, n_cl = 4, seed = 0, version = "0")
718720
```
719721

720722
### Get gene description via biomaRt

0 commit comments

Comments
 (0)