Skip to content

Commit

Permalink
Merge branch 'issue-26' into dev (close #26, #43)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Oct 5, 2023
2 parents 09bd0e3 + 7a12d81 commit 810b8dd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 32 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: DIscBIO
Date: 2021-04-28
Title: A User-Friendly Pipeline for Biomarker Discovery in Single-Cell Transcriptomics
Version: 1.2.0.9003
Version: 1.2.0.9004
Authors@R:
c(
person(
Expand Down Expand Up @@ -38,7 +38,7 @@ Description: An open, multi-algorithmic pipeline for easy, fast and efficient
<doi:10.1101/700989>.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: methods, TSCAN, boot, httr, mclust, statmod, igraph,
Imports: methods, TSCAN, httr, mclust, statmod, igraph,
RWeka, philentropy, NetIndices, png, grDevices,
RColorBrewer, ggplot2, rpart, fpc, cluster, rpart.plot,
tsne, AnnotationDbi, org.Hs.eg.db, graphics, stats, utils, impute,
Expand Down Expand Up @@ -87,6 +87,7 @@ Collate:
'RpartDT.R'
'RpartEVAL.R'
'VolcanoPlot.R'
'bootstrap.R'
'calc_pcareduceres.R'
'cross.val.R'
'customConverters.R'
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ importFrom(NetIndices,GenInd)
importFrom(RColorBrewer,brewer.pal)
importFrom(RWeka,J48)
importFrom(TSCAN,TSCANorder)
importFrom(boot,boot)
importFrom(cluster,clusGap)
importFrom(cluster,maxSE)
importFrom(cluster,silhouette)
Expand Down
28 changes: 3 additions & 25 deletions R/Jaccard.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,26 @@
#' @param K A numeric value of the number of clusters
#' @param plot if `TRUE`, plots the mean Jaccard similarities
#' @param R number of bootstrap replicates
#' @param ... Further arguments passed to \code{boot::boot}
#' @importFrom philentropy distance
#' @importFrom boot boot
#' @importFrom graphics barplot box
#' @return A plot of the mean Jaccard similarity coefficient per cluster.
Jaccard <- function(
object,
Clustering = "K-means",
K,
plot = TRUE,
R = 100,
...) {
Jaccard <- function(object, Clustering = "K-means", K, plot = TRUE, R = 100) {
JACCARD <- vector()

# Validation
if (!(Clustering %in% c("K-means", "MB"))) {
stop("Clustering has to be either K-means or MB")
}

JS <- function(data, indices) {
d <- data[indices, ] # allows boot to select sample
jac <- suppressMessages(distance(t(d), method = "jaccard"))
jac1 <- 1 - jac
JSmean <- mean(jac1)
return(JSmean)
}
for (i in 1:K) {
# Optimize by avoiding if every loop. Only thing variable is data
if (Clustering == "K-means") {
target_col <- object@kmeans$kpart
} else if (Clustering == "MB") {
target_col <- object@MBclusters$clusterid
}
results <- boot(
data = object@fdata[, which(target_col == i)],
statistic = JS,
R = R,
stype = "f",
...
)
results <- bootstrap(object@fdata[, which(target_col == i)], R)
# to get the mean of all bootstrappings (mean of mean Jaccard values)
JACCARD[i] <- round(mean(results$t), digits = 3)
JACCARD[i] <- round(mean(results), digits = 3)
}
if (plot) {
barplot(
Expand Down
20 changes: 20 additions & 0 deletions R/bootstrap.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
bootstrap <- function(data, n_reps) {
results <- numeric(n_reps)
n <- nrow(data)
i <- matrix(sample(n, n * n_reps, replace = TRUE), n_reps, n)
freqs <- t(apply(i, 1, tabulate, ncol(i)))
for (rep in seq_len(n_reps)) {
samp <- freqs[rep, ]
jac <- JS(data, samp)
results[rep] <- mean(jac)
}
return(results)
}

JS <- function(data, indices) {
d <- data[indices, ]
jac <- suppressMessages(distance(t(d), method = "jaccard"))
jac1 <- 1 - jac
JSmean <- mean(jac1)
return(JSmean)
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocMana

BiocManager::install(
c(
"SingleCellExperimentmethods", "TSCAN", "boot", "httr", "mclust",
"SingleCellExperimentmethods", "TSCAN", "httr", "mclust",
"statmod", "igraph", "RWeka", "philentropy", "NetIndices", "png",
"grDevices", "RColorBrewer", "ggplot2", "rpart", "fpc",
"cluster", "rpart.plot", "tsne", "AnnotationDbi", "org.Hs.eg.db",
Expand Down
4 changes: 1 addition & 3 deletions man/Jaccard.Rd

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

0 comments on commit 810b8dd

Please sign in to comment.