Skip to content

Commit f6a73bb

Browse files
committed
Supplemental figure updates
1 parent fa41bf6 commit f6a73bb

28 files changed

+594
-140
lines changed

code/revision/plots_PRECAST-k-compare.R

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,23 @@ spe$k18.f = factor(spe$PRECAST_k18, levels=c(10,8,1,
6363

6464

6565

66-
plotGroupedHeatmap(spe, features=genes, group="k16.f", swap_rownames="gene_name",
66+
hm1 = plotGroupedHeatmap(spe, features=genes, group="k16.f", swap_rownames="gene_name",
6767
center=T, scale=T, zlim=c(-2,4),
6868
cluster_rows=F, cluster_cols=F, border_col="white",
6969
color=RColorBrewer::brewer.pal(9,"Greys"),
70-
angle_col="0")
71-
72-
70+
angle_col="0", fontsize=10, fontsize_row=12, silent=T)
71+
hm2 = plotGroupedHeatmap(spe, features=genes, group="k17.f", swap_rownames="gene_name",
72+
center=T, scale=T, zlim=c(-2,4),
73+
cluster_rows=F, cluster_cols=F, border_col="white",
74+
color=RColorBrewer::brewer.pal(9,"Greys"),
75+
angle_col="0", fontsize=10, fontsize_row=12, silent=T)
76+
hm3 = plotGroupedHeatmap(spe, features=genes, group="k18.f", swap_rownames="gene_name",
77+
center=T, scale=T, zlim=c(-2,4),
78+
cluster_rows=F, cluster_cols=F, border_col="white",
79+
color=RColorBrewer::brewer.pal(9,"Greys"),
80+
angle_col="0", fontsize=10, fontsize_row=12, silent=T)
81+
ggsave(file="plots/revision/supp_PRECAST-compare-k_heatmap.pdf", gridExtra::grid.arrange(hm1[[4]], hm2[[4]], hm3[[4]], ncol=3),
82+
height=4, width=12, units="in")
7383

7484
################ make pies
7585
#for pies need manual annotation
@@ -106,32 +116,52 @@ man.pal = c("THAL"="#1e1eff","CTX"="#5ffffb", "SUB"="#add294", "PCL-CA1"="#00dc0
106116
"GCL"="#005000", "SGZ"="#dfa56e", "ML"="#c1c1c1", "SL"="#444444", "SR"="#828E84", "SLM"="tan4",
107117
"SO"="#A698AE", "WM"="#ff3ffc", "CP"="#00006a")
108118

109-
ggplot(as.data.frame(colData(spe.manual)), aes(x="", fill=ManualAnnotation))+
110-
geom_bar(stat="count", position="fill")+
119+
p1 <- ggplot(as.data.frame(colData(spe.manual)), aes(x="", fill=ManualAnnotation))+
120+
geom_bar(stat="count", position="fill", color="white", linewidth=.3)+
121+
scale_fill_manual(values=man.pal)+
122+
facet_wrap(vars(k16.f), ncol=5)+theme_void()+
123+
coord_polar(theta = "y")+labs(title="PRECAST k=16 clusters")+
124+
theme(aspect.ratio=1, legend.position="none", strip.text=element_text(size=12))
125+
p2 <- ggplot(as.data.frame(colData(spe.manual)), aes(x="", fill=ManualAnnotation))+
126+
geom_bar(stat="count", position="fill", color="white", linewidth=.3)+
127+
scale_fill_manual(values=man.pal)+
128+
facet_wrap(vars(k17.f), ncol=5)+theme_void()+
129+
coord_polar(theta = "y")+labs(title="PRECAST k=17 clusters")+
130+
theme(aspect.ratio=1, legend.position="none", strip.text=element_text(size=12))
131+
p3 <- ggplot(as.data.frame(colData(spe.manual)), aes(x="", fill=ManualAnnotation))+
132+
geom_bar(stat="count", position="fill", color="white", linewidth=.3)+
111133
scale_fill_manual(values=man.pal)+
112134
facet_wrap(vars(k18.f), ncol=5)+theme_void()+
113135
coord_polar(theta = "y")+labs(title="PRECAST k=18 cluster")+
114-
theme(aspect.ratio=.8, legend.position="none")
136+
theme(aspect.ratio=1, legend.position="none", strip.text=element_text(size=12))
137+
138+
pdf(file="plots/revision/supp_PRECAST-compare-k_pie.pdf", height=4, width=12)
139+
gridExtra::grid.arrange(p1+theme(panel.spacing = unit(6, "pt"), plot.margin=unit(c(6,12,6,12),"pt")),
140+
p2+theme(panel.spacing = unit(6, "pt"), plot.margin=unit(c(6,12,6,12),"pt")),
141+
p3+theme(panel.spacing = unit(6, "pt"), plot.margin=unit(c(6,12,6,12),"pt")), ncol=3)
142+
dev.off()
115143

116144
#legend for pies
117-
ggplot(cbind.data.frame("y"=c(rep(1,4), rep(2,3), rep(3,6), rep(4,2)),
145+
pl <- ggplot(cbind.data.frame("y"=c(rep(1,4), rep(2,3), rep(3,6), rep(4,2)),
118146
"x"=c(seq(from=1, by=.2, length.out=4),
119-
seq(from=1, by=.2, length.out=3),
120-
seq(from=1, by=.2, length.out=6),
147+
#seq(from=1, by=.2, length.out=3),
148+
c(1.4,1.0,1.2),#swap PCL-CA3 to end
149+
seq(from=1, by=.2, length.out=6),
121150
seq(from=1, by=.2, length.out=2)),
122151
"labels"=names(man.pal)),
123152
aes(x=x, y=y, color=factor(labels, levels=names(man.pal))))+
124-
geom_point(size=3)+scale_color_manual(values=man.pal)+
125-
geom_text(aes(label=labels), nudge_x = .03, hjust=0, color="black", size=4)+
153+
geom_point(size=2)+scale_color_manual(values=man.pal)+
154+
geom_text(aes(label=labels), nudge_x = .03, hjust=0, color="black", size=3)+
126155
scale_y_reverse()+scale_x_continuous(expand=expansion(add=c(.1,.2)))+
127156
theme_void()+
128157
theme(legend.position="none",
129-
plot.margin=unit(c(1,.2,1,.2),"cm"))
158+
plot.margin=unit(c(.2,.2,.2,.2),"cm"))
130159

160+
ggsave("plots/revision/supp_PRECAST-compare-k_pie-legend.pdf", pl, height=1, width=3)
131161

132162
################ spot plots
133163

134-
test = spe[,spe$sample_id %in% c("Br3942_V11L05-333_C1","Br3942_V11L05-333_D1")]
164+
test = spe[,spe$sample_id == "Br3942_V11L05-333_D1"]
135165
load(file=here::here('plots','spatial_palette_final.rda'))
136166

137167
k16.pal = c("10"="#5ffffb","8"="#99ff99","1"="#61963d", "14"="#add294", "9"="#00dc00",
@@ -144,50 +174,33 @@ k17.k18.pal = c("10"="#5ffffb","8"="#99ff99","1"="#61963d", "14"="#add294", "9"=
144174
"13"="#444444", "5"="#777777", "15"="#dfa56e",
145175
"6"="#ff3ffc", "16"="#7a007a", "18"="#ff80fe", "12"="#00006a", "11"="#1e1eff")
146176

147-
#test$is15_k17 = test$PRECAST_k17==15
148-
#test$is15_k18 = test$PRECAST_k18==15
149-
plotSpots(test, annotate="k16.f", sample_id="sample_id",
177+
p1 <- plotSpots(test, annotate="k16.f", sample_id="sample_id",
150178
point_size=.5)+
151-
scale_color_manual(values=k16.pal)+theme_void()+ggtitle("k=16")
152-
153-
#legend
154-
ggplot(cbind.data.frame("y"=c(1:9, 1:7), "x"=c(rep(1,9), rep(1.25,7)),
155-
"labels"=names(k16.pal)),
156-
aes(x=x, y=y, color=factor(labels, levels=names(k16.pal))))+
157-
geom_point(size=3)+scale_color_manual(values=k16.pal)+
158-
geom_text(aes(label=labels), nudge_x = .06, hjust=0, color="black", size=4)+
159-
scale_y_reverse()+scale_x_continuous(expand=expansion(add=c(.1,.4)))+#theme_bw()+
160-
theme_void()+
161-
theme(legend.position="none",
162-
plot.margin=unit(c(1,.2,1,.2),"cm"))
163-
164-
plotSpots(test, annotate="k17.f", sample_id="sample_id",
165-
point_size=.5)+
166-
scale_color_manual(values=k17.k18.pal)+theme_void()+ggtitle("k=17")
167-
168-
#legend
169-
ggplot(cbind.data.frame("y"=c(1:9, 1:8), "x"=c(rep(1,9), rep(1.25,8)),
170-
"labels"=setdiff(names(k17.k18.pal),"18")),
171-
aes(x=x, y=y, color=factor(labels,
172-
levels=setdiff(names(k17.k18.pal),"18"))))+
173-
geom_point(size=3)+scale_color_manual(values=k17.k18.pal)+
174-
geom_text(aes(label=labels), nudge_x = .06, hjust=0, color="black", size=4)+
175-
scale_y_reverse()+scale_x_continuous(expand=expansion(add=c(.1,.4)))+#theme_bw()+
176-
theme_void()+
177-
theme(legend.position="none",
178-
plot.margin=unit(c(1,.2,1,.2),"cm"))
179-
180-
plotSpots(test, annotate="k18.f", sample_id="sample_id",
181-
point_size=.5)+
182-
scale_color_manual(values=k17.k18.pal)+theme_void()+ggtitle("k=18")
183-
184-
#legend
185-
ggplot(cbind.data.frame("y"=c(1:9, 1:9), "x"=c(rep(1,9), rep(1.25,9)),
186-
"labels"=names(k17.k18.pal)),
187-
aes(x=x, y=y, color=factor(labels, levels=names(k17.k18.pal))))+
188-
geom_point(size=3)+scale_color_manual(values=k17.k18.pal)+
189-
geom_text(aes(label=labels), nudge_x = .06, hjust=0, color="black", size=4)+
190-
scale_y_reverse()+scale_x_continuous(expand=expansion(add=c(.1,.4)))+#theme_bw()+
191-
theme_void()+
192-
theme(legend.position="none",
193-
plot.margin=unit(c(1,.2,1,.2),"cm"))
179+
scale_color_manual(values=k16.pal)+
180+
guides(colour = guide_legend(ncol = 2))+
181+
theme_void()+labs(color="k=16")+
182+
theme(strip.text=element_blank(), legend.key.size = unit(12, "pt"),
183+
legend.title=element_text(size=12), legend.text=element_text(size=10),
184+
legend.box.spacing= unit(0, "pt"), legend.margin=margin(0,2,0,0, "pt"))
185+
186+
p2 <- plotSpots(test, annotate="k17.f", sample_id="sample_id",
187+
point_size=.5)+
188+
scale_color_manual(values=k17.k18.pal)+
189+
guides(colour = guide_legend(ncol = 2))+
190+
theme_void()+labs(color="k=17")+
191+
theme(strip.text=element_blank(), legend.key.size = unit(12, "pt"),
192+
legend.title=element_text(size=12), legend.text=element_text(size=10),
193+
legend.box.spacing= unit(0, "pt"), legend.margin=margin(0,2,0,0, "pt"))
194+
195+
p3 <- plotSpots(test, annotate="k18.f", sample_id="sample_id",
196+
point_size=.5)+
197+
scale_color_manual(values=k17.k18.pal)+
198+
guides(colour = guide_legend(ncol = 2))+
199+
theme_void()+labs(color="k=18")+
200+
theme(strip.text=element_blank(), legend.key.size = unit(12, "pt"),
201+
legend.title=element_text(size=12), legend.text=element_text(size=10),
202+
legend.box.spacing= unit(0, "pt"), legend.margin=margin(0,2,0,0, "pt"))
203+
204+
pdf(file="plots/revision/supp_PRECAST-compare-k_spot-plots.pdf", height=4, width=12)
205+
gridExtra::grid.arrange(p1, p2, p3, ncol=3)
206+
dev.off()

code/revision/plots_SPG-QC-thresholds.R

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
library(SpatialExperiment)
22
library(dplyr)
33
library(ggplot2)
4-
library(here)
4+
library(ggspavis)
55

66
load(here::here("processed-data", "04_QC", "spe_QC_allSamples.Rdata"))
77

@@ -32,30 +32,59 @@ ggplot(df, aes(x=sorted, y=low_genes))+
3232
theme_bw()+theme(text=element_text(size=16))
3333

3434
### plot spot values
35+
p1 <- ggplot(as.data.frame(colData(spe_spg)), aes(x=brnum, y=sum, color=low_sum_id))+
36+
geom_boxplot(outlier.size=.3, linewidth=.3)+scale_color_manual(values=c("black","red3"))+
37+
scale_y_log10()+scale_x_discrete(labels=c("Br3942\n(VSPG)","Br8325\n(VSPG)"))+
38+
labs(x="donor", y="# UMI", color="spot\nremoved",
39+
title="Library size")+
40+
theme_bw()+theme(text=element_text(size=8), legend.title=element_text(size=7), legend.text=element_text(size=6),
41+
legend.box.spacing= unit(2, "pt"), legend.margin=margin(0,0,0,2, "pt"),
42+
legend.key.size=unit(8,"pt"), legend.position="bottom")
3543

36-
ggplot(as.data.frame(colData(spe_spg)), aes(x=brnum, y=sum, color=low_sum_id))+
37-
geom_boxplot(outlier.size=.5)+scale_color_manual(values=c("black","red3"))+
38-
scale_y_log10()+
39-
labs(x="donor", y="# UMI", color="outlier",
40-
title="QC summary: library size", subtitle="3MAD per capture area")+
41-
theme_bw()+theme(text=element_text(size=16))
42-
43-
ggplot(as.data.frame(colData(spe_spg)), aes(x=brnum, y=detected, color=low_detected_id))+
44-
geom_boxplot(outlier.size=.5)+scale_color_manual(values=c("black","red3"))+
45-
scale_y_log10()+
46-
labs(x="donor", y="# genes", color="outlier",
47-
title="QC summary: detected genes", subtitle="3MAD per capture area")+
48-
theme_bw()+theme(text=element_text(size=16))
4944

45+
p2 <- ggplot(as.data.frame(colData(spe_spg)), aes(x=brnum, y=detected, color=low_detected_id))+
46+
geom_boxplot(outlier.size=.3, linewidth=.3)+scale_color_manual(values=c("black","red3"))+
47+
scale_y_log10()+scale_x_discrete(labels=c("Br3942\n(VSPG)","Br8325\n(VSPG)"))+
48+
labs(x="donor", y="# genes",
49+
title="Detected genes", color="spot\nremoved")+
50+
theme_bw()+theme(text=element_text(size=8), legend.title=element_text(size=7), legend.text=element_text(size=6),
51+
legend.box.spacing= unit(2, "pt"), legend.margin=margin(0,0,0,2, "pt"),
52+
legend.key.size=unit(8,"pt"), legend.position="bottom")
5053

5154
### spots kept
5255

53-
ggplot(as.data.frame(colData(spe_spg)) %>%
54-
mutate(check2=factor(discard_auto_id, levels=c(TRUE, FALSE), labels=c("removed","kept"))),
55-
aes(x=brnum, group=as.factor(sample_id)))+
56-
geom_bar(stat="count", position=position_dodge2(width=.9, preserve="single"),
57-
fill="grey", color="grey20", )+
58-
scale_y_log10()+
56+
p3 <- ggplot(as.data.frame(colData(spe_spg)) %>%
57+
mutate(check2=factor(discard_auto_id, levels=c(TRUE, FALSE), labels=c("removed","kept"))),
58+
aes(x=brnum, group=as.factor(sample_id)))+
59+
geom_bar(stat="count", position="dodge", fill="grey", color="grey20", linewidth=.3)+
60+
scale_y_log10()+scale_x_discrete(labels=c("Br3942\n(VSPG)","Br8325\n(VSPG)"))+
5961
facet_grid(rows=vars(check2))+
60-
labs(x="donor", y="# spots", title="QC summary: spots kept", subtitle="3MAD per capture area")+
61-
theme_bw()+theme(text=element_text(size=16))
62+
labs(x="donor", y="# spots", title="QC summary")+
63+
theme_bw()+theme(text=element_text(size=8))
64+
65+
pdf(file="plots/revision/supp_Vis-SPG-qc.pdf", width=7, height=3)
66+
gridExtra::grid.arrange(p1, p2, p3, ncol=3)
67+
dev.off()
68+
69+
70+
### spot plots
71+
spe_spg$sample_id = factor(spe_spg$sample_id, levels=c("V12D07-332_A1","V12D07-332_D1","V12D07-332_C1","V12D07-332_B1",#br3942
72+
"V12D07-335_B1","V12D07-335_A1","V12D07-335_C1","V12D07-335_D1"#br8325
73+
))
74+
75+
sp1 = plotSpots(spe_spg[,spe_spg$brnum=="Br3942_VSPG"], annotate="discard_auto_id", sample_id="sample_id",
76+
point_size=.2)+
77+
scale_color_manual(values=c("grey","red3"))+theme_void()+
78+
labs(title="Br3942 (VSPG)", color="spot\nremoved")+
79+
theme(strip.background=element_blank(), strip.text=element_blank(),
80+
plot.title.position = "panel", plot.title= element_text(hjust=.5))
81+
sp2 = plotSpots(spe_spg[,spe_spg$brnum=="Br8325_VSPG"], annotate="discard_auto_id", sample_id="sample_id",
82+
point_size=.2)+
83+
scale_color_manual(values=c("grey","red3"))+theme_void()+
84+
labs(title="Br8325 (VSPG)", color="spot\nremoved")+
85+
theme(strip.background=element_blank(), strip.text=element_blank(),
86+
plot.title.position = "panel", plot.title= element_text(hjust=.5))
87+
88+
pdf(file="plots/revision/supp_Vis-SPG-qc_spot-plots.pdf", width=6, height=8)
89+
gridExtra::grid.arrange(sp1, sp2, ncol=1)
90+
dev.off()

code/revision/plots_SRT-QC-thresholds.R

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,35 @@ ggplot(df, aes(x=sorted, y=low_genes))+
3232

3333
### plot spot values
3434

35-
ggplot(as.data.frame(colData(spe_he)), aes(x=brnum, y=sum, color=low_sum_id))+
35+
p1 <- ggplot(as.data.frame(colData(spe_he)), aes(x=brnum, y=sum, color=low_sum_id))+
3636
geom_boxplot(outlier.size=.5)+scale_color_manual(values=c("black","red3"))+
3737
scale_y_log10()+
38-
labs(x="donor", y="# UMI", color="outlier",
39-
title="QC summary: library size", subtitle="3MAD per capture area")+
40-
theme_bw()+theme(text=element_text(size=16))
38+
labs(x="donor", y="# UMI", color="spot\nremoved",
39+
title="QC summary: library size")+
40+
theme_bw()+theme(text=element_text(size=12), legend.title=element_text(size=10), legend.text=element_text(size=8),
41+
legend.box.spacing= unit(2, "pt"), legend.margin=margin(0,0,0,2, "pt"))
4142

42-
ggplot(as.data.frame(colData(spe_he)), aes(x=brnum, y=detected, color=low_detected_id))+
43+
p2 <- ggplot(as.data.frame(colData(spe_he)), aes(x=brnum, y=detected, color=low_detected_id))+
4344
geom_boxplot(outlier.size=.5)+scale_color_manual(values=c("black","red3"))+
4445
scale_y_log10()+
4546
labs(x="donor", y="# genes", color="outlier",
46-
title="QC summary: detected genes", subtitle="3MAD per capture area")+
47-
theme_bw()+theme(text=element_text(size=16))
47+
title="QC summary: detected genes", color="spot\nremoved")+
48+
theme_bw()+theme(text=element_text(size=12), legend.title=element_text(size=10), legend.text=element_text(size=8),
49+
legend.box.spacing= unit(2, "pt"), legend.margin=margin(0,0,0,2, "pt"))
4850

4951
### spots kept
5052

51-
ggplot(as.data.frame(colData(spe_he)) %>%
53+
p3 <- ggplot(as.data.frame(colData(spe_he)) %>%
5254
mutate(check2=factor(discard_auto_id, levels=c(TRUE, FALSE), labels=c("removed","kept"))),
5355
aes(x=brnum, group=as.factor(sample_id)))+
5456
geom_bar(stat="count", position=position_dodge2(width=.9, preserve="single"),
5557
fill="grey", color="grey20", )+
5658
scale_y_log10()+
57-
facet_grid(cols=vars(check2))+
58-
labs(x="donor", y="# spots", title="QC summary: spots kept", subtitle="3MAD per capture area")+
59-
theme_bw()+theme(text=element_text(size=16))
59+
facet_grid(rows=vars(check2))+
60+
labs(x="donor", y="# spots", title="QC summary: spots kept")+
61+
theme_bw()+theme(text=element_text(size=12))
62+
63+
pdf(file="plots/revision/supp_Vis-HE-qc.pdf", width=7, height=9)
64+
gridExtra::grid.arrange(p1, p2, p3, ncol=1)
65+
dev.off()
66+

0 commit comments

Comments
 (0)