Single cell analysis #8 데이터 시각화 (GSEA-2)

 # 메타데이터에서 클러스터 정보 할당

seurat_combined <- SetIdent(seurat_combined, value = seurat_combined$seurat_clusters)


# 클러스터 ID 확인

unique(Idents(seurat_combined))  # 이제 클러스터 ID를 확인



target_cluster <- "7"  # 예: 클러스터 ID가 문자열인 경우

seurat_clustered <- subset(seurat_combined, idents = target_cluster)


# 해당 클러스터의 마커 찾기

# 현재 클러스터 ID 확인

all_clusters <- unique(Idents(seurat_combined))

# "12"를 제외한 나머지 클러스터 ID 수집

other_clusters <- all_clusters[all_clusters != "7"]


# FindMarkers 실행

markers_target <- FindMarkers(seurat_combined, ident.1 = "7", ident.2 = other_clusters)


# 유전자 랭킹 생성

ranks_target <- markers_target$avg_log2FC

names(ranks_target) <- rownames(markers_target)


# HALLMARK 경로 가져오기

gene_sets_hallmark <- msigdbr(species = "Homo sapiens", category = "H")

hallmark_pathways <- split(x = gene_sets_hallmark$gene_symbol, f = gene_sets_hallmark$gs_name)


# FGSEA 실행

fgsea_results_target <- fgsea(pathways = hallmark_pathways, stats = ranks_target, nperm = 1000)


# 상위 결과 보기

head(fgsea_results_target[order(fgsea_results_target$pval), ])


# 상위 경로 선택 (예: p-value 기준 상위 3개 경로 선택)

top_pathways <- fgsea_results_target [order(fgsea_results_target $pval), ]$pathway[1:6]


# 여러 경로에 대한 plotEnrichment 결과 생성

p1 <- plotEnrichment(hallmark_pathways[[top_pathways[1]]], ranks_ht04) +

  labs(title = top_pathways[1]) +

  theme_minimal() + 

  theme(plot.title = element_text(size = 14, face = "bold")) +  # 제목 스타일 조정

  scale_color_manual(values = c("blue")) +  # 선 색상 변경

  theme(legend.position = "none")  # 범례 제거


p2 <- plotEnrichment(hallmark_pathways[[top_pathways[2]]], ranks_ht04) +

  labs(title = top_pathways[2]) +

  theme_minimal() + 

  theme(plot.title = element_text(size = 14, face = "bold")) +

  scale_color_manual(values = c("blue")) +

  theme(legend.position = "none")


p3 <- plotEnrichment(hallmark_pathways[[top_pathways[3]]], ranks_ht04) +

  labs(title = top_pathways[3]) +

  theme_minimal() + 

  theme(plot.title = element_text(size = 14, face = "bold")) +

  scale_color_manual(values = c("blue")) +

  theme(legend.position = "none")


p4 <- plotEnrichment(hallmark_pathways[[top_pathways[4]]], ranks_ht04) +

  labs(title = top_pathways[4]) +

  theme_minimal() + 

  theme(plot.title = element_text(size = 14, face = "bold")) +

  scale_color_manual(values = c("blue")) +

  theme(legend.position = "none")


p5 <- plotEnrichment(hallmark_pathways[[top_pathways[5]]], ranks_ht04) +

  labs(title = top_pathways[5]) +

  theme_minimal() + 

  theme(plot.title = element_text(size = 14, face = "bold")) +

  scale_color_manual(values = c("blue")) +

  theme(legend.position = "none")


p6 <- plotEnrichment(hallmark_pathways[[top_pathways[6]]], ranks_ht04) +

  labs(title = top_pathways[6]) +

  theme_minimal() + 

  theme(plot.title = element_text(size = 14, face = "bold")) +

  scale_color_manual(values = c("blue")) +

  theme(legend.position = "none")


# 여러 plot을 patchwork로 결합

(p1 / p2 | p3 / p4 | p5 / p6)  # 가로로 배치


댓글

이 블로그의 인기 게시물

#single cell sequencing 기초 분석 - #1 R 설치 및 package 설치

리눅스 기초 #10 GATK calling을 사용하기 위하여, reference file indexing하는 방법

Single cell 분석을 위한 package 소개