Commit 5e66915e authored by AustinHartman's avatar AustinHartman
Browse files

update examples

parent 16897426
Loading
Loading
Loading
Loading
+12 −17
Original line number Diff line number Diff line
@@ -25,30 +25,28 @@ compute_hash <- function(data_df, vars_use) {
    return(hash)
}

#' Collapse counts
#' Collapse counts based on multiple categorical metadata columns
#'
#' @param counts_mat counts matrix where columns represent cells and rows
#' represent features
#' @param meta_data data.frame containing cell metadata
#' @param varnames subset of `meta_data` column names
#' @param min_cells_per_group minimum cells to keep collapsed group
#' @param keep_n keep or drop the `N`` column containing the number of
#' @param keep_n keep or drop the `N` column containing the number of
#' cells in each group. Default is `FALSE`
#' @param how method of collapsing counts from groups. `sum` or `mean`
#'
#' @importFrom data.table data.table
#'
#' @examples
#' library(Seurat)
#' m <- matrix(sample.int(8, 100*500, replace=TRUE),nrow=100, ncol=500)
#' rownames(m) <- paste0("G", 1:100)
#' colnames(m) <- paste0("C", 1:500)
#' o <- CreateSeuratObject(m)
#' o$md1 <- sample(c("a", "b"), 500, replace=TRUE)
#' o$md2 <- sample(c("c", "d"), 500, replace=TRUE)
#' data_collapsed <- collapse_counts(
#'     o@assays$RNA@counts, o@meta.data, c('md1', 'md2')
#' )
#' md1 <- sample(c("a", "b"), 500, replace=TRUE)
#' md2 <- sample(c("c", "d"), 500, replace=TRUE)
#' df <- data.frame(md1, md2)
#' data_collapsed <- collapse_counts(m, df, c("md1", "md2"))
#' head(data_collapsed$$counts_mat)
#'
#' @export
#'
@@ -364,16 +362,13 @@ pseudobulk_within <- function(
#'
#' @examples
#' \dontrun{
#'     library(Seurat)
#'     m <- matrix(sample.int(8, 100*500, replace=TRUE),nrow=100, ncol=500)
#'     rownames(m) <- paste0("G", 1:100)
#'     colnames(m) <- paste0("C", 1:500)
#'     o <- CreateSeuratObject(m)
#'     o$md1 <- sample(c("a", "b"), 500, replace = TRUE)
#'     o$md2 <- sample(c("c", "d"), 500, replace = TRUE)
#'     data_collapsed <- collapse_counts(
#'         o@assays$RNA@counts, o@meta.data, c('md1', 'md2')
#'     )
#'     md1 <- sample(c("a", "b"), 500, replace=TRUE)
#'     md2 <- sample(c("c", "d"), 500, replace=TRUE)
#'     df <- data.frame(md1, md2)
#'     data_collapsed <- collapse_counts(m, df, c("md1", "md2"))
#'     res_mat <- pseudobulk_deseq2(
#'         ~md1 + md1,
#'         data_collapsed$meta_data,
+8 −10
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
% Please edit documentation in R/pseudobulk.R
\name{collapse_counts}
\alias{collapse_counts}
\title{Collapse counts}
\title{Collapse counts based on multiple categorical metadata columns}
\usage{
collapse_counts(
  counts_mat,
@@ -23,24 +23,22 @@ represent features}

\item{min_cells_per_group}{minimum cells to keep collapsed group}

\item{keep_n}{keep or drop the `N`` column containing the number of
\item{keep_n}{keep or drop the `N` column containing the number of
cells in each group. Default is `FALSE`}

\item{how}{method of collapsing counts from groups. `sum` or `mean`}
}
\description{
Collapse counts
Collapse counts based on multiple categorical metadata columns
}
\examples{
library(Seurat)
m <- matrix(sample.int(8, 100*500, replace=TRUE),nrow=100, ncol=500)
rownames(m) <- paste0("G", 1:100)
colnames(m) <- paste0("C", 1:500)
o <- CreateSeuratObject(m)
o$md1 <- sample(c("a", "b"), 500, replace=TRUE)
o$md2 <- sample(c("c", "d"), 500, replace=TRUE)
data_collapsed <- collapse_counts(
    o@assays$RNA@counts, o@meta.data, c('md1', 'md2')
)
md1 <- sample(c("a", "b"), 500, replace=TRUE)
md2 <- sample(c("c", "d"), 500, replace=TRUE)
df <- data.frame(md1, md2)
data_collapsed <- collapse_counts(m, df, c("md1", "md2"))
head(data_collapsed$$counts_mat)

}
+5 −8
Original line number Diff line number Diff line
@@ -43,16 +43,13 @@ Pseudobulk DESeq2
}
\examples{
\dontrun{
    library(Seurat)
    m <- matrix(sample.int(8, 100*500, replace=TRUE),nrow=100, ncol=500)
    rownames(m) <- paste0("G", 1:100)
    colnames(m) <- paste0("C", 1:500)
    o <- CreateSeuratObject(m)
    o$md1 <- sample(c("a", "b"), 500, replace = TRUE)
    o$md2 <- sample(c("c", "d"), 500, replace = TRUE)
    data_collapsed <- collapse_counts(
        o@assays$RNA@counts, o@meta.data, c('md1', 'md2')
    )
    md1 <- sample(c("a", "b"), 500, replace=TRUE)
    md2 <- sample(c("c", "d"), 500, replace=TRUE)
    df <- data.frame(md1, md2)
    data_collapsed <- collapse_counts(m, df, c("md1", "md2"))
    res_mat <- pseudobulk_deseq2(
        ~md1 + md1,
        data_collapsed$meta_data,
+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ group labels.

```{r}
data(object_seurat)
# ensure object structure matches with the installed Seurat version
object_seurat <- UpdateSeuratObject(object_seurat)
head(wilcoxauc(object_seurat, 'cell_type'))

```