Chapter 16 SCENIC
library(Seurat)
library(tidyverse)
library(magrittr)
library(SCENIC)
library(SingleCellExperiment)
library(SCopeLoomR)
16.1 Load Seurat Obj
<- readRDS('data/Demo_CombinedSeurat_SCT_Preprocess_FilterLQCells.rds')
combined Idents(combined) <- 'cluster'
DefaultAssay(combined) <- 'RNA'
<- NormalizeData(combined) combined
16.2 Filtering genes for calculating time
<- combined@assays$RNA@data
exprMat <- combined@meta.data
cellInfo
<- which(rowSums(exprMat) > 1*.01*ncol(exprMat))
loci1 <- exprMat[loci1, ] exprMat_filter
16.3 Tranfer into loom files
<- function(loom, cellAnnotation)
add_cell_annotation
{<- data.frame(cellAnnotation)
cellAnnotation if(any(c("nGene", "nUMI") %in% colnames(cellAnnotation)))
{warning("Columns 'nGene' and 'nUMI' will not be added as annotations to the loom file.")
<- cellAnnotation[,colnames(cellAnnotation) != "nGene", drop=FALSE]
cellAnnotation <- cellAnnotation[,colnames(cellAnnotation) != "nUMI", drop=FALSE]
cellAnnotation
}
if(ncol(cellAnnotation)<=0) stop("The cell annotation contains no columns")
if(!all(get_cell_ids(loom) %in% rownames(cellAnnotation))) stop("Cell IDs are missing in the annotation")
<- cellAnnotation[get_cell_ids(loom),,drop=FALSE]
cellAnnotation # Add annotation
for(cn in colnames(cellAnnotation))
{add_col_attr(loom=loom, key=cn, value=cellAnnotation[,cn])
}
invisible(loom)
}
<- build_loom("data/Demo_CombinedSeurat_SCT_Preprocess_FilterLQCells.loom", dgem=exprMat_filter)
loom <- add_cell_annotation(loom, cellInfo)
loom close_loom(loom)
16.4 Run SCENIC vis pySCENIC
GRN
pyscenic grn {loom_file} hs_hgnc_tfs.txt -o adj.csv --num_workers 20
CLI
pyscenic ctx adj.csv *feather --annotations_fname motifs-v9-nr.hgnc-m0.001-o0.0.tbl --expression_mtx_fname {loom_file} --output reg.csv --mask_dropouts --num_workers
AUCell
pyscenic aucell {loom_file} reg.csv --output {out_loom_file} --num_workers 20
16.5 Retrieve AUC scores per cell
- AUC scores
<- open_loom('data/Demo_CombinedSeurat_SCT_Preprocess_FilterLQCells.loom')
loom <- get_regulons(loom, column.attr.name="Regulons")
regulons_incidMat <- regulonsToGeneLists(regulons_incidMat)
regulons <- get_regulons_AUC(loom, column.attr.name='RegulonsAUC')
regulonAUC
saveRDS(list('regulons' = regulons, 'regulonAUC' = regulonAUC),
file = 'data/Demo_CombinedSeurat_SCT_Preprocess_FilterLQCells-pyscenic-output-AUC.rds')
- Binary AUC scores
from binarization import *
import pandas as pd
= pd.read_csv('test.auc.mat', sep = '\t')
auc_mtx
= binarize(auc_mtx)
auc_mtx_binary = pd.DataFrame(auc_mtx_binary[0]) test