library(reticulate) reticulate::install_miniconda() reticulate::use_condaenv() py_install("python-igraph") py_install("numpy") py_install("leidenalg", forge = TRUE) library(DIscBIO) library(leiden) library(M3Drop) load("SC.RData") # Loading the "SC" object filteredDataset<-SC@fdata xprs <- as.matrix(filteredDataset) xprs[xprs == min(xprs)] <- 0 top.feats <- M3Drop::M3DropFeatureSelection(expr_mat = xprs, mt_method = "fdr",suppress.plot = FALSE, mt_threshold = 0.5) ## Fits a Michaelis-Menten function to the dropout-rate. top.feats <- head(top.feats$Gene, 500) top.xprs <- xprs[top.feats, ] Adj <- stats::cor(top.xprs) QNT <- quantile(Adj, probs = c(0.5)) bin.Adj <- (Adj > QNT) + 0 lei.clusts <- leiden(bin.Adj, resolution_parameter = 0.5) # Leiden algorithm names(lei.clusts) <- colnames(bin.Adj) ### Visualizing the clusters SC@kmeans$kpart<-lei.clusts Factor<-factor(lei.clusts) K<- length(levels(Factor)) plottSNE(SC) # Silhouette plot withr::with_options(repr.plot.width=12, repr.plot.height=25) plotSilhouette(SC,K=K) # Jaccard Similarity withr::with_options(repr.plot.width=10, repr.plot.height=12) Jaccard(SC, K=K, plot = TRUE) lei.clusts <- leiden(bin.Adj, resolution_parameter = 1) # Leiden algorithm names(lei.clusts) <- colnames(bin.Adj) ### Visualizing the clusters SC@kmeans$kpart<-lei.clusts Factor<-factor(lei.clusts) K<- length(levels(Factor)) withr::with_options(repr.plot.width=6, repr.plot.height=6) plottSNE(SC) # Silhouette plot withr::with_options(repr.plot.width=12, repr.plot.height=25) plotSilhouette(SC,K=K) # Jaccard Similarity withr::with_options(repr.plot.width=10, repr.plot.height=12) Jaccard(SC, K=K, plot = TRUE)