Convert Seurat to iCellR - rezakj/iCellR GitHub Wiki
How to convert from a Seurat 5 object
- Get the raw data
library(iCellR)
library(Seurat)
objectName <- readRDS("../my.seurat.rds")
my.data <- as.data.frame(as.matrix(objectName@assays$RNA@layers$counts))
rownames(my.data) <- rownames(objectName@assays$RNA@[email protected])
colnames(my.data) <- rownames(objectName@assays$RNA@[email protected])
head(my.data)[1:3]
- Get PCA, UMAP and clusters
myPCA <- as.data.frame(objectName@[email protected])
head(myPCA)
myUMAP <- as.data.frame(objectName@[email protected])
colnames(myUMAP) <- c("V1","V2")
head(myUMAP)
MyClust <- as.data.frame([email protected])
colnames(MyClust) <- "clusters"
head(MyClust)
To add condition names, modify the row names in the raw data and the column names in the PCA, UMAP, and cluster data before creating the iCellR object. Conditions in iCellR are defined or displayed in the column names of the data and are separated by an underscore (_) sign.
###### Optional but good to do
# get the cell IDs
MyUMIs <- colnames(my.data)
# clean the UMIs if they have "_". Replace "_" with "."
MyUMIs <- gsub("-",".",MyUMIs)
MyUMIs <- gsub("_",".",MyUMIs)
# if you want to get the condition names and add them to the rownames, find them in the meta data
# meta.data <- ([email protected])
# replace UMIs with corrected names and added conditions if needed
rownames(myPCA) <- MyUMIs
rownames(myUMAP) <- MyUMIs
rownames(MyClust) <- MyUMIs
colnames(my.data) <- MyUMIs
- Make iCellR object
my.obj <- make.obj(my.data)
# make the raw data to also be the main data
[email protected] <- [email protected]
# normalize the main data using iCellR normalization
# my.obj <- norm.data(my.obj, norm.method = "ranked.glsf", top.rank = 500)
[email protected] <- myPCA
[email protected] <- myUMAP
[email protected] <- MyClust
# Alternatively you re-run PCA and UMAP if needed.
my.obj
Now you can use iCellR for the rest of the analysis.