Created
April 29, 2022 18:54
-
-
Save jspaezp/93cf300d4aaeb94c410edfefab9c8124 to your computer and use it in GitHub Desktop.
sctree seurat workflow
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
--- | |
title: "SctreeSeuratWorkflow" | |
output: html_document | |
date: '2022-04-29' | |
--- | |
```{r} | |
# Modified from https://satijalab.org/seurat/articles/pbmc3k_tutorial.html | |
library(dplyr) | |
library(Seurat) | |
library(patchwork) | |
tempfilename <- tempfile() | |
download.file(url="https://cf.10xgenomics.com/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz", destfile = tempfilename) | |
tempdirname <- tempdir() | |
untar(tarfile = tempfilename, exdir = tempdirname) | |
counts_dir <- paste0(tempdirname, "/", "filtered_gene_bc_matrices/hg19/") | |
# Load the PBMC dataset | |
pbmc.data <- Read10X(data.dir = counts_dir) | |
# Initialize the Seurat object with the raw (non-normalized data). | |
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200) | |
pbmc <- NormalizeData(pbmc) | |
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000) | |
pbmc <- ScaleData(pbmc) | |
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc)) | |
pbmc <- FindNeighbors(pbmc, dims = 1:10) | |
pbmc <- FindClusters(pbmc, resolution = 0.5) | |
pbmc <- RunUMAP(pbmc, dims = 1:10) | |
``` | |
```{r fig.height=15, fig.width=15} | |
markers <- FindAllMarkers( | |
pbmc, | |
warn.imp.method = FALSE, | |
test.use = "RangerDE") | |
top_markers = markers$gene[1:6] | |
tree_fit <- fit_ctree( | |
pbmc, | |
genes_use = top_markers, | |
cluster = "ALL") | |
plot_gates(pbmc, tree_fit, "20") | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment