-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[r] Add pbmc3k dataset helper (#792)
* Add method for creating seurat pbmc3k dataset * Update news * Bump version and update docs
- Loading branch information
1 parent
2a148c5
commit 8dda13a
Showing
5 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#' Seurat 3k PBMCs from 10x Genomics | ||
#' | ||
#' Create a [`SeuratObject::Seurat`] object containing the widely used 3k PBMCs | ||
#' dataset from 10x Genomics. | ||
#' | ||
#' @returns a [`SeuratObject::Seurat`] object | ||
#' @seealso https://support.10xgenomics.com/single-cell-gene-expression/datasets/1.1.0/pbmc3k | ||
#' @importFrom Matrix readMM | ||
#' @importFrom utils download.file read.table untar | ||
#' @export | ||
|
||
dataset_seurat_pbmc3k <- function() { | ||
url <- "https://cf.10xgenomics.com/samples/cell-exp/1.1.0/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz" | ||
|
||
tarfile <- file.path(tempdir(), basename(url)) | ||
tardir <- sub("\\.tar\\.gz$", "", tarfile) | ||
datadir <- file.path(tardir, "filtered_gene_bc_matrices", "hg19") | ||
|
||
if (!dir.exists(tardir)) { | ||
if (!file.exists(tarfile)) { | ||
utils::download.file(url = url, destfile = tarfile) | ||
} | ||
utils::untar(tarfile, exdir = tardir) | ||
} | ||
|
||
mat <- Matrix::readMM(file.path(datadir, "matrix.mtx")) | ||
genes <- utils::read.table( | ||
file = file.path(datadir, "genes.tsv"), | ||
header = FALSE, | ||
col.names = c("id", "gene_name") | ||
) | ||
barcodes <- utils::read.table( | ||
file = file.path(datadir, "barcodes.tsv"), | ||
header = FALSE, | ||
col.names = "id" | ||
) | ||
dimnames(mat) <- list(genes$id, barcodes$id) | ||
|
||
object <- SeuratObject::CreateSeuratObject(counts = mat) | ||
object[["RNA"]] <- SeuratObject::AddMetaData( | ||
object = object[["RNA"]], | ||
metadata = genes$gene_name, | ||
col.name = "gene_name" | ||
) | ||
object | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.