Skip to content

Interfacing with Other Applications

EDePasquale edited this page Jul 15, 2020 · 3 revisions

In Progress!

This is where we will be providing code and guidance on how to incorporate DoubletDecon doublet predictions into other bioinformatics workflows. If you have any suggestions for things you would like to see on this page, please send them to [email protected] or [email protected].


Contents:

  • Seurat UMAP with projected DoubletDecon doublet predictions
  • More in progress!

Code Snippets:

Seurat UMAP with projected DoubletDecon doublet predictions

(R version 4.0.2,
Seurat version 3.1.5)

Load required packages

library(Seurat)
library(DoubletDecon)
BiocPackages=c("DeconRNASeq", "clusterProfiler", "hopach", "mygene", 
               "tidyr", "R.utils", "foreach", "doParallel", "stringr","dplyr")
lapply(BiocPackages,library, character.only = TRUE) 
library(MCL)
library(dplyr)
library(ggplot2)

Set location of the directory containing the datasets

inDataPath="/DS/DoubletDeconForReal/STAR Protocol/July2020Vignette/"
outDataPath=inDataPath
setwd(inDataPath)

Prepare Seurat files for use with DoubletDecon

## Update Seurat object is handy if it was
##  created with an older version of Seurat
seuratObject=UpdateSeuratObject(readRDS("seurat.rds"))
newFiles=Improved_Seurat_Pre_Process(seuratObject, num_genes=50, write_files=FALSE)
location=outDataPath
filename="PBMC_example"
write.table(newFiles$newExpressionFile, paste0(location, filename, "_expression"), sep="\t")
write.table(newFiles$newFullExpressionFile, paste0(location, filename, "_fullExpression"), sep="\t")
write.table(newFiles$newGroupsFile, paste0(location, filename , "_groups"), sep="\t", col.names = F)

Run DoubletDecon and close graphics device so start fresh for UMAP plot

results=Main_Doublet_Decon(rawDataFile=newFiles$newExpressionFile, 
                           groupsFile=newFiles$newGroupsFile, 
                           filename=filename, 
                           location=location,
                           fullDataFile=NULL, 
                           removeCC=FALSE, 
                           species="hsa", 
                           rhop=1.1, 
                           write=TRUE, 
                           PMF=FALSE, 
                           useFull=FALSE, 
                           heatmap=FALSE,
                           centroids=TRUE,
                           num_doubs=100, 
                           only50=FALSE,
                           min_uniq=4,
                           nCores=1)
dev.off()

Create UMAP with DoubletDecon results using Seurat (start here if you have previously ran DoubletDecon)

DRS_doublet_table=results$DRS_doublet_table
addmargins(table(DRS_doublet_table$isADoublet))
DRS_doublet_table$Dlabel=factor(DRS_doublet_table$isADoublet,c(FALSE,TRUE),ordered = T, labels=c("Singlet","Doublet"))
seuratObject=AddMetaData(seuratObject,DRS_doublet_table$Dlabel, col.name = "Dlabel")
Idents(seuratObject)[email protected]$Dlabel
dp1=DimPlot(seuratObject,reduction="umap")
dp1=dp1 +
  theme(legend.position="top") +
  theme(axis.text = element_text(size=9),
        axis.title = element_text(size=10),
        legend.text = element_text(size=9))
dp1
quit()

The final result!