-
Notifications
You must be signed in to change notification settings - Fork 0
/
DEGs_plot.R
146 lines (75 loc) · 3.6 KB
/
DEGs_plot.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
setwd("C:/Users/Jacky/Desktop/DEGs")
seu_obj <- readRDS("./RDS/annotation.rds")
#在Seurat对象的metadata中删除指定的列
[email protected] <- select([email protected], -cell_id)
[email protected] <- select([email protected], -HPV_Specific)
[email protected] <- select([email protected], -sample_id)
metatable <- read_excel("./metadata/Neo_metadata.xlsx")
metadata <- FetchData(seu_obj, "cell.name")
metadata$cell_id <- rownames(metadata)
metadata <- left_join(x = metadata, y = metatable, by = "cell.name")
rownames(metadata) <- metadata$cell_id
seu_obj <- AddMetaData(seu_obj, metadata = metadata)
View([email protected])
CellDimPlot(
srt = seu_obj, group.by = c("Phase"), reduction = "SeuratUMAP2D",
title = "Seurat", theme_use = "theme_blank",label = TRUE
)
CellDimPlot(
srt = seu_obj, group.by = c("T_cell_label"), reduction = "SeuratUMAP2D",
title = "Seurat", theme_use = "theme_blank"
)
metatable <- read_excel("./metadata/patients_metadata.xlsx")
metadata <- FetchData(seu_obj, "orig.ident")
metadata$cell_id <- rownames(metadata)
metadata$sample_id <- metadata$orig.ident
metadata <- left_join(x = metadata, y = metatable, by = "sample_id")
rownames(metadata) <- metadata$cell_id
seu_obj <- AddMetaData(seu_obj, metadata = metadata)
View([email protected])
meatadata <- [email protected]
write.table(data.frame(ID=rownames(meatadata),meatadata), file = "metadata.txt", sep = "\t", col.names = T, row.names = F, quote = F)
saveRDS(seu_obj,"annotation.rds")
setwd("C:/Users/Jacky/Desktop/HPV_scRNA")
library(scRNAtoolVis)
library(ggplot2)
library(tidyverse)
library(ggrepel)
setwd("C:/Users/Jacky/Desktop/PDAC/scRNA/DEGs")
cell_types <- unique([email protected]$celltype)
for (cell_type in cell_types) {
# 根据celltype标识细胞
Idents(seu_obj) <- [email protected]$celltype
# 提取特定细胞类型的子集
cell_subset <- subset(seu_obj, idents = cell_type)
# 根据T_cell_label重新标识细胞子集
Idents(cell_subset) <- [email protected]$Label
# 查找差异表达基因
DEGs <- FindMarkers(cell_subset, ident.1 = "1", ident.2 = "0", min.pct = 0.25)
# 将差异表达基因保存到文件
output_file <- paste0(cell_type, "_DEGs.txt")
write.table(data.frame(ID = rownames(DEGs), DEGs), file = output_file, sep = "\t", col.names = TRUE, row.names = FALSE, quote = FALSE)
}
file_list <- list.files(pattern = "\\.txt$")
# 读取所有文件并合并
combined_data <- lapply(file_list, function(file) {
# 读取文件
data <- read.table(file, header = TRUE, sep = "\t") # 假设文件是用制表符分隔的
# 添加文件名作为新列
data$cluster <- file
# 返回修改后的数据框
return(data)
}) %>% bind_rows()
names(combined_data)[names(combined_data) == "ID"] <- "gene" #修改ID名称为gene
write.table(combined_data, file = "combined_data.txt", row.names = FALSE, col.names = TRUE, quote = FALSE, sep = "\t")
df1 <- read.csv("combined_data.csv", header = TRUE, encoding = 'UTF-8')
mycol <- c( "steelblue","#E64B357F","#4DBBD57F","#F98400","#DF6FA0","#00A0877F","#3C54887F","#F39B7F7F","#8491B47F","#E2D200", 'pink')
#添加其它参数修改标签,这里调整一下字体和文字大小:
jjVolcano(diffData = df1,
tile.col = corrplot::COL2('RdBu', 15)[2:12],
size = 3.5,
fontface = 'italic')
#修改点颜色:
jjVolcano(diffData = df1) +
scale_color_manual(values = mycol) +
scale_fill_manual(values = mycol)