Skip to content

Commit

Permalink
spelling & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jashapiro committed Nov 19, 2024
1 parent 53eb748 commit a44e296
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 58 deletions.
37 changes: 2 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repos:
- id: check-case-conflict
- id: check-merge-conflict
- id: trailing-whitespace
exclude: 'renv/.*'
- id: end-of-file-fixer
exclude: '\.Rd'

Expand All @@ -33,43 +34,9 @@ repos:
# codemeta must be above use-tidy-description when both are used
# - id: codemeta-description-updated
- id: use-tidy-description
- id: spell-check
exclude: >
(?x)^(
.*\.[rR]|
.*\.feather|
.*\.jpeg|
.*\.pdf|
.*\.png|
.*\.py|
.*\.RData|
.*\.rds|
.*\.Rds|
.*\.Rproj|
.*\.sh|
(.*/|)\.gitignore|
(.*/|)\.gitlab-ci\.yml|
(.*/|)\.lintr|
(.*/|)\.pre-commit-.*|
(.*/|)\.Rbuildignore|
(.*/|)\.Renviron|
(.*/|)\.Rprofile|
(.*/|)\.travis\.yml|
(.*/|)appveyor\.yml|
(.*/|)DESCRIPTION|
(.*/|)NAMESPACE|
(.*/|)renv/settings\.dcf|
(.*/|)renv.*\.lock|
(.*/|)requirements.*\.in|
(.*/|)requirements.*\.txt|
(.*/|).*Dockerfile|
(.*/|)WORDLIST|
\.github/workflows/.*|
data/.*|
)$
- id: lintr
- id: parsable-R
- id: no-browser-statement
- id: no-debug-statement
- id: deps-in-desc
exclude: docker/.*
exclude: 'docker/.*|renv/.*'
30 changes: 18 additions & 12 deletions R/calculate-clusters.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
#' Calculate graph-based clusters from a provided matrix
#'
#' This function is provided to simplify application of bluster package clustering functions on OpenScPCA data.
#' In particular, this function runs bluster::clusterRows() with the bluster::NNGraphParam() function on a
#' In particular, this function runs `bluster::clusterRows()` with the `bluster::NNGraphParam()` function on a
#' principal components matrix, provided either directly or via single-cell object.
#' Note that defaults for some arguments may differ from the bluster::NNGraphParam() defaults.
#' Note that defaults for some arguments may differ from the `bluster::NNGraphParam()` defaults.
#' Specifically, the clustering algorithm defaults to "louvain" and the weighting scheme to "jaccard"
#' to align with common practice in scRNA-seq analysis.
#'
#' @import methods
#'
#' @param x An object containing PCs that clustering can be performed in. This can be either a SingleCellExperiment
#' object, a Seurat object, or a matrix where columns are PCs and rows are cells. If a matrix is provided, it must
#' have row names of cell ids (e.g., barcodes).
#' object, a Seurat object, or a matrix where columns are PCs and rows are cells.
#' If a matrix is provided, it must have row names of cell ids (e.g., barcodes).
#' @param algorithm Clustering algorithm to use. Must be one of "louvain" (default), "walktrap", or "leiden".
#' @param weighting Weighting scheme to use. Must be one of "jaccard" (default), "rank", or "number"
#' @param nn Number of nearest neighbors. The default is 10.
#' @param resolution Resolution parameter used by louvain and leiden clustering only. Default is 1.
#' @param objective_function Leiden-specific parameter for whether to use the Constant Potts Model ("CPM"; default) or "modularity"
#' @param objective_function Leiden-specific parameter for whether to use the Constant Potts Model ("CPM"; default)
#' or "modularity"
#' @param cluster_args List of additional arguments to pass to the chosen clustering function.
#' Only single values for each argument are supported (no vectors or lists).
#' See igraph documentation for details on each clustering function: https://igraph.org/r/html/latest
#' See `igraph` documentation for details on each clustering function: <https://igraph.org/r/html/latest>
#' @param threads Number of threads to use. The default is 1.
#' @param seed Random seed to set for clustering.
#' @param pc_name Name of principal components slot in provided object. This argument is only used if a SingleCellExperiment
#' or Seurat object is provided. If not provided, the SingleCellExperiment object name will default to "PCA" and the
#' @param pc_name Name of principal components slot in provided object.
#' This argument is only used if a SingleCellExperiment or Seurat object is provided.
#' If not provided, the SingleCellExperiment object name will default to "PCA" and the
#' Seurat object name will default to "pca".
#'
#' @return A data frame of cluster results with columns `cell_id` and `cluster`. Additional columns represent algorithm parameters
#' and include at least: `algorithm`, `weighting`, and `nn`. Louvain and leiden clustering will also include `resolution`, and
#' leiden clustering will further include `objective_function`.
#' @return A data frame of cluster results with columns `cell_id` and `cluster`.
#' Additional columns represent algorithm parameters and include at least: `algorithm`, `weighting`, and `nn`.
#' Louvain and Leiden clustering will also include `resolution`,
#' and Leiden clustering will further include `objective_function`.
#'
#' @export
#'
Expand Down Expand Up @@ -242,7 +245,10 @@ prepare_pc_matrix <- function(x, pc_name = NULL) {
} else if (is(x, "SingleCellExperiment") || is(x, "Seurat")) {
x <- extract_pc_matrix(x, pc_name = pc_name)
} else {
stop("The first argument should be one of: a SingleCellExperiment object, a Seurat object, or a matrix with row names.")
stop(
"The first argument should be one of: ",
"a SingleCellExperiment object, a Seurat object, or a matrix with row names."
)
}

return(x)
Expand Down
25 changes: 14 additions & 11 deletions man/calculate_clusters.Rd

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

1 change: 1 addition & 0 deletions rOpenScPCA.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

0 comments on commit a44e296

Please sign in to comment.