-
Notifications
You must be signed in to change notification settings - Fork 2
/
intestline_ms_figures.Rmd
209 lines (155 loc) · 6.03 KB
/
intestline_ms_figures.Rmd
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
---
title: "Generating figures for intestline manuscript"
author: "Jiangyan Yu ([email protected])"
date: "`r Sys.Date()`"
output:
html_document:
code_folding: hide
number_sections: yes
theme: united
toc: yes
toc_float: yes
pdf_document:
toc: yes
---
# library and directory
```{r}
rm(list=ls())
library(dplyr)
library(magrittr)
library(ggplot2)
## set working directory
working_dir = "/home/yu.j/sciebo/Projects/CODEX_ownerJY//"
figure_dir = paste0(working_dir,"/ms_figures")
##
intestline = read.csv(file = paste0(working_dir,"/CODEX_data/IntestLine-linear_structure_15-Sep-2022_09h27min.csv"))
base_layer = read.csv(file = paste0(working_dir,"/CODEX_data/better_backbone.csv"))
```
# fig2
## fig2b_selected_base_layer
```{r}
pdf(file = paste0(figure_dir,"/V2fig2b_selected_base_layer.pdf"),width = 8,height = 8)
plot(intestline$x,intestline$y,pch=16,cex=0.2,col="black")
points(base_layer$x,base_layer$y,pch=16,cex=0.5,col="red")
dev.off()
```
## fig2c_connect_spot_n_baselayer_after_filtering
```{r}
pdf(file = paste0(figure_dir,"/V2fig2c_connect_spot_n_baselayer_before_filtering.pdf"),width = 8,height = 8)
## select successfully projected spots
plot_data = subset(intestline,note == "Successfully projected")
plot(plot_data$x,plot_data$y,pch=16,cex=0)
segments(x0=plot_data$x,y0=plot_data$y,x1 = plot_data$nearest_Row, y1=plot_data$nearest_Column,pch=16,cex=0.1,lwd=0.1,col = "grey")
points(x=plot_data$nearest_Row,y=plot_data$nearest_Column,pch=16,cex=0.3,col="red")
dev.off()
```
## fig2d_filtering_distance
```{r}
pdf(file = paste0(figure_dir,"/V2fig2d_filtering_distance.pdf"),width = 4,height = 3)
plot.ecdf(x=intestline$Thickness,ylab = "Cumulative frequency",xlab="Distance to base layer",main = "")
abline(v = 1000, lty= 2, col = "red")
# title(main = "", xlab = "Distance to base layer")
dev.off()
```
## fig2e_filtering__zscore
```{r}
pdf(file = paste0(figure_dir,"/V2fig2e_filtering_zscore.pdf"),width = 4,height = 3)
## select successfully projected spots
plot_data = subset(intestline,note == "Successfully projected")
plot.ecdf(x=as.numeric(plot_data$zscore),ylab = "Cumulative frequency",xlab="Z-score of distances to the same base layer point",main = "")
abline(v = 2, lty= 2, col = "red")
# title(main = "", xlab = "Distance to base layer")
dev.off()
```
## fig2f_connect_spot_n_baselayer_after_filtering
```{r}
pdf(file = paste0(figure_dir,"/V2fig2f_connect_spot_n_baselayer_after_filtering.pdf"),width = 8,height = 8)
## select successfully projected spots
plot_data = subset(intestline,note == "Successfully projected")
## remove low noisy
plot_data = subset(plot_data, as.numeric(Thickness) < 1000 & as.numeric(zscore) <2)
plot(plot_data$x,plot_data$y,pch=16,cex=0)
segments(x0=plot_data$x,y0=plot_data$y,x1 = plot_data$nearest_Row, y1=plot_data$nearest_Column,pch=16,cex=0.1,lwd=0.1,col = "#457b9d")
points(x=plot_data$nearest_Row,y=plot_data$nearest_Column,pch=16,cex=0.3,col="red")
dev.off()
```
## fig2g_linear_structure
```{r}
pdf(file = paste0(figure_dir,"/V2fig2g_linear_structure.pdf"),width = 30,height = 4)
## select successfully projected spots
plot_data = subset(intestline,note == "Successfully projected")
## remove low noisy
plot_data = subset(plot_data, as.numeric(Thickness) < 1000 & as.numeric(zscore) <2)
plot(plot_data$Length,plot_data$Thickness,pch=16,cex=0.3,col = "#457b9d")
dev.off()
```
# fig3
## fig3a_rolled_image
```{r}
# markers = colnames(intestline)[18:34]
markers = c("Villin","Olfm4","Ki67","SMA","Lysozyme")
scale_marker = function(x){(x-min(x))/(max(x)-min(x))}
for(i in markers){
pdf(file = paste0(figure_dir,"/V2fig3a_rolled_",i,".pdf"),width = 8,height = 8)
# i = "Ki67"
tmp_data = intestline[,c("x","y",i)]
tmp_data$scaled = scale_marker(intestline[,i])
tmp_data = tmp_data[order(tmp_data[, "scaled"],decreasing = FALSE),]
p = ggplot(tmp_data,aes(x,y,color=scaled))+
geom_point(size=0.01)+
scale_colour_gradientn(colors = c("#e6e6e6",
"#e60000",
"#e60000",
"#e60000",
"#e60000"),
breaks = c(0,
0.5,
1))+
labs(title = i)+
theme(plot.title = element_text(hjust = 0.5)) +
theme(
axis.line = element_line(color = 'black'),
panel.background = element_rect(fill = 'white', color = 'black'),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank()
)
plot(p)
dev.off()
}
```
## fig3b_linear
```{r}
markers = colnames(intestline)[18:34]
scale_marker = function(x){(x-min(x))/(max(x)-min(x))}
markers = c("Villin","Olfm4","Ki67","SMA","Lysozyme")
for(i in markers){
pdf(file = paste0(figure_dir,"/V2fig3b_linear_",i,".pdf"),width = 30,height = 4)
# i = "Lysozyme"
tmp_data = plot_data[,c("Length","Thickness",i)]
tmp_data$scaled = scale_marker(tmp_data[,i])
## overlay large values on top
tmp_data = tmp_data[order(tmp_data[, "scaled"],decreasing = FALSE),]
p = ggplot(tmp_data,aes(Length,Thickness,color=scaled))+
geom_point(size=0.01)+
scale_colour_gradientn(colors = c("#e6e6e6",
"#e60000",
"#e60000",
"#e60000",
"#e60000"),
breaks = c(0,
0.5,
1))+
labs(title = i)+
theme(plot.title = element_text(hjust = 0.5)) +
theme(
axis.line = element_line(color = 'black'),
panel.background = element_rect(fill = 'white', color = 'black'),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank()
)
plot(p)
dev.off()
}
```