Skip to content

Instantly share code, notes, and snippets.

@jspaezp
Created April 29, 2022 18:54
Show Gist options
  • Save jspaezp/93cf300d4aaeb94c410edfefab9c8124 to your computer and use it in GitHub Desktop.
Save jspaezp/93cf300d4aaeb94c410edfefab9c8124 to your computer and use it in GitHub Desktop.
sctree seurat workflow
---
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