Created
May 12, 2020 10:28
-
-
Save wenjie1991/f8c64d305699add06ef5be282cfa6634 to your computer and use it in GitHub Desktop.
scrublet in seurat pipeline
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
```{r} | |
library(reticulate) | |
# You can set the conda environment | |
use_condaenv("scrublet", required = T) | |
``` | |
```{python} | |
import scrublet as scr | |
import scipy.io | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import os | |
def predict_doublets(matrix): | |
counts_matrix = scipy.io.mmread(matrix).T.tocsc() | |
scrub = scr.Scrublet(counts_matrix, expected_doublet_rate=0.10) | |
doublet_scores, predicted_doublets = scrub.scrub_doublets(min_counts=2, min_cells=3, min_gene_variability_pctl=85, n_prin_comps=30) | |
#scrub.plot_histogram() | |
#scrub.set_embedding('UMAP', scr.get_umap(scrub.manifold_obs_, 10, min_dist=0.3)) | |
#scrub.plot_embedding('UMAP', order_points=True) | |
return scrub.doublet_scores_obs_ | |
matrix = "../data/00_filtered_feature_bc_matrix/count_Mutant/filtered_feature_bc_matrix/matrix.mtx" | |
ds_mt = predict_doublets(matrix) | |
matrix = "../data/00_filtered_feature_bc_matrix/count_Wild-type/filtered_feature_bc_matrix/matrix.mtx" | |
ds_wt = predict_doublets(matrix) | |
``` | |
```{r} | |
ds = c(py$ds_mt, py$ds_wt) | |
names(ds) = rownames(so[["orig.ident"]]) | |
# so is a seurat object | |
so[['doublet_score']] = ds | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment