Skip to content

Commit 94c0e5b

Browse files
committed
clean up lots of documentation
1 parent 4b832b5 commit 94c0e5b

25 files changed

+215
-218
lines changed

DESCRIPTION

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: EmbedSOM
2-
Version: 2.1
2+
Version: 2.1.1
33
Title: Fast Embedding Guided by Self-Organizing Map
44
Authors@R: c(person("Mirek", "Kratochvil",
55
role = c("aut", "cre"),
@@ -17,22 +17,23 @@ Authors@R: c(person("Mirek", "Kratochvil",
1717
role = "cph",
1818
email = "[email protected]"))
1919
Depends: R (>= 3.2)
20-
Suggests:
20+
Suggests: knitr, rmarkdown
21+
Imports:
22+
FNN,
2123
ggplot2,
22-
Matrix,
2324
igraph,
25+
Matrix,
2426
Rtsne,
2527
umap,
26-
uwot,
27-
knitr,
28-
rmarkdown
28+
uwot
2929
Description: Provides a smooth mapping of multidimensional points into
3030
low-dimensional space defined by a self-organizing map. Designed to work
3131
with 'FlowSOM' and flow-cytometry use-cases. See Kratochvil et al. (2019)
32-
<doi:10.1101/496869>.
32+
<doi:10.12688/f1000research.21642.1>.
3333
License: GPL (>= 3)
3434
LazyData: true
3535
URL: https://bioinfo.uochb.cas.cz/embedsom
3636
Encoding: UTF-8
3737
RoxygenNote: 6.1.1
38+
Roxygen: list(markdown = TRUE)
3839
VignetteBuilder: knitr

R/coords.R

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ guessDistMethod <- function(dist.method, map) {
4040
#' @param data Input data matrix, with individual data points in rows
4141
#' @param k How many points to sample
4242
#' @param coordsFn a function to generate embedding coordinates (default none)
43-
#' @return map object (without the grid, if coordsFn was not specified)
43+
#' @return map object (without the grid, if `coordsFn` was not specified)
4444
#'
4545
#' @examples
4646
#' d <- iris[,1:4]
@@ -61,17 +61,17 @@ RandomMap <- function(data, k, coordsFn) {
6161
#'
6262
#' May give better results than 'RandomMap' on data where random sampling
6363
#' is complicated.
64-
#' This does not use actual kMeans clustering, but re-uses the batch SOM with
65-
#' tiny radius (which is the same as kMeans). In consequence, the speedup of
66-
#' SOM function is applied here as well. Additionally, because we don't need
67-
#' that amount of clustering precision, parameters 'batch=F, rlen=1' may give
68-
#' a satisfactory result very quickly.
64+
#' This does not use actual kMeans clustering, but re-uses the batch version of
65+
#' [SOM()] with tiny radius (which makes it work the same as kMeans). In
66+
#' consequence, the speedup of SOM function is applied here as well. Additionally,
67+
#' because we don't need that amount of clustering precision, parameters `batch=F, rlen=1'
68+
#' may give a satisfactory result very quickly.
6969
#'
7070
#' @param data Input data matrix, with individual data points in rows
7171
#' @param k How many points to sample
7272
#' @param coordsFn a function to generate embedding coordinates (default none)
73-
#' @param batch Use batch-SOM training (effectively kMeans, default T)
74-
#' @param ... Passed to 'SOM', useful e.g. for 'parallel=T' or 'rlen=5'
73+
#' @param batch Use batch-SOM training (effectively kMeans, default TRUE)
74+
#' @param ... Passed to [SOM()], useful e.g. for 'parallel=T' or 'rlen=5'
7575
#' @return map object (without the grid, if coordsFn was not specified)
7676
#'
7777
#' @examples
@@ -98,10 +98,10 @@ kMeansMap <- function(data, k, coordsFn, batch=T, ...) {
9898

9999
#' Add tSNE-based coordinates to a map
100100
#'
101-
#' @param dim Dimension of the result (passed to tSNEFn as 'dims')
102-
#' @param tSNEFn tSNE function to run (default 'Rtsne::Rtsne')
103-
#' @param ... passed to 'tSNEFn'
104-
#' @return a function that transforms the map, usable as 'coordsFn' parameter
101+
#' @param dim Dimension of the result (passed to `tSNEFn` as `dims`)
102+
#' @param tSNEFn tSNE function to run (default [Rtsne::Rtsne])
103+
#' @param ... passed to `tSNEFn`
104+
#' @return a function that transforms the map, usable as `coordsFn` parameter
105105
#' @export
106106
tSNECoords <- function(dim=NULL, tSNEFn=Rtsne::Rtsne, ...) {
107107
function(map) {
@@ -113,16 +113,16 @@ tSNECoords <- function(dim=NULL, tSNEFn=Rtsne::Rtsne, ...) {
113113

114114
#' Add UMAP-based coordinates to a map
115115
#'
116-
#' @param dim Dimension of the result (passed to UMAPFn as 'n_components')
117-
#' @param UMAPFn UMAP function to run (default 'umap::umap' configured by 'umap::umap.defaults')
118-
#' @return a function that transforms the map, usable as 'coordsFn' parameter
116+
#' @param dim Dimension of the result (passed to `UMAPFn` as `n_components`)
117+
#' @param UMAPFn UMAP function to run (default [umap::umap] configured by [umap::umap.defaults])
118+
#' @return a function that transforms the map, usable as `coordsFn` parameter
119119
#' @export
120-
UMAPCoords <- function(dim=NULL,
121-
UMAPFn=function(x, dim){
122-
cfg <- umap::umap.defaults
123-
cfg$n_components = dim
124-
umap::umap(x, cfg)$layout
125-
}) {
120+
UMAPCoords <- function(dim=NULL, UMAPFn=NULL) {
121+
if(is.null(UMAPFn)) UMAPFn <- function(x, dim) {
122+
cfg <- umap::umap.defaults
123+
cfg$n_components = dim
124+
umap::umap(x, cfg)$layout
125+
}
126126
function(map) {
127127
dim <- guessDim(dim, map)
128128
map$grid <- UMAPFn(map$codes, dim)
@@ -132,10 +132,10 @@ UMAPCoords <- function(dim=NULL,
132132

133133
#' Add UMAP-based coordinates to a map, using the 'uwot' package
134134
#'
135-
#' @param dim Dimension of the result (passed to uwotFn as 'dims')
136-
#' @param uwotFn UMAP function to run (default 'uwot::uwot')
137-
#' @param ... passed to 'uwotFn'
138-
#' @return a function that transforms the map, usable as 'coordsFn' parameter
135+
#' @param dim Dimension of the result (passed to `uwotFn` as `dims`)
136+
#' @param uwotFn UMAP function to run (default [uwot::umap])
137+
#' @param ... passed to `uwotFn`
138+
#' @return a function that transforms the map, usable as `coordsFn` parameter
139139
#' @export
140140
uwotCoords <- function(dim=NULL, uwotFn=uwot::umap, ...) {
141141
function(map) {
@@ -147,12 +147,12 @@ uwotCoords <- function(dim=NULL, uwotFn=uwot::umap, ...) {
147147

148148
#' Add U-Matrix-optimized embedding coordinates to the map
149149
#'
150-
#' The map must already contain a SOM grid with corresponding 'xdim','ydim' (possibly 'zdim')
150+
#' The map must already contain a SOM grid with corresponding `xdim`,`ydim` (possibly `zdim`)
151151
#'
152-
#' @param dim Dimension of the result (passed to layoutFn)
153-
#' @param dist.method The method to compute distances, passed to 'stats::dist' as parameter 'method'
152+
#' @param dim Dimension of the result (passed to `layoutFn`)
153+
#' @param dist.method The method to compute distances, passed to [stats::dist()] as parameter `method`
154154
#' @param distFn Custom transformation function of the distance matrix
155-
#' @param layoutFn iGraph-compatible graph layouting function (default 'igraph::layout_with_kk')
155+
#' @param layoutFn iGraph-compatible graph layouting function (default [igraph::layout_with_kk])
156156
#' @return a function that transforms the map, usable as 'coordsFn' parameter
157157
#' @export
158158
UMatrixCoords <- function(dim=NULL, dist.method=NULL, distFn=function(x)x, layoutFn=igraph::layout_with_kk) {
@@ -179,10 +179,10 @@ UMatrixCoords <- function(dim=NULL, dist.method=NULL, distFn=function(x)x, layou
179179
#' Add MST-style embedding coordinates to the map
180180
#'
181181
#' @param dim Dimension of the result (passed to layoutFn)
182-
#' @param dist.method The method to compute distances, passed to 'stats::dist' as parameter 'method'
182+
#' @param dist.method The method to compute distances, passed to [stats::dist()] as parameter `method`
183183
#' @param distFn Custom transformation function of the distance matrix
184-
#' @param layoutFn iGraph-compatible graph layouting function (default 'igraph::layout_with_kk')
185-
#' @return a function that transforms the map, usable as 'coordsFn' parameter
184+
#' @param layoutFn iGraph-compatible graph layouting function (default [igraph::layout_with_kk()])
185+
#' @return a function that transforms the map, usable as `coordsFn` parameter
186186
#' @export
187187
MSTCoords <- function(dim=NULL, dist.method=NULL, distFn=function(x)x, layoutFn=igraph::layout_with_kk) {
188188
function(map) {
@@ -204,11 +204,11 @@ MSTCoords <- function(dim=NULL, dist.method=NULL, distFn=function(x)x, layoutFn=
204204
#' problems. It is therefore useful to transform the distances for avoiding that
205205
#' (e.g. by exponentiating them slightly).
206206
#'
207-
#' @param dim Dimension of the result (passed to layoutFn)
208-
#' @param dist.method The method to compute distances, passed to 'stats::dist' as parameter 'method'
207+
#' @param dim Dimension of the result (passed to `layoutFn`)
208+
#' @param dist.method The method to compute distances, passed to [stats::dist()] as parameter `method`
209209
#' @param distFn Custom transformation function of the distance matrix
210-
#' @param layoutFn iGraph-compatible graph layouting function (default 'igraph::layout_with_kk')
211-
#' @return a function that transforms the map, usable as 'coordsFn' parameter
210+
#' @param layoutFn iGraph-compatible graph layouting function (default [igraph::layout_with_kk])
211+
#' @return a function that transforms the map, usable as `coordsFn` parameter
212212
#' @export
213213
GraphCoords <- function(dim=NULL, dist.method=NULL, distFn=function(x)x, layoutFn=igraph::layout_with_kk) {
214214
function(map) {
@@ -224,15 +224,15 @@ GraphCoords <- function(dim=NULL, dist.method=NULL, distFn=function(x)x, layoutF
224224

225225
#' Add KNN-topology-based embedding coordinates to the map
226226
#'
227-
#' Internally, this uses 'FNN::get.knn' to compute the k-neighborhoods. That
228-
#' function only supports Euclidean metric, so kNNCoords throws a warning whenever
227+
#' Internally, this uses [FNN::get.knn()] to compute the k-neighborhoods. That
228+
#' function only supports Euclidean metric, therefore `kNNCoords` throws a warning whenever
229229
#' a different metric is used.
230230
#'
231231
#' @param k Size of the neighborhoods (default 4)
232-
#' @param dim Dimension of the result (passed to layoutFn)
232+
#' @param dim Dimension of the result (passed to `layoutFn`)
233233
#' @param distFn Custom transformation function of the distance matrix
234-
#' @param layoutFn iGraph-compatible graph layouting function (default 'igraph::layout_with_kk')
235-
#' @return a function that transforms the map, usable as 'coordsFn' parameter
234+
#' @param layoutFn iGraph-compatible graph layouting function (default [igraph::layout_with_kk])
235+
#' @return a function that transforms the map, usable as `coordsFn` parameter
236236
#' @export
237237
kNNCoords <- function(k=4, dim=NULL, distFn=function(x)x, layoutFn=igraph::layout_with_kk) {
238238
function(map) {
@@ -245,7 +245,7 @@ kNNCoords <- function(k=4, dim=NULL, distFn=function(x)x, layoutFn=igraph::layou
245245
adj <- matrix(0, n, n)
246246
adj[kns[,2]+n*(kns[,1]-1)] <- 1
247247
adj[kns[,1]+n*(kns[,2]-1)] <- 1
248-
adj <- adj*(distFn(as.matrix(dist(map$codes, method='euclidean'))))
248+
adj <- adj*(distFn(as.matrix(stats::dist(map$codes, method='euclidean'))))
249249

250250
map$grid <- layoutFn(dim=dim,
251251
igraph::graph_from_adjacency_matrix(adj, mode='undirected', weighted=T))

R/embed.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717

1818
#' Process the cells with SOM into a nice embedding
1919
#'
20-
#' @param data Data matrix with points that optionally overrides the one from `fsom$data`.
20+
#' @param data Data matrix with points that optionally overrides the one from `fsom$data`
2121
#' @param map Map object in FlowSOM format, to optionally override `fsom$map`
2222
#' @param fsom FlowSOM object with a built SOM (used if data or map are missing)
2323
#' @param smooth Produce smoother (positive values) or more rough approximation (negative values).
24-
#' @param k How many SOM neighbors to take into the whole computation
25-
#' @param adjust How much non-local information to remove (parameter a)
26-
#' @param importance Importance of dimensions that was used to train the SOM
27-
#' @param coords A matrix of embedding-space coordinates that correspond to 'map$codes' (i.e. the "embedded landmarks"). Overrides 'map$grid' if not NULL.
28-
#' @param coordsFn A coordinates-generating function (e.g. 'EmbedSOM::tSNECoords()') that overrides the existing 'map$grid'.
29-
#' @param emcoords Provided for backwards compatibility, will be removed. Either a matrix of embedded coordinates (same number of rows as 'map$codes', and either 2 or 3 columns depending on the SOM grid dimension), or one of 'flat' (default behavior), 'som' (adjust the SOM coords according to U-matrix distances), 'mst' (embed to MST-like structure), 'fsom-mst' (embed to MST that should look exactly like that of FlowSOM), 'tsne' (embed using tSNE from package Rtsne), 'umap' (embed using UMAP from package umap) or 'uwot::umap' (embed using UMAP from package uwot)
30-
#' @param emcoords.pow Provided for backwards compatibility, will be removed. Exaggeration factor (power) of the distances in U-matrix used for some methods of auto-generating emcoords; default 1.
24+
#' @param k How many neighboring landmarks (e.g. SOM nodes) to take into the whole computation
25+
#' @param adjust How much non-local information to remove from the approximation
26+
#' @param importance Scaling of the landmarks, will be used to scale the incoming data (should be same as used for training the SOM or to select the landmarks)
27+
#' @param coords A matrix of embedding-space coordinates that correspond to `map$codes` (i.e. the "embedded landmarks"). Overrides `map$grid` if not NULL.
28+
#' @param coordsFn A coordinates-generating function (e.g. [tSNECoords()]) that overrides the existing `map$grid`.
29+
#' @param emcoords Provided for backwards compatibility, will be removed. Use `coords` and `coordsFn` instead.
30+
#' @param emcoords.pow Provided for backwards compatibility, will be removed. Use a parametrized `coordsFn` instead.
3131
#' @param threads Number of threads used for computation, 0 chooses hardware concurrency, 1 (default) turns off parallelization.
32-
#' @param parallel Boolean flag whether the computation should be parallelized (this flag is just a nice name for 'threads' and does not do anything directly -- default FALSE sets threads=1, TRUE sets threads=0)
33-
#' @return matrix with 2D or 3D coordinates of the embedded cels, depending on the map
32+
#' @param parallel Boolean flag whether the computation should be parallelized (this flag is just a nice name for `threads` and does not do anything directly -- default FALSE sets threads=1, TRUE sets threads=0)
33+
#' @return matrix with 2D or 3D coordinates of the embedded `data`, depending on the `map`
3434
#'
3535
#' @examples
3636
#' d <- cbind(rnorm(10000), 3*runif(10000), rexp(10000))

0 commit comments

Comments
 (0)