Skip to content

Commit

Permalink
Add matrix with right dimensions to pseudobulk.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiez committed Jul 18, 2024
1 parent 93b3102 commit 9b6ab7d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions R/pseudobulk.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,27 @@ pseudobulk.Seurat <- function(x, split.by, group.by, samples=NULL, genes=NULL, a
})
names(xl) <- group_levels

# if (is.null(samples)) {
# samples <- x[[]][[group.by]]
# if (!is.factor(samples))
# samples <- factor(samples)
if (is.null(samples)) {
samples <- x[[]][[group.by]]
if (!is.factor(samples))
samples <- factor(samples)

# samples <- levels(samples)
# samples <- data.frame(row.names=samples)
# }
samples <- levels(samples)
samples <- data.frame(row.names=samples)
}

xl <- lapply(xl, function(x) {
m <- matrix(0, nrow=nrow(x), ncol=length(samples))

if (packageVersion("Seurat") >= "5.0.0")
tmp <- Seurat::AggregateExpression(x, group.by=group.by, assay=assay)[[assay]]
else
tmp <- Seurat:::PseudobulkExpression(x, pb.method="aggregate", group.by=group.by, assay=assay, slot=layers[1])[[assay]]

if (!is.null(samples))
tmp <- tmp[, rownames(samples)]
tmp
m[rownames(tmp), colnames(tmp)] <- tmp
#tmp <- tmp[, rownames(samples)]
#tmp
m
})

dge <- lapply(names(xl), function(n) {
Expand All @@ -63,7 +66,7 @@ pseudobulk.Seurat <- function(x, split.by, group.by, samples=NULL, genes=NULL, a
#tmp <- edgeR::DGEList(xl[[n]])#, samples=s)
#tmp$genes <- genes
tmp <- xl[[n]]
colnames(tmp) <- unname(colnames(tmp))
#colnames(tmp) <- unname(colnames(tmp))
tmp
})
names(dge) <- names(xl)
Expand Down

0 comments on commit 9b6ab7d

Please sign in to comment.