LAB

Classifying Cell Types Using scRNA-seq Data 🧬 (Seurat & Scanpy Hands-on Tutorial). scRNA-seq 데이터로 세포 유형을 분류하는 방법 🧬 (Seurat, Scanpy 실습)

Kevin Baek 2025. 3. 12. 03:38
반응형

1️⃣ scRNA-seq란 무엇인가?

**Single-cell RNA sequencing (scRNA-seq)**는 개별 세포 단위에서 전사체를 분석하는 기법으로, 세포 유형을 분류하고 세포 간 유전자 발현 차이를 이해하는 데 필수적인 기술임.
✅ 조직 내 이질적인 세포 집단을 식별하는 데 유용
신경과학, 면역학, 암 연구 등에서 세포 유형별 유전자 발현 패턴 분석 가능
✅ 특정 세포 유형의 기능 및 분화 과정 연구에 활용됨


2️⃣ scRNA-seq 데이터 분석을 위한 필수 도구

🔹 Seurat (R-based) – 가장 널리 사용되는 scRNA-seq 분석 패키지
🔹 Scanpy (Python-based) – 빠른 데이터 처리 및 대규모 데이터셋 분석에 강점
🔹 CellRanger (10X Genomics) – scRNA-seq 원시 데이터 처리 (FASTQ → Count Matrix 변환)
🔹 Monocle (R-based) – 의사시간(Pseudotime) 분석 및 세포 분화 경로 추적


3️⃣ Seurat을 이용한 scRNA-seq 데이터 분석 (R)

📌 Step 1: Seurat 패키지 설치 및 데이터 불러오기 

# Seurat 설치 및 로드
install.packages("Seurat")
library(Seurat)

# scRNA-seq 데이터 불러오기 (10X Genomics 데이터)
data <- Read10X(data.dir = "filtered_feature_bc_matrix/")
seurat_obj <- CreateSeuratObject(counts = data, project = "scRNA-seq", min.cells = 3, min.features = 200)

 

📌 Step 2: 데이터 정규화 및 필터링 

# 세포 품질 필터링 (미토콘드리아 유전자 비율 확인)
seurat_obj[["percent.mt"]] <- PercentageFeatureSet(seurat_obj, pattern = "^MT-")

# 품질 기준 적용 (세포 당 유전자 수, 미토콘드리아 비율 기준)
seurat_obj <- subset(seurat_obj, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5)

# Log Normalization 수행
seurat_obj <- NormalizeData(seurat_obj, normalization.method = "LogNormalize", scale.factor = 10000)

 

📌 Step 3: PCA 및 UMAP을 이용한 차원 축소

# 고변이 유전자 식별
seurat_obj <- FindVariableFeatures(seurat_obj, selection.method = "vst", nfeatures = 2000)

# 데이터 스케일링
seurat_obj <- ScaleData(seurat_obj, features = rownames(seurat_obj))

# PCA 수행
seurat_obj <- RunPCA(seurat_obj, features = VariableFeatures(object = seurat_obj))

# UMAP 시각화
seurat_obj <- RunUMAP(seurat_obj, dims = 1:10)
DimPlot(seurat_obj, reduction = "umap", label = TRUE, pt.size = 1)

 

📌 Step 4: 세포 유형 클러스터링 

# 최근접 이웃(Nearest Neighbors) 찾기
seurat_obj <- FindNeighbors(seurat_obj, dims = 1:10)

# 클러스터 할당
seurat_obj <- FindClusters(seurat_obj, resolution = 0.5)

# 클러스터 시각화
DimPlot(seurat_obj, reduction = "umap", group.by = "seurat_clusters")

 

📌 Step 5: 세포 유형 결정 및 마커 유전자 분석

# 클러스터별 마커 유전자 찾기
markers <- FindAllMarkers(seurat_obj, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)

# 특정 클러스터의 마커 유전자 확인 (예: 0번 클러스터)
markers_cluster0 <- FindMarkers(seurat_obj, ident.1 = 0, min.pct = 0.25)

# Heatmap으로 마커 유전자 시각화
DoHeatmap(seurat_obj, features = top10$gene) + NoLegend().

 

4️⃣ Scanpy를 이용한 scRNA-seq 데이터 분석 (Python)

Seurat과 달리 Scanpy는 Python 기반으로 대규모 데이터셋을 빠르게 분석할 수 있음.

📌 Step 1: Scanpy 패키지 설치 및 데이터 불러오기 

import scanpy as sc

# 데이터 불러오기 (10X Genomics 데이터)
adata = sc.read_10x_mtx("filtered_feature_bc_matrix/", var_names="gene_symbols", cache=True)

 

📌 Step 2: 데이터 필터링 및 정규화  

# 미토콘드리아 유전자 비율 계산
adata.var["mt"] = adata.var_names.str.startswith("MT-")
sc.pp.calculate_qc_metrics(adata, qc_vars=["mt"], percent_top=None, log1p=False, inplace=True)

# 품질 기준 적용
adata = adata[adata.obs.n_genes_by_counts > 200, :]
adata = adata[adata.obs.pct_counts_mt < 5, :]

# Log Normalization
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)

 

📌 Step 3: 차원 축소 (PCA & UMAP)

# 고변이 유전자 선택
sc.pp.highly_variable_genes(adata, min_mean=0.0125, max_mean=3, min_disp=0.5)

# 데이터 스케일링
sc.pp.scale(adata, max_value=10)

# PCA 수행
sc.tl.pca(adata, svd_solver="arpack")

# UMAP 실행 및 시각화
sc.pp.neighbors(adata, n_neighbors=10, n_pcs=40)
sc.tl.umap(adata)
sc.pl.umap(adata, color=["n_genes_by_counts"])

📌 Step 4: 세포 클러스터링 

# 클러스터링 수행
sc.tl.leiden(adata, resolution=0.5)

# 클러스터링 결과 시각화
sc.pl.umap(adata, color=["leiden"])

 

📌 Step 5: 마커 유전자 분석

# 클러스터별 마커 유전자 찾기
sc.tl.rank_genes_groups(adata, "leiden", method="wilcoxon")

# 특정 클러스터의 마커 유전자 확인
sc.pl.rank_genes_groups(adata, n_genes=20, sharey=False)

 

5️⃣ Seurat vs Scanpy 비교

Feature                                        Seurat (R)                                                     Scanpy (Python)

속도 느림 빠름
대용량 데이터 처리 제한적 우수함
시각화 옵션 다양함 기본적인 기능 제공
유연성 Bioconductor 패키지와 호환 Pandas, NumPy와 연계 가능

6️⃣ 결론: scRNA-seq 데이터 분석을 위한 최적의 도구는?

Seurat은 생명과학 연구자들이 가장 많이 사용하는 R 기반 툴로, 깊이 있는 분석과 다양한 시각화 옵션이 강점
Scanpy는 Python 기반으로 대규모 scRNA-seq 데이터 분석에 강력하며 속도가 빠름

💡 연구 환경에 따라 Seurat과 Scanpy를 함께 활용하는 것도 좋은 전략!
🔥 추가적인 궁금한 점 있으면 언제든 질문 환영! 🧬🔬

 

 

Reference

🔬 Seurat-Based Tutorials (R)

  1. Seurat - Guided Clustering Tutorial
    • A step-by-step tutorial on scRNA-seq analysis using Seurat, covering normalization, clustering, and cell type identification.
  2. Single Cell RNA-seq Analysis Using Seurat
    • Bioconductor's vignette for Seurat, demonstrating quality control, data transformation, and differential gene expression analysis.
  3. Introduction to scRNA-Seq with R (Seurat)
    • A beginner-friendly tutorial covering scRNA-seq processing, filtering, and clustering in R with Seurat.

🐍 Scanpy-Based Tutorials (Python)

  1. Scanpy Documentation & Tutorials
    • Official documentation with multiple tutorials on preprocessing, clustering, and visualization of single-cell datasets.
  2. Filtering, Clustering, and Exploring Single-Cell RNA-seq Data with Scanpy
    • A hands-on guide for scRNA-seq analysis using Scanpy, focusing on quality control, normalization, and UMAP visualization.
  3. scRNA-seq Analysis in Python with Scanpy
    • A practical guide explaining key functions in Scanpy for clustering, dimensionality reduction, and gene expression analysis.

--------------------------------------------------------------

 

1️⃣ What is scRNA-seq?

Single-cell RNA sequencing (scRNA-seq) is a powerful technology that allows researchers to analyze gene expression at the individual cell level.
✅ It enables the identification of heterogeneous cell populations
✅ Useful for studying neuroscience, immunology, cancer biology, and more
✅ Helps in understanding cellular functions and differentiation processes


2️⃣ Essential Tools for scRNA-seq Analysis

🔹 Seurat (R-based) – A widely used toolkit for scRNA-seq data processing and visualization
🔹 Scanpy (Python-based) – Efficient for large-scale datasets and computational analysis
🔹 CellRanger (10X Genomics) – Prepares raw scRNA-seq data (FASTQ → Count Matrix)
🔹 Monocle (R-based) – Used for trajectory analysis and cell lineage inference


3️⃣ Analyzing scRNA-seq Data Using Seurat (R)

📌 Step 1: Install Seurat and Load Data

r
 
# Install and load Seurat
install.packages("Seurat")
library(Seurat)

# Load scRNA-seq dataset (10X Genomics data)
data <- Read10X(data.dir = "filtered_feature_bc_matrix/")
seurat_obj <- CreateSeuratObject(counts = data, project = "scRNA-seq", min.cells = 3, min.features = 200)

📌 Step 2: Data Normalization & Filtering

r
 
# Compute mitochondrial gene percentage
seurat_obj[["percent.mt"]] <- PercentageFeatureSet(seurat_obj, pattern = "^MT-")

# Filter cells based on QC metrics
seurat_obj <- subset(seurat_obj, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5)

# Log normalization
seurat_obj <- NormalizeData(seurat_obj, normalization.method = "LogNormalize", scale.factor = 10000)

📌 Step 3: PCA and UMAP for Dimensionality Reduction

r
 
# Identify highly variable genes
seurat_obj <- FindVariableFeatures(seurat_obj, selection.method = "vst", nfeatures = 2000)

# Scale the data
seurat_obj <- ScaleData(seurat_obj, features = rownames(seurat_obj))

# Perform PCA
seurat_obj <- RunPCA(seurat_obj, features = VariableFeatures(object = seurat_obj))

# Run UMAP for visualization
seurat_obj <- RunUMAP(seurat_obj, dims = 1:10)
DimPlot(seurat_obj, reduction = "umap", label = TRUE, pt.size = 1)

 


📌 Step 4: Clustering Cells

r
 
# Find neighbors
seurat_obj <- FindNeighbors(seurat_obj, dims = 1:10)

# Cluster cells
seurat_obj <- FindClusters(seurat_obj, resolution = 0.5)

# Visualize clusters
DimPlot(seurat_obj, reduction = "umap", group.by = "seurat_clusters")

📌 Step 5: Identifying Cell Types Using Marker Genes

r
 

# Find marker genes for each cluster
markers <- FindAllMarkers(seurat_obj, only.pos = TRUE, min.pct = 0.25, logfc.threshold = 0.25)

# Identify markers for a specific cluster (e.g., cluster 0)
markers_cluster0 <- FindMarkers(seurat_obj, ident.1 = 0, min.pct = 0.25)

# Visualize marker genes using a heatmap
DoHeatmap(seurat_obj, features = top10$gene) + NoLegend()


4️⃣ Analyzing scRNA-seq Data Using Scanpy (Python)

Scanpy is a Python-based toolkit that is efficient for handling large-scale single-cell datasets.

📌 Step 1: Install Scanpy and Load Data

import scanpy as sc

# Load 10X Genomics data
adata = sc.read_10x_mtx("filtered_feature_bc_matrix/", var_names="gene_symbols", cache=True)

 


📌 Step 2: Data Filtering & Normalization

# Compute mitochondrial gene percentage
adata.var["mt"] = adata.var_names.str.startswith("MT-")
sc.pp.calculate_qc_metrics(adata, qc_vars=["mt"], percent_top=None, log1p=False, inplace=True)

# Filter cells based on quality control
adata = adata[adata.obs.n_genes_by_counts > 200, :]
adata = adata[adata.obs.pct_counts_mt < 5, :]

# Normalize data
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)


📌 Step 3: Dimensionality Reduction (PCA & UMAP)

 

# Identify highly variable genes
sc.pp.highly_variable_genes(adata, min_mean=0.0125, max_mean=3, min_disp=0.5)

# Scale data
sc.pp.scale(adata, max_value=10)

# Perform PCA
sc.tl.pca(adata, svd_solver="arpack")

# Run UMAP for visualization
sc.pp.neighbors(adata, n_neighbors=10, n_pcs=40)
sc.tl.umap(adata)
sc.pl.umap(adata, color=["n_genes_by_counts"])




📌 Step 4: Clustering Cells

 

# Cluster cells using Leiden algorithm
sc.tl.leiden(adata, resolution=0.5)

# Visualize clusters
sc.pl.umap(adata, color=["leiden"])


📌 Step 5: Identifying Cell Types Using Marker Genes

# Find marker genes for each cluster
sc.tl.rank_genes_groups(adata, "leiden", method="wilcoxon")

# Visualize marker genes
sc.pl.rank_genes_groups(adata, n_genes=20, sharey=False)

5️⃣ Seurat vs Scanpy Comparison

Feature                                                   Seurat (R)                                       Scanpy (Python)

Speed Slower Faster
Handling Large Datasets Limited Efficient
Visualization Options Extensive Basic
Flexibility Works well with Bioconductor Works well with Pandas, NumPy

6️⃣ Conclusion: Which Tool Should You Use?

Seurat is widely used in biological research and provides rich visualization tools for in-depth single-cell RNA-seq analysis.
Scanpy is faster and better for large-scale datasets, making it ideal for computational biologists and data scientists.

💡 Many researchers combine Seurat and Scanpy to leverage the strengths of both tools!

🔥 If you have any questions or need further clarification, feel free to ask! 🧬📊

 

#scRNAseq #SingleCellRNAseq #Bioinformatics #Transcriptomics #Genomics #NextGenSequencing #NGS #GeneExpression #SingleCellAnalysis #SingleCellBiology #Seurat #Scanpy #PythonForBioinformatics #RBioinformatics #SeuratAnalysis #ScanpyAnalysis #UMAP #tSNE #PCA #DimensionalityReduction #CellClustering #CellTypeClassification #MarkerGenes #DifferentialExpression #RNAseqAnalysis #LeidenClustering #SeuratClustering #Heatmap #DataVisualization #GeneMarkerIdentification #NeuroscienceResearch #CancerGenomics #Immunology #StemCellResearch #PersonalizedMedicine #SingleCellTechnology #OrganoidResearch #TumorMicroenvironment #Microglia #Astrocytes

반응형