-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCENIC_pre-processing.R
More file actions
58 lines (47 loc) · 2.94 KB
/
SCENIC_pre-processing.R
File metadata and controls
58 lines (47 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
####################################################################################
############## SCENIC PRE-PROCESSING STEPS ###################
############## CONVERTION OF THE INITIAL SEURAT OBJECT TO A .mtx FORMAT ##########
####################################################################################
library(Seurat)
library(Matrix) # For sparse matrix handling and writeMM()
# Load the integrated initial Seurat object
seurat_obj <- readRDS("integrated.rds")
# Create a data.frame containing gene names
# Monocle3 requires a gene_metadata table with at least "gene_short_name"
feature_names <- as.data.frame(rownames(seu_annotated))
# Set rownames to gene names (same order as expression matrix)
rownames(feature_names) <- rownames(seu_annotated)
# Rename the column to the required Monocle3 field
colnames(feature_names) <- "gene_short_name"
# Convert Seurat object to a Monocle3 CellDataSet
# Use raw "counts" (required for SCENIC)
seu_monocl <- monocle3::new_cell_data_set(Seurat::GetAssayData(seu_annotated,
layer = "counts"),
cell_metadata = seu_annotated@meta.data,
gene_metadata = feature_names)
# Define experimental groups based on orig.ident
groupe_HET <- c("LHX2_HET_3","LHX2_HET_4")
groupe_KO <- c("LHX2_KO_5","LHX2_KO_6")
groupe_WT <- c("LHX2_WT_1r","LHX2_WT_2r")
# Subset the Monocle object by condition
seu_HET <- seu_monocl[, colData(seu_monocl)$orig.ident %in% groupe_HET]
seu_KO <- seu_monocl[, colData(seu_monocl)$orig.ident %in% groupe_KO]
seu_WT <- seu_monocl[, colData(seu_monocl)$orig.ident %in% groupe_WT]
# Extract expression matrices (raw counts)
expr_mat_HET <- assay(seu_HET, "counts")
expr_mat_KO <- assay(seu_KO, "counts")
expr_mat_WT <- assay(seu_WT, "counts")
# Write matrices and annotations to disk (Matrix Market format)
# Required for SCENIC and other downstream tools
# ----- HET -----
writeMM(expr_mat_HET, "expr_mat_HET.mtx") # Sparse count matrix
write.table(rownames(expr_mat_HET), "genes_HET.txt", quote=FALSE, row.names = FALSE, col.names = FALSE) # Gene names
write.table(colnames(expr_mat_HET), "cells_HET.txt", quote=FALSE, row.names = FALSE, col.names = FALSE) # Cell barcodes
# ----- KO -----
writeMM(expr_mat_KO, "expr_mat_KO.mtx") # Sparse count matrix
write.table(rownames(expr_mat_KO), "genes_KO.txt", quote=FALSE, row.names = FALSE, col.names = FALSE) # Gene names
write.table(colnames(expr_mat_KO), "cells_KO.txt", quote=FALSE, row.names = FALSE, col.names = FALSE) # Cell barcodes
# ----- WT -----
writeMM(expr_mat_WT, "expr_mat_WT.mtx") # Sparse count matrix
write.table(rownames(expr_mat_WT), "genes_WT.txt", quote=FALSE, row.names = FALSE, col.names = FALSE) # Gene names
write.table(colnames(expr_mat_WT), "cells_WT.txt", quote=FALSE, row.names = FALSE, col.names = FALSE) # Cell barcodes