Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collective updates #303

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,12 @@ Suggests:
ggrepel,
gprofiler2,
IRanges,
irlba,
knitr,
org.Hs.eg.db,
plotly,
psych,
RcppPlanc,
reactome.db,
rgl,
rglwidget,
rmarkdown,
sankey,
scattermore (>= 0.7),
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ S3method(plotSpatial2D,liger)
S3method(plotSpatial2D,ligerSpatialDataset)
S3method(quantileNorm,Seurat)
S3method(quantileNorm,liger)
S3method(runCINMF,Seurat)
S3method(runCINMF,liger)
S3method(runINMF,Seurat)
S3method(runINMF,liger)
S3method(runIntegration,Seurat)
Expand Down Expand Up @@ -156,6 +158,7 @@ export(restoreH5Liger)
export(restoreOnlineLiger)
export(retrieveCellFeature)
export(reverseMethData)
export(runCINMF)
export(runCluster)
export(runDoubletFinder)
export(runGOEnrich)
Expand Down
8 changes: 8 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ RunModularityClusteringCpp <- function(SNN, modularityFunction, resolution, algo
.Call(`_rliger2_RunModularityClusteringCpp`, SNN, modularityFunction, resolution, algorithm, nRandomStarts, nIterations, randomSeed, printOutput, edgefilename)
}

colNormalize_dense_cpp <- function(x, L) {
.Call(`_rliger2_colNormalize_dense_cpp`, x, L)
}

colAggregateMedian_dense_cpp <- function(x, group, n) {
.Call(`_rliger2_colAggregateMedian_dense_cpp`, x, group, n)
}

scaleNotCenter_byRow_rcpp <- function(x) {
.Call(`_rliger2_scaleNotCenter_byRow_rcpp`, x)
}
Expand Down
123 changes: 0 additions & 123 deletions R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,126 +107,3 @@
# featureIdx
# return(ld)
# }

#' #' Perform Wilcoxon rank-sum test
#' #' @description Perform Wilcoxon rank-sum tests on specified dataset using
#' #' given method.
#' #' @param object A \linkS4class{liger} object with cluster assignment available.
#' #' @param useDatasets A character vector of the names, a numeric or logical
#' #' vector of the index of the datasets to be normalized. Default
#' #' \code{NULL} uses all datasets.
#' #' @param method Choose from \code{"clusters"} or \code{"datasets"}. Default
#' #' \code{"clusters"} compares between clusters across all datasets, while
#' #' \code{"datasets"} compares between datasets within each cluster.
#' #' @param useCluster The name of the column in \code{cellMeta} slot storing the
#' #' cluster assignment variable. Default \code{"leiden_cluster"}
#' #' @param usePeak Logical, whether to test peak counts instead of gene
#' #' expression. Requires presence of ATAC modility datasets. Default
#' #' \code{FALSE}.
#' #' @param verbose Logical. Whether to show information of the progress. Default
#' #' \code{getOption("ligerVerbose")} which is \code{TRUE} if users have not set.
#' #' @param data.use,compare.method \bold{Deprecated}. See Usage section for
#' #' replacement.
#' #' @return A 10-columns data.frame with test results.
#' #' @export
#' #' @examples
#' #' library(dplyr)
#' #' result <- runWilcoxon(pbmcPlot)
#' #' result %>% group_by(group) %>% top_n(2, logFC)
#' runWilcoxon <- function(
#' object,
#' useDatasets = NULL,
#' method = c("clusters", "datasets"),
#' useCluster = "leiden_cluster",
#' usePeak = FALSE,
#' verbose = getOption("ligerVerbose"),
#' # Deprecated coding style,
#' data.use = useDatasets,
#' compare.method = method
#' ) {
#' .deprecateArgs(list(data.use = "useDatasets", compare.method = "method"))
#' method <- match.arg(method)
#' # Input checks ####
#' useDatasets <- .checkUseDatasets(object, useDatasets,
#' modal = ifelse(usePeak, "atac", "default"))
#' if (!isTRUE(usePeak)) {
#' if (method == "datasets" & length(useDatasets) < 2)
#' stop("Should have at least 2 datasets as input ",
#' "when compare between datasets")
#' if (isH5Liger(object, useDatasets)) {
#' stop("HDF5 based datasets detected but is not supported. \n",
#' "Try `object.sub <- downsample(object, useSlot = ",
#' "'normData')` to create ANOTHER object with in memory data.")
#' }
#' allNormed <- all(sapply(datasets(object),
#' function(ld) !is.null(normData(ld))))
#' if (!allNormed)
#' stop("All datasets being involved has to be normalized")
#'
#' ## get all shared genes of datasets involved
#' normDataList <- getMatrix(object, "normData", dataset = useDatasets,
#' returnList = TRUE)
#' features <- Reduce(intersect, lapply(normDataList, rownames))
#' normDataList <- lapply(normDataList, function(x) x[features,])
#' featureMatrix <- Reduce(cbind, normDataList)
#' } else {
#' if (method == "datasets" || length(useDatasets) != 1)
#' stop("For wilcoxon test on peak counts, can only use ",
#' "\"cluster\" method on one dataset.")
#' normPeakList <- lapply(useDatasets, function(d) normPeak(object, d))
#' features <- Reduce(intersect, lapply(normPeakList, rownames))
#' featureMatrix <- Reduce(cbind, normPeakList)
#' #featureMatrix <- normPeak(object, useDatasets)
#' if (is.null(featureMatrix))
#' stop("Peak counts of specified dataset has to be normalized. ",
#' "Please try `normalizePeak(object, useDatasets = '",
#' useDatasets, "')`.")
#' #features <- rownames(featureMatrix)
#' }
#'
#' ## Subset metadata involved
#' cellIdx <- object$dataset %in% useDatasets
#' cellSource <- object$dataset[cellIdx]
#' clusters <- .fetchCellMetaVar(object, useCluster, cellIdx = cellIdx,
#' checkCategorical = TRUE)
#'
#' if (isTRUE(verbose))
#' .log("Performing Wilcoxon test on ", length(useDatasets), " datasets: ",
#' paste(useDatasets, collapse = ", "))
#' # perform wilcoxon test ####
#' if (method == "clusters") {
#' # compare between clusters across datasets
#' nfeatures <- length(features)
#' if (nfeatures > 100000) {
#' if (isTRUE(verbose)) .log("Calculating Large-scale Input...")
#' results <- Reduce(rbind, lapply(
#' suppressWarnings(split(seq(nfeatures),
#' seq(nfeatures / 100000))),
#' function(index) {
#' fm <- log1p(1e10*featureMatrix[index, ])
#' wilcoxauc(fm, clusters)
#' }))
#' } else {
#' # TODO: If we add log-transformation to normalization method in the
#' # future, remember to have conditions here.
#' fm <- log1p(1e10*featureMatrix)
#' results <- wilcoxauc(fm, clusters)
#' }
#' } else {
#' # compare between datasets within each cluster
#' results <- Reduce(rbind, lapply(levels(clusters), function(cluster) {
#' clusterIdx <- clusters == cluster
#' subLabel <- paste0(cluster, "-", cellSource[clusterIdx])
#' if (length(unique(subLabel)) == 1) {
#' # if cluster has only 1 data source
#' warning("Skipped Cluster ", cluster,
#' " since it has only one dataset source.")
#' return()
#' } else {
#' subMatrix <- log1p(1e10*featureMatrix[, clusterIdx])
#' return(wilcoxauc(subMatrix, subLabel))
#' }
#' }))
#' }
#' return(results)
#' }
Loading
Loading