Skip to content

Instantly share code, notes, and snippets.

@crazyhottommy
Created January 4, 2019 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyhottommy/335d52845807ed4ed6588d8a848efca6 to your computer and use it in GitHub Desktop.
Save crazyhottommy/335d52845807ed4ed6588d8a848efca6 to your computer and use it in GitHub Desktop.
library(splatter)
library(scater)
library(scran)
library(Seurat)
library(dplyr)

# Load the PBMC dataset https://s3-us-west-2.amazonaws.com/10x.files/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz
pbmc.data <- Read10X(data.dir = "~/Downloads/filtered_gene_bc_matrices/hg19/")

pbmc <- CreateSeuratObject(raw.data = pbmc.data, min.cells = 3, min.genes = 200, 
    project = "10X_PBMC")
# turn the sparse matrix to dense for splatter, pbmc is the 2700 cell seurat object
params <- splatEstimate(as.matrix(pbmc@raw.data))

# set the number of cells for each cluster
cells<- c(1000, 500, 400, 200, 200, 100, 100, 100, 60, 40)
sim <- splatSimulate(params, method = "groups", seed = 352412, 
                     group.prob = cells/sum(cells) ,
                     de.prob = c(0.3, 0.15, 0.3, 0.1, 0.3, 0.15, 0.15, 0.1, 0.1, 0.4))

sce <- computeSumFactors(sim)
sce <- normalize(sce)
summary(sizeFactors(sce))
var.fit <- trendVar(sce, parametric=TRUE, use.spikes=F,
    loess.args=list(span=0.3))
var.out <- decomposeVar(sce, var.fit)
head(var.out)
sce <- denoisePCA(sce, technical=var.out)
dim(reducedDim(sce, "PCA")) 

set.seed(100)
plotTSNE(sce, run_args=list(use_dimred="PCA", perplexity=50),
    colour_by="Group") + ggtitle("Perplexity = 50")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment