rezakj / iCellR

Single (i) Cell R package (iCellR) is an interactive R package to work with high-throughput single cell sequencing technologies (i.e scRNA-seq, scVDJ-seq, scATAC-seq, CITE-Seq and Spatial Transcriptomics (ST)).
120 stars 19 forks source link

data input from other object #2

Closed zehualilab closed 4 years ago

zehualilab commented 5 years ago

Thanks for this wonderful tool! Does this package have any functions to input data from other objects like seurat, cds or singlecellexperiment? Or is there any way to create an object with established metadata containing the clustering information? I am really looking forward to that.

rezakj commented 5 years ago

Hi, thanks for your comment and using iCellR. Yes, it is possible to convert a Seurat object or other objects to an iCellR object. I will make a function that would do it and add it in the next version. But for now you can manually do it this way:

read Seurat object and name it OBJ for example. OBJ <- readRDS("Seurat.rds")

get the raw data from your Seurat object my.data <- as.data.frame(as.matrix(OBJ@raw.data))

make an iCellR object with the raw data and name it my.obj.

library(iCellR)
my.obj <- make.obj(my.data)

# make sure it's made properly
slotNames(my.obj)
my.obj

Now that you have an iCellR object you can transfer other data slots and add them. Example: add main data (filtered and normalized) my.obj@main.data <- as.data.frame(as.matrix(OBJ@data)) add clustering data

Clust <- as.data.frame(as.matrix(OBJ@ident))
colnames(Clust) <- "clusters"
my.obj@best.clust <- Clust

add tSNE data my.obj@tsne.data <- as.data.frame(as.matrix(OBJ@dr$tsne@cell.embeddings)) save your iCelR object save(my.obj, file = "my.obj.Robj") Hope this helps. Reza

zehualilab commented 5 years ago

Thank you so much for your help! It worked fine with me.

zehualilab commented 5 years ago

Thank you so mich for your help! I have successfully transformed my Seurat object to iCellR object with counts/normalized/scaled data and reduction data. I just fail to figure out the slot of iCellR object corresponding with the metadata slot in Seurat object. I am looking forward to transforming the metadata to the conditions in iCellR object. And also, is there any way to add more slots in my iCellR object? Thanks so much!

rezakj commented 5 years ago

Conditions in iCellR are set in the header of the data and are separated by an underscore (_). You can add your meta data field of interest for each cell id like this: WT_AAACATACAACCAC-1 In this case "WT" is the condition for the cell "AAACATACAACCAC-1". For now you can just change the header (column names) for your raw.data slot or main.data slot, but I will make this easier in the future.

Adding a slot to iCellR might not help you as there are not codes to make it functional. But I will add this slot in the next version and make it functional. For now just change the header.

Also, the stats slot is kind of meta data (mito info, coverage per cell, etc.) so if you want just add more columns to this slot to keep your extra data saved without making a new slot.

zehualilab commented 4 years ago

Thanks for your help, it worked fine with me!