pwwang / scplotter

scplotter is an R package that is built upon plotthis. It provides a set of functions to visualize single-cell sequencing data in an easy and efficient way.
https://pwwang.github.io/scplotter/
GNU General Public License v3.0
97 stars 12 forks source link

How to properly prepare the data for CellDimPlot visualization #8

Open wenyunvip opened 2 days ago

wenyunvip commented 2 days ago

[Help Needed] How to prepare Seurat object for CellDimPlot visualization after 10X data processing

Current Code

I'm processing 10X single-cell data using Seurat and trying to visualize it with CellDimPlot. Here's my current workflow:

# Loading libraries
library(Seurat)
library(dplyr)

# Reading all h5 files from Newdata folder
ids <- list.files(path = "Newdata", full.names = TRUE, pattern = "\\.h5$")

# Function to create and process Seurat object
create_and_process_seurat <- function(file_path) {
  data1 <- Read10X_h5(file_path, use.names = TRUE)
  biofscicol <- gsub("\\.h5$", "", basename(file_path))

  biofsci <- CreateSeuratObject(counts = data1, 
                           project = biofscicol, 
                           min.cells = 3,
                           min.features = 200)
  biofsci$Type <- Idents(biofsci)
  biofsci[["percent.mt"]] <- PercentageFeatureSet(biofsci, pattern = "^MT-")
  biofsci[["percent.rb"]] <- PercentageFeatureSet(biofsci, pattern = "^RP")

  # Filtering cells
  biofsci <- biofsci %>%
    subset(nCount_RNA >= 1000 &
             nFeature_RNA >= 200 & nFeature_RNA <= 10000 &
             percent.mt <= 20 &
             percent.rb <= 20)
  return(biofsci)
}

# Processing first file
biofsci <- create_and_process_seurat(ids[1])

# Processing and merging remaining files
if (length(ids) > 1) {
  for (file in ids[-1]) {
    biofscin <- create_and_process_seurat(file)
    biofsci <- merge(biofsci, biofscin)
  }
}

# Saving results
saveRDS(biofsci, "biofsci04.rds")

Issue

When trying to use CellDimPlot on the processed data, I encounter issues. I need guidance on:

  1. How to properly prepare the data for CellDimPlot visualization
  2. Understanding the required data structure for CellDimPlot
  3. The correct workflow to transition from Seurat processing to CellDimPlot

Questions

  1. What additional preprocessing steps are needed for CellDimPlot compatibility?
  2. Does the Seurat object need specific modifications before using CellDimPlot?
  3. Is there a specific format or structure required for CellDimPlot input?
  4. Are there example workflows showing how to prepare pancreas_sub data for CellDimPlot?

Technical Details

Expected Outcome

Tags

single-cell seurat visualization celldimplot r-programming 10x-genomics

pwwang commented 2 days ago

Simply, if a Seurat object can be visualized by Seurat::DimPlot, it can be visualized by CellDimPlot. If you are looking for tutorials to prepare a Seurat object, please refer to: