markers_mouse.R 4.8 KB
Newer Older
Ivan Merelli's avatar
Ivan Merelli committed
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
library(Seurat)
library(dplyr)

Full_final <- readRDS("/DATA/31/molteni/vexas_mouse_3/results/Full/01-seurat/Full_final.rds")

# computation on cluster numbers
setwd("/DATA/31/molteni/vexas_mouse_3/results/DE_markers/")
Idents(Full_final)<-"RNA_snn_h.orig.ident_res.0.6"

clusters <- levels(Full_final@meta.data$RNA_snn_h.orig.ident_res.0.6)


for(i in 0:length(clusters)) {
  markers <- FindMarkers(Full_final, ident.1 = "A", group.by = "orig.ident", subset.ident = i)
  markers['cluster'] <- i
  filename=paste("markers_cluster_",i,".csv", sep="")
  write.csv(markers, file=filename)
}

df <- list.files(path='/DATA/31/molteni/vexas_mouse_3/results/DE_markers/') %>% 
  lapply(read.csv) %>% 
  bind_rows

df <- df[df$p_val_adj<0.05,]

write.csv(df, file="AvsC_sigMarkers.csv")
cells_by_sample <- table(Full_final@meta.data$RNA_snn_h.orig.ident_res.0.6, Full_final@meta.data$orig.ident)
write.csv(cells_by_sample, file="cells_bysample.csv")


# computation on custom annotation

Full_final <- readRDS("/DATA/31/molteni/vexas_mouse_3/results/Full/01-seurat/Full_final_annot.rds")

setwd("/DATA/31/molteni/vexas_mouse_3/results/DE_markers2/new/")

clusters <- unique (Full_final$celltypes_annot)

for(i in clusters) {
  markers <- FindMarkers(Full_final, ident.1 = "A", group.by = "orig.ident", subset.ident = i)
  markers['cluster'] <- i
  filename=paste("markers_cluster_",i,".csv", sep="")
  write.csv(markers, file=filename)
}


df <- list.files(path='/DATA/31/molteni/vexas_mouse_3/results/DE_markers2/new/') %>% 
  lapply(read.csv) %>% 
  bind_rows

df <- df[df$p_val_adj<0.05,]
setwd("/DATA/31/molteni/vexas_mouse_3/results/summary")
write.csv(df, file="AvsC_sigMarkers_custom.csv")

cc_distribution <-as.data.frame (table(Full_final$Phase, Full_final$orig.ident, Full_final$celltypes_annot))
colnames(cc_distribution) <- c("Phase","orig.ident","cluster","CellNumb")
write.csv(cc_distribution, file="cell_cycle.csv")


 
# computation on custom annotation after filtering cluster 19, res 1.2

Full_final <- readRDS("/DATA/31/molteni/vexas_mouse_3/results/Full/01-seurat/Full_final_annot_filt.rds")

setwd("/DATA/31/molteni/vexas_mouse_3/results/DE_markers/AvsC/")

clusters <- unique (Full_final$celltypes_annot)

for(i in clusters) {
  markers <- FindMarkers(Full_final, ident.1 = "A", group.by = "orig.ident", subset.ident = i)
  markers['cluster'] <- i
  filename=paste("markers_cluster_",i,".csv", sep="")
  write.csv(markers, file=filename)
}


df <- list.files(path='/DATA/31/molteni/vexas_mouse_3/results/DE_markers/AvsC/') %>% 
  lapply(read.csv) %>% 
  bind_rows

df <- df[df$p_val_adj<0.05,]
setwd("/DATA/31/molteni/vexas_mouse_3/results/summary")
write.csv(df, file="AvsC_sigMarkers_custom.csv")

cells_by_sample <- table(Full_final@meta.data$celltypes_annot, Full_final@meta.data$orig.ident)
write.csv(cells_by_sample, file="cells_bysample.csv")

cc_distribution <-as.data.frame (table(Full_final$Phase, Full_final$orig.ident, Full_final$celltypes_annot))
colnames(cc_distribution) <- c("Phase","orig.ident","cluster","CellNumb")
write.csv(cc_distribution, file="cell_cycle.csv")


#markers tra cluster specifici
## GMP2 VS GMP2
setwd("/DATA/31/molteni/vexas_mouse_3/results/DE_GMP2_GMP1")
Idents(Full_final) <- "celltypes_annot"
markers <- FindMarkers(Full_final, ident.1 = "GMP_2", ident.2 = "GMP_1")
write.csv(markers, file="GMP2vsGMP1_Full.csv")

Idents(Full_final) <- "orig.ident"
Full_final_A <- subset(Full_final, idents = "A")
Idents(Full_final_A) <- "celltypes_annot"
markers <- FindMarkers(Full_final_A, ident.1 = "GMP_2", ident.2 = "GMP_1")
write.csv(markers, file="GMP2vsGMP1_A.csv")

Idents(Full_final) <- "orig.ident"
Full_final_C <- subset(Full_final, idents ="C")
Idents(Full_final_C) <- "celltypes_annot"
markers <- FindMarkers(Full_final_C, ident.1 = "GMP_2", ident.2 = "GMP_1")
write.csv(markers, file="GMP2vsGMP1_C.csv")


## B Cell Prog 1 vs B Cell Prog 2
setwd("/DATA/31/molteni/vexas_mouse_3/results/DE_BP1_BP2")
Idents(Full_final) <- "celltypes_annot"
markers <- FindMarkers(Full_final, ident.1 = "B_cell_progenitors_1", ident.2 = "B_cell_progenitors_2")
write.csv(markers, file="BP1vsBP2_Full.csv")

Idents(Full_final_A) <- "celltypes_annot"
markers <- FindMarkers(Full_final_A, ident.1 = "B_cell_progenitors_1", ident.2 = "B_cell_progenitors_2")
write.csv(markers, file="BP1vsBP2_A.csv")

Idents(Full_final_C) <- "celltypes_annot"
markers <- FindMarkers(Full_final_C, ident.1 = "B_cell_progenitors_1", ident.2 = "B_cell_progenitors_2")
write.csv(markers, file="BP1vsBP2_C.csv")


setwd("/DATA/31/molteni/vexas_mouse_3/results/DE_markers/AvsC/")
df <- list.files(path='/DATA/31/molteni/vexas_mouse_3/results/DE_markers/AvsC/') %>% 
  lapply(read.csv) %>% 
  bind_rows

#df <- df[df$p_val_adj<0.05,]

top50 <- df %>%
  group_by(cluster) %>%
  dplyr::filter(avg_log2FC > 0) %>%
  slice_head(n = 50) %>%
  ungroup() -> top50

write.csv(top50, file="top50_by_cluster.csv")