Skip to content

Commit

Permalink
Sort samples (columns) by sample name.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiez committed Dec 9, 2023
1 parent 5b09aee commit f2e66c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 11 additions & 2 deletions R/pseudobulk.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@
#' @param genes A data.frame with gene information to include in slot "genes" in the DGEList object.
#' @param assay Seurat assay to use. Default: NULL (default assay).
#' @param layers Seurat layers to use. Default: counts.
#' @param sort_samples whetner to sort the columns of the pseudobulk samples based on the order in the samples data.frame.
#'
#' @export
pseudobulk <- function(x, split.by, group.by, samples=NULL, genes=NULL, ...) {
pseudobulk <- function(x, split.by, group.by, samples=NULL, genes=NULL, sort_samples=TRUE, ...) {
UseMethod("pseudobulk")
}

#' @rdname pseudobulk
#' @export
pseudobulk.Seurat <- function(x, split.by, group.by, samples=NULL, genes=NULL, assay=NULL, layers="counts", sort_samples=TRUE, ...) {
if (!is.null(assay))
DefaultAssay(x) <- assay

assay <- DefaultAssay(x)

if (packageVersion("Seurat") >= "5.0.0")
x <- Seurat::DietSeurat(x, layers=layers, assay=assay)
x <- Seurat::DietSeurat(x, layers=layers, assay=assay)
else
x <- Seurat::DietSeurat(x, counts=TRUE, data=TRUE, assay=assay)

Expand Down Expand Up @@ -62,5 +65,11 @@ pseudobulk <- function(x, split.by, group.by, samples=NULL, genes=NULL, ...) {
})
names(dge) <- names(xl)

if (sort_samples) {
dge <- lapply(dge, function(x) {
x[, sort(rownames(samples))]
})
}

dge
}
13 changes: 12 additions & 1 deletion man/pseudobulk.Rd

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

0 comments on commit f2e66c3

Please sign in to comment.