Skip to content

Commit 226a0ec

Browse files
committed
use built-in transposition for cosine computation example
`coop::tcosine`
1 parent 84deb26 commit 226a0ec

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

R/delineate_with_similarity.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#' 2. It uses base R functions to reduce the dependencies
2828
#'
2929
#'
30-
#' @seealso For similarity metrics: [`coop::cosine`](https://rdrr.io/cran/coop/man/cosine.html), [stats::cor], [`Hmisc::rcorr`](https://rdrr.io/cran/Hmisc/man/rcorr.html). For using taxonomic identifications for clusters : [delineate_with_identification]. For further analyses: [set_reference_spectra].
30+
#' @seealso For similarity metrics: [`coop::tcosine`](https://rdrr.io/cran/coop/man/cosine.html), [stats::cor], [`Hmisc::rcorr`](https://rdrr.io/cran/Hmisc/man/rcorr.html). For using taxonomic identifications for clusters : [delineate_with_identification]. For further analyses: [set_reference_spectra].
3131
#' @export
3232
#' @examples
3333
#' # Toy similarity matrix between the six example spectra of

README.Rmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ processed <- spectra_dir %>%
5555
processed %>%
5656
list() %>%
5757
merge_processed_spectra() %>%
58-
t() %>%
59-
coop::cosine() %>%
58+
coop::tcosine() %>%
6059
delineate_with_similarity(threshold = 0.92) %>%
6160
set_reference_spectra(processed$metadata) %>%
6261
pick_spectra() %>%

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ processed <- spectra_dir %>%
5050
processed %>%
5151
list() %>%
5252
merge_processed_spectra() %>%
53-
t() %>%
54-
coop::cosine() %>%
53+
coop::tcosine() %>%
5554
delineate_with_similarity(threshold = 0.92) %>%
5655
set_reference_spectra(processed$metadata) %>%
5756
pick_spectra() %>%

dev/dereplicate-spectra.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ Once all the batches of spectra have been processed together, we can use a dista
362362

363363
While we do not provide specific functions to generate the similarity matrix, we illustrate below how it can be easily computed.
364364
Note that the feature matrix from [`merge_processed_spectra()`](https://clavellab.github.io/maldipickr/reference/merge_processed_spectra.html) has spectra as rows and peaks values as columns.
365-
So to get a similarity matrix between spectra, the feature matrix must be transposed before cosine computation.
365+
So to get a similarity matrix between spectra, either the feature matrix must be transposed or a dedicated function must be used.
366366

367367
```{r similarity, eval=FALSE}
368368
# A. Compute the similarity matrix on the transposed feature matrix
@@ -372,8 +372,8 @@ sim_matrix <- stats::cor(t(fm), method = "pearson")
372372
# B.1 Install the coop package
373373
# install.packages("coop")
374374
375-
# B.2 Compute the similarity matrix on the transposed feature matrix
376-
sim_matrix <- coop::cosine(t(fm))
375+
# B.2 Compute the similarity matrix on the rows of the feature matrix
376+
sim_matrix <- coop::tcosine(fm)
377377
```
378378

379379
# Delineate clusters of spectra
@@ -418,7 +418,7 @@ This representation allows to infer the clusters easily. A table summarizes for
418418
#' 2. It uses base R functions to reduce the dependencies
419419
#'
420420
#'
421-
#' @seealso For similarity metrics: [`coop::cosine`](https://rdrr.io/cran/coop/man/cosine.html), [stats::cor], [`Hmisc::rcorr`](https://rdrr.io/cran/Hmisc/man/rcorr.html). For using taxonomic identifications for clusters : [delineate_with_identification]. For further analyses: [set_reference_spectra].
421+
#' @seealso For similarity metrics: [`coop::tcosine`](https://rdrr.io/cran/coop/man/cosine.html), [stats::cor], [`Hmisc::rcorr`](https://rdrr.io/cran/Hmisc/man/rcorr.html). For using taxonomic identifications for clusters : [delineate_with_identification]. For further analyses: [set_reference_spectra].
422422
#' @export
423423
delineate_with_similarity <- function(sim_matrix, threshold) {
424424
if (!is.matrix(sim_matrix)) {

man/delineate_with_similarity.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/dereplicate-bruker-maldi-biotyper-spectra.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Once all the batches of spectra have been processed together, we can use a dista
120120

121121
While we do not provide specific functions to generate the similarity matrix, we illustrate below how it can be easily computed.
122122
Note that the feature matrix from [`merge_processed_spectra()`](https://clavellab.github.io/maldipickr/reference/merge_processed_spectra.html) has spectra as rows and peaks values as columns.
123-
So to get a similarity matrix between spectra, the feature matrix must be transposed before cosine computation.
123+
So to get a similarity matrix between spectra, either the feature matrix must be transposed or a dedicated function must be used.
124124

125125

126126
```{r similarity, eval = FALSE}
@@ -131,8 +131,8 @@ sim_matrix <- stats::cor(t(fm), method = "pearson")
131131
# B.1 Install the coop package
132132
# install.packages("coop")
133133
134-
# B.2 Compute the similarity matrix on the transposed feature matrix
135-
sim_matrix <- coop::cosine(t(fm))
134+
# B.2 Compute the similarity matrix on the rows of the feature matrix
135+
sim_matrix <- coop::tcosine(fm)
136136
```
137137

138138
# Delineate clusters of spectra

0 commit comments

Comments
 (0)