-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDEG.r
47 lines (35 loc) · 1.38 KB
/
DEG.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
library(Seurat)
library(dplyr)
library(ggplot2)
library(ggrepel)
# Set working directory
setwd(file.path("/path/experiment/scRNA-seq/summary/QCsample"))
# Load pre-processed objects
data1 <- readRDS("CTRL.rds")
data2 <- readRDS("WGDp12.rds")
# Extract specific layer data
counts_CTRL <- data1[["RNA"]]$`counts.Gene Expression.CTRL`
counts_WGDp12 <- data2[["RNA"]]$`counts.Gene Expression.WGDp12`
# Create Seurat objects
seurat_obj1 <- CreateSeuratObject(counts = counts_CTRL)
seurat_obj1$group <- "CTRL" # Add group column labeled as CTRL
seurat_obj2 <- CreateSeuratObject(counts = counts_WGDp12)
seurat_obj2$group <- "WGDp12" # Add group column labeled as WGDp12
# Merge and normalize data
seurat_obj <- merge(seurat_obj1, y = seurat_obj2)
seurat_obj <- NormalizeData(seurat_obj)
# Select variable features
seurat_obj <- FindVariableFeatures(seurat_obj)
# Scale data and run PCA analysis
seurat_obj <- ScaleData(seurat_obj)
seurat_obj <- RunPCA(seurat_obj)
# Join data layers
seurat_obj <- JoinLayers(seurat_obj)
# Confirm cluster assignment
table(Idents(seurat_obj))
# Perform differential gene expression analysis
Idents(seurat_obj) <- seurat_obj$group
group_markers <- FindMarkers(seurat_obj, ident.1 = "WGDp12", ident.2 = "CTRL", logfc.threshold = 0)
head(group_markers)
# Save differential expression results
write.table(group_markers, quote = FALSE, paste0("DEGs_WGDp12_vs_CTRL.txt"), sep = "\t")