HaojiaWu / CellScopes.jl

A Julia package for single cell and spatial data analysis
MIT License
27 stars 2 forks source link

How to Subset CellScopes Objects with Metadata from Seurat or stLearn #12

Open YuxiZhang-0113 opened 2 months ago

YuxiZhang-0113 commented 2 months ago

Hi,

I've been testing CellScopes with various spatial transcriptomics datasets and find its capabilities very impressive. However, I encountered an issue when trying to subset CellScopes objects.

I often use metadata from objects processed with Seurat or stLearn and integrate this metadata into a processed CellScopes object for visualization. Sometimes, the metadata I have does not cover all the spots in the CellScopes object, leading to mismatches.

I also attempted to convert Seurat's visium object to a CellScopes object using cs.from_seurat. However, this approach does not allow me to use cs.add_visium_img to add the original Tiff file. The error I received is:

MethodError: no method matching add_visium_img(::CellScopes.VisiumObject, ::String) Closest candidates are: add_visium_img(::CellScopes.VisiumObject; img_path) at ~/.julia/packages/CellScopes/mRlqf/src/spatial/sp_processing.jl:251

Stacktrace: [1] top-level scope @ In[5]:1

Therefore, I would appreciate any guidance on how to subset CellScopes objects for various spatial transcriptomics and single-cell data.

Thank you for your assistance!

Best regards

HaojiaWu commented 2 months ago

Hi, "I often use metadata from objects processed with Seurat or stLearn and integrate this metadata into a processed CellScopes object for visualization. Sometimes, the metadata I have does not cover all the spots in the CellScopes object, leading to mismatches." You can try this:

  1. create a complete CellScopes object.
  2. subset the CellScopes object using the same cell ids that are used in your Seurat object. Here we provide a function for subseting cells.
    subset_obj = cs.subset_objec(cs_obj;  cells = a_vector_of_cell_ids)
  3. Input the metadata from seurat or stlearn into the CellScopes metadata. Make sure the cell order is the same between the CellScope object and your seurat/stlearn object.

"I also attempted to convert Seurat's visium object to a CellScopes object using cs.from_seurat. However, this approach does not allow me to use cs.add_visium_img to add the original Tiff file. The error I received is:" Can you use this line below and see if it works for you? I have updated the tutorial for this part.

visium = cs.add_visium_img(visium; img_path ="/mnt/sdb/breast_cancer_visium/CytAssist_FFPE_Human_Breast_Cancer_tissue_image_8bit.tif")