Skip to content

Commit 90375cd

Browse files
committed
Final updates to supplemental figures
1 parent f6a73bb commit 90375cd

File tree

2 files changed

+61
-68
lines changed

2 files changed

+61
-68
lines changed

code/revision/plots_nmf-donor-bias-bar-94.R

Lines changed: 61 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,25 @@ gen.non0 = cbind(as.data.frame(gen.non0.mtx), as.data.frame(colData(sce)[rowname
5454
test = group_by(gen.non0, brnum, round, sort) %>% summarise_at(gen.nmf, sum) %>%
5555
tidyr::pivot_longer(all_of(gen.nmf), names_to="nmf", values_to="n.non0.spots")
5656
test$nmf_f = factor(test$nmf, levels=nmf.ordered.keep)
57-
test$xlabel = paste(test$brnum, test$round, test$sort)
58-
59-
ggplot(group_by(test, nmf_f, xlabel) %>% summarise(n.non0.spots=sum(n.non0.spots)),
60-
aes(y=n.non0.spots, x=nmf_f, fill=xlabel))+
61-
geom_bar(stat="identity", position="fill", color="grey50")+theme_bw()+
62-
scale_fill_manual(values=c("#a6cee3","#74add1","#4575b4","#313695",
63-
"#b2df8a","#33a02c",
64-
"#fb9a99","#e31a1c",#3492
65-
"#fee08b","#fdbf6f","#ff7f00","#f46d43",#6423
66-
"#c2a5cf","#6a3d9a",#6432
67-
"grey","grey50",#6471
68-
"#ffff99","goldenrod","#b35806","#7f3b08",#6522
69-
"#8dd3c7","aquamarine",#8325
70-
"#f4a582","#b2182b",#8492
71-
"grey40","black"))+#8667
72-
labs(y="% nuclei with non-0 loading", title="General NMF patterns",fill="Sample")+
73-
theme(axis.text.x=element_text(angle=90, hjust=1, vjust=.5))
57+
test$xlabel = paste(test$brnum, test$sort)
58+
59+
sn.brnum.palette = c("#4575b4","#313695", "#b2df8a","#33a02c",
60+
"#fb9a99","#e31a1c", "#ff7f00","#f46d43",
61+
"#c2a5cf","#6a3d9a", "grey","grey50",
62+
"#ffff99","goldenrod", "#8dd3c7","aquamarine",
63+
"#f4a582","#b2182b", "grey40","black")
64+
names(sn.brnum.palette) = paste(rep(c("Br2720","Br2743","Br3942","Br6423","Br6432",
65+
"Br6471","Br6522","Br8325","Br8492","Br8667"), each=2),
66+
rep(c("PI","PI+NeuN+"), length.out=20))
67+
68+
g1 <- ggplot(group_by(test, nmf_f, xlabel) %>% summarise(n.non0.spots=sum(n.non0.spots)),
69+
aes(x=n.non0.spots, y=nmf_f, fill=xlabel))+
70+
geom_bar(stat="identity", position="fill", color="grey50", linewidth=.5, width=1)+
71+
scale_x_continuous(expand=c(0,0))+
72+
scale_fill_manual(values=sn.brnum.palette)+guides(fill = guide_legend(ncol = 2))+
73+
labs(x="% nuclei with non-0 loading", title="General NMF patterns: snRNA-seq",fill="Sample")+
74+
theme_minimal()+theme(legend.position="bottom", legend.byrow = T, axis.ticks.x = element_line(color="black"),
75+
axis.title.y=element_blank(), axis.text.x=element_text(hjust=1), text=element_text(size=10))
7476

7577
#specific patterns only
7678
spec.nmf = setdiff(nmf.ordered.keep, gen.nmf)
@@ -81,22 +83,16 @@ spec.non0 = cbind(as.data.frame(spec.non0.mtx),
8183
test2 = group_by(spec.non0, brnum, round, sort) %>% summarise_at(spec.nmf, sum) %>%
8284
tidyr::pivot_longer(all_of(spec.nmf), names_to="nmf", values_to="n.non0.spots")
8385
test2$nmf_f = factor(test2$nmf, levels=nmf.ordered.keep)
84-
test2$xlabel = paste(test2$brnum, test2$round, test2$sort)
85-
86-
ggplot(group_by(test2, nmf_f, xlabel) %>% summarise(n.non0.spots=sum(n.non0.spots)),
87-
aes(y=n.non0.spots, x=nmf_f, fill=xlabel))+
88-
geom_bar(stat="identity", position="fill", color="grey50")+theme_bw()+
89-
scale_fill_manual(values=c("#a6cee3","#74add1","#4575b4","#313695",#2720
90-
"#b2df8a","#33a02c",#2743
91-
"#fb9a99","#e31a1c",#3492
92-
"#fdbf6f","#ff7f00","#fee08b","#f46d43",#6423
93-
"#c2a5cf","#6a3d9a",#6432
94-
"grey","grey50",#6471
95-
"#ffff99","goldenrod","#b35806","#7f3b08",#6522
96-
"#8dd3c7","aquamarine",#8325
97-
"#f4a582","#b2182b",#8492
98-
"grey40","black"))+#8667
99-
labs(y="% nuclei with non-0 loading", title="Specific NMF patterns",fill="Sample")
86+
test2$xlabel = paste(test2$brnum, test2$sort)
87+
88+
s1 <- ggplot(group_by(test2, nmf_f, xlabel) %>% summarise(n.non0.spots=sum(n.non0.spots)),
89+
aes(x=n.non0.spots, y=nmf_f, fill=xlabel))+
90+
geom_bar(stat="identity", position="fill", color="grey50", linewidth=.5, width=1)+
91+
scale_x_continuous(expand=c(0,0))+
92+
scale_fill_manual(values=sn.brnum.palette)+
93+
labs(x="% nuclei with non-0 loading", title="Specific NMF patterns: snRNA-seq")+
94+
theme_minimal()+theme(legend.position="none", axis.title.y=element_blank(), axis.text.x=element_text(hjust=1),
95+
axis.ticks.x = element_line(color="black"), text=element_text(size=10))
10096

10197
#################
10298
## ok now do same as above but with SRT
@@ -107,53 +103,50 @@ gen.non0.mtx = as.matrix(colData(spe)[,gen.nmf])
107103
gen.non0.mtx = gen.non0.mtx>0
108104
gen.non0 = cbind(as.data.frame(gen.non0.mtx),
109105
as.data.frame(colData(spe)[rownames(gen.non0.mtx),c("brnum","sample_id")]))
110-
test = group_by(gen.non0, brnum, sample_id) %>% summarise_at(gen.nmf, sum) %>%
106+
test3 = group_by(gen.non0, brnum, sample_id) %>% summarise_at(gen.nmf, sum) %>%
111107
tidyr::pivot_longer(all_of(gen.nmf), names_to="nmf", values_to="n.non0.spots")
112-
test$nmf_f = factor(test$nmf, levels=nmf.ordered.keep)
113-
test$brnum_f = factor(test$brnum, levels=levels(spe$brnum)[c(10,1:9)])
108+
test3$nmf_f = factor(test3$nmf, levels=nmf.ordered.keep)
109+
test3$brnum_f = factor(test3$brnum, levels=levels(spe$brnum)[c(10,1:9)])
114110

115-
ggplot(group_by(test, nmf_f, brnum_f) %>% summarise(n.non0.spots=sum(n.non0.spots)),
111+
brnum.palette = c("#313695","#33a02c","#fb9a99","#ff7f00","#6a3d9a",
112+
"grey","#ffff99","#8dd3c7","#b2182b","grey40")
113+
names(brnum.palette) <- c("Br2720","Br2743","Br3942","Br6423","Br6432",
114+
"Br6471","Br6522","Br8325","Br8492","Br8667")
115+
116+
g2 <- ggplot(group_by(test3, nmf_f, brnum_f) %>% summarise(n.non0.spots=sum(n.non0.spots)),
116117
aes(x=n.non0.spots, y=nmf_f, fill=brnum_f))+
117-
geom_bar(stat="identity", position="fill", color="grey50")+theme_bw()+
118-
scale_fill_manual(values=c("#313695",#2720
119-
"#33a02c",#2743
120-
"#fb9a99",#3492
121-
"#ff7f00",#6423
122-
"#6a3d9a",#6432
123-
"grey",#6471
124-
"#ffff99",#6522
125-
"#8dd3c7",#8325
126-
"#b2182b",#8492
127-
"grey40","black"#8667
128-
))+
129-
labs(x="% spots with non-0 loading", title="General NMF patterns",fill="Donor")
118+
geom_bar(stat="identity", position="fill", color="grey50", linewidth=.5, width=1)+
119+
scale_x_continuous(expand=c(0,0))+
120+
scale_fill_manual(values=brnum.palette)+
121+
guides(fill = guide_legend(ncol = 1))+
122+
labs(x="% spots with non-0 loading", title="General NMF patterns: SRT",fill="Donor")+
123+
theme_minimal()+theme(legend.position="bottom", legend.byrow = T,
124+
axis.title.y=element_blank(), axis.text.x=element_text(hjust=1),
125+
axis.ticks.x = element_line(color="black"), text=element_text(size=10))
130126

131127
#specific patterns
132128
spec.nmf = setdiff(nmf.ordered.keep, gen.nmf)
133129
spec.non0.mtx = as.matrix(colData(spe)[,spec.nmf])
134130
spec.non0.mtx = spec.non0.mtx>0
135131
spec.non0 = cbind(as.data.frame(spec.non0.mtx),
136132
as.data.frame(colData(spe)[rownames(spec.non0.mtx),c("brnum","sample_id")]))
137-
test2 = group_by(spec.non0, brnum) %>% summarise_at(spec.nmf, sum) %>%
133+
test4 = group_by(spec.non0, brnum) %>% summarise_at(spec.nmf, sum) %>%
138134
tidyr::pivot_longer(all_of(spec.nmf), names_to="nmf", values_to="n.non0.spots")
139-
test2$nmf_f = factor(test2$nmf, levels=nmf.ordered.keep)
140-
test2$brnum_f = factor(test2$brnum, levels=levels(spe$brnum)[c(10,1:9)])
135+
test4$nmf_f = factor(test4$nmf, levels=nmf.ordered.keep)
136+
test4$brnum_f = factor(test4$brnum, levels=levels(spe$brnum)[c(10,1:9)])
141137

142-
ggplot(group_by(test2, nmf_f, brnum_f) %>% summarise(n.non0.spots=sum(n.non0.spots)),
138+
s2 <- ggplot(group_by(test4, nmf_f, brnum_f) %>% summarise(n.non0.spots=sum(n.non0.spots)),
143139
aes(x=n.non0.spots, y=nmf_f, fill=brnum_f))+
144-
geom_bar(stat="identity", position="fill", color="grey50")+theme_bw()+
145-
scale_fill_manual(values=c("#313695",#2720
146-
"#33a02c",#2743
147-
"#fb9a99",#3492
148-
"#ff7f00",#6423
149-
"#6a3d9a",#6432
150-
"grey",#6471
151-
"#ffff99",#6522
152-
"#8dd3c7",#8325
153-
"#b2182b",#8492
154-
"grey40","black"#8667
155-
))+
156-
labs(x="% spots with non-0 loading", title="Specific NMF patterns",fill="Donor")
140+
geom_bar(stat="identity", position="fill", color="grey50", linewidth=.5, width=1)+
141+
scale_x_continuous(expand=c(0,0))+
142+
scale_fill_manual(values=brnum.palette)+
143+
labs(x="% spots with non-0 loading", title="Specific NMF patterns: SRT")+
144+
theme_minimal()+theme(legend.position="none", axis.title.y=element_blank(), axis.text.x=element_text(hjust=1),
145+
axis.ticks.x = element_line(color="black"), text=element_text(size=10))
146+
147+
pdf(file="plots/revision/supp_nmf-donor-proportion.pdf", height=12, width=8)
148+
gridExtra::grid.arrange(g1, s1, g2, s2, ncol=2)
149+
dev.off()
157150

158151
#################
159152
## look at nmf94 that became cell type specific
@@ -237,7 +230,7 @@ plotReducedDim(sce, dimred="UMAP", color_by="TTR", point_size=.1)+
237230
brnum.palette = c("#313695","#33a02c","#fb9a99","#ff7f00","#6a3d9a",
238231
"grey","#ffff99","#8dd3c7","#b2182b","grey40")
239232
names(brnum.palette) <- c("Br2720","Br2743","Br3942","Br6423","Br6432",
240-
"Br6471","Br6522","Br8325","Br8492","Br88667")
233+
"Br6471","Br6522","Br8325","Br8492","Br8667")
241234

242235
filter(as.data.frame(colData(sce)), mid.cell.class=="CSF") %>% pull(brnum) %>% table()
243236
ggplot(filter(as.data.frame(colData(sce)), mid.cell.class=="CSF"),
26.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)