forked from knights-lab/IMP_analyses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rapp.history
589 lines (540 loc) · 27.5 KB
/
.Rapp.history
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
Sys.getenv("PATH")
source("/Users/pvangay/Copy/UMN/Knights Lab/Probiotics/to send/diff.otus.R")
library(pwr)
?pwr.anova.test
pwr.anova.test(k=2, f=.1, power=.8)
pwr.anova.test(k=2, f=.25, power=.8)
pwr.anova.test(k=2, f=.4, power=.8)
paste("a", letters[1:3])
agrep
agrep(pattern="[0-9]+", x=c("tesres2222", "sfsd"))
?agrep
agrep(pattern="[:digit:]+", x=c("tesres2222", "sfsd"))
agrep(pattern="[:digit:]", x=c("tesres2222", "sfsd"))
agrep(pattern="^tes", x=c("tesres2222", "sfsd"))
agrep(pattern="([0-9])", x=c("tesres2222", "sfsd"))
?outlier
x <- cbind(1:5, 5:10)
x <- cbind(1:5, 5:9)
x
c(x)
c(as.data.frame(x))
c(as.matrix(as.data.frame(x)))
counts = 17689
lengths = 225
eps = 0.05
a <- (1-eps)^counts b <- (1 / (3^(counts-1))) c <- eps^counts x <- a / (a + b * c) y <- 1 - x^lengths
y[1]
a[1]
b[1]
c[1]
x[1]
b[1]==0
x <- (1-eps)^counts / ((1-eps)^counts + (1 / (3^(counts-1)))*eps^counts)
x[1]
counts = 11420
a <- (1-eps)^counts b <- (1 / (3^(counts-1))) c <- eps^counts x <- a / (a + b * c) y <- 1 - x^lengths
a[1]
(1-.05)^15000
(1-.05)^14000
min(double)
double.xmin
.Machine
.Machine$double.xmin
a <- .Machine$double.xmin
a / (a + a*a)
print(a)
1-a^225
a <- NA
is.na(a)
is.null(a)
is.null(NULL)
356563*.05
7/17828.15
1-7/17828.15
?scan
x <- c(3,4,56,3,5,3,3)
unique(x)
library(pwr)
pwr.anova.test(k=2, f=abs(-0.0157416/(2*0.0213438)), power=.8)
pwr.anova.test(k=2, f=abs(-0.0157416/(2*0.095)), power=.8)
pwr.anova.test(k=2, f=abs(-0.1557416/(2*0.01)), power=.8)
pwr.anova.test(k=2, f=abs(0.155/(2*0.0107)), power=.8)
pwr.anova.test(k=2, f=abs(0.03345/(2*0.00928)), power=.8)
pwr.anova.test(k=2, f=abs(0.013/(2*.03)), power=.8)
pwr.anova.test(k=2, f=abs(0.006/(2*.011)), power=.8)
pwr.anova.test(k=2, f=abs(0.005/(2*.009)), power=.8)
pwr.anova.test(k=2, f=abs(0.001/(2*.0002)), power=.8)
x <- (0.7628,0.0147,0.9342,0.1107,0.6797,3.77E-08)
x <- c(0.7628,0.0147,0.9342,0.1107,0.6797,3.77E-08)
apply(p.adjust, x, n=118)
apply(x, 1, p.adjust, n=118)
lapply(x, p.adjust, n=118)
unlist(lapply(x, p.adjust, n=118))
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <- c(0.99027,0.01113,0.4947,0.00593,0.68112,2.00E-16)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <- c(0.762751,0.014663,0.934182,0.110733,0.6797,0.000474)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.99027,0.01113,0.4947,0.00593,0.68112,0.11016)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.0151,0.2543,0.5273,0.1373,0.6461)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.24,0.982,0.711,0.135,0.252)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(00.23701,0.00406,0.5826,0.17664,0.35576)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.7822,0.00425,0.49998,0.00642,0.83877)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.62879,0.24398,0.85792,0.56728,0.17594,0.00197,0.34862)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.595889,0.057916,0.783039,0.699298,0.195882,0.000785,0.905865)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.422,0.103,0.596,0.188,0.281,0.445,0.434)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.859907,0.019876,0.927471,0.210074,0.912991,0.033952,0.000183)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.39105,0.00896,0.56906,0.85463,0.82854,0.00265,0.6415)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.842973,0.191493,0.899186,0.697909,0.624673,0.000883,0.100037)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.6204,0.0262,0.8081,0.2157,0.5274)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.5176,0.0166,0.8463,0.1508,0.3899)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.685,0.0109,0.6065,0.1982,0.3044)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.83045,0.000583,0.629129,0.593527,0.735863)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <-c(0.93858,0.00515,0.83757,0.49479,0.92551)
unlist(lapply(x, p.adjust, n=118, method="fdr"))
x <- rep(0.0147, 119)
p.adjust(x, method="fdr")
x
x <- cbind(c(1,1,1), c(2,2,2))
x
colMeans(x)
x <- cbind(c(1,1,1), c(2,2,2))
x
rownames(x) <- c("a","b","c")
rownames(x)[which(x[,1] %in% c(1,2))]
rownames(x)[x[,1] %in% c(1,2)]
x[,1] %in% c(1,2)
?rank
library(beeswarm)
beeswarm(x=-log10(rep(1:10)), main="Alpha Diversity",#
ylab="Effect Size", pwpch=rep(23,length(unlist(cols))), pwcol=unlist(cols), pwbg=unlist(cols))#
legend("topright", legend = c("Yes", "No"), pch = pch , col = 1:2)
beeswarm(x=(rep(1:10)), main="Alpha Diversity",#
ylab="Effect Size", pwpch=rep(23,length(unlist(cols))), pwcol=unlist(cols), pwbg=unlist(cols))#
legend("topright", legend = c("Yes", "No"), pch = pch , col = 1:2)
beeswarm(x=(rep(1:10)), main="Alpha Diversity")
line(1)
abline(h=2)
beeswarm(x=(rep(1:10)), main="Alpha Diversity")
abline(h=2, lty=2)
?wilcox.test
?lm
test <- cbind(1:2,1:2)
rownames(test) <- "#S"
rownames(test) <- c("#S", "1")
test
?abline
x <- 1 > 3
x
x <- 5 > 3
x
class(x)
pwr.anova.test()
library(pwr)
?pwr.anova.test()
pwr.anova.test(2, f=-0.0334525, sig.level=0.05, power=.80)
pwr.anova.test(2, f=0.0334525, sig.level=0.05, power=.80)
pwr.anova.test(2, f=0.1555, sig.level=0.05, power=.80)
pwr.t.test(sig.level=0.05, power=.80, type="two.sample", d=.1554/.0107)
pwr.t.test(sig.level=0.05, power=.80, type="two.sample", d=.03345/.00928)
pwr.t.test(sig.level=0.05, power=.80, type="two.sample", d=..03/.001)
pwr.t.test(sig.level=0.05, power=.80, type="two.sample", d=..03/.003)
pwr.t.test(sig.level=0.05, power=.80, type="two.sample", d=.03/.003)
pwr.t.test(sig.level=0.05, power=.80, type="two.sample", d=.007/.001)
pwr.t.test(sig.level=0.05, power=.80, type="two.sample", d=.145/.02)
pwr.t.test(sig.level=0.05, power=.80, type="two.sample", d=.001746/.0002)
.03345/.00928
?Sys.geten
?Sys.getenv
library(optparse)
install.packages("optparse")
library(optparse)
?hclust
source("/Users/pvangay/Dropbox/UMN/KnightsLab/IMP/ANALYSES/analysis/bin/load.r")
dm <- wuf_dm[cs,cs] # best to use unifrac hereddm <- as.dist(dm)pc <- cmdscale(ddm,2)map0 <- map[cs,]bd <- betadisper(ddm, map0$Sample.Group)centroid.dist <- bd$distances # distances of all samples to their group centroids!hmong1 <- names(sort(centroid.dist[rownames(map0)[map0$Sub.Study=="CS" & map0$Years.in.US > 30 & map0$Sample.Group=="Hmong1st"]])[1:15])
use.rare=FALSE
source("/Users/pvangay/Dropbox/UMN/KnightsLab/IMP/ANALYSES/analysis/bin/load.r")
dm <- wuf_dm[cs,cs] # best to use unifrac hereddm <- as.dist(dm)pc <- cmdscale(ddm,2)map0 <- map[cs,]bd <- betadisper(ddm, map0$Sample.Group)centroid.dist <- bd$distances # distances of all samples to their group centroids!hmong1 <- names(sort(centroid.dist[rownames(map0)[map0$Sub.Study=="CS" & map0$Years.in.US > 30 & map0$Sample.Group=="Hmong1st"]])[1:15])
dm <- wuf_dm[cs,cs] # best to use unifrac hereddm <- as.dist(dm)pc <- cmdscale(ddm,2)map0 <- map[cs,]bd <- betadisper(ddm, map0$Sample.Group)centroid.dist <- bd$distances # distances of all samples to their group centroids!hmong1 <- names(sort(centroid.dist[rownames(map0)[map0$Sub.Study=="CS" & map0$Years.in.US > 30 & map0$Sample.Group=="Hmong1st"]])[1:20])
hmong1
hmong1 <- names(sort(centroid.dist[rownames(map0)[map0$Sub.Study=="CS" & map0$Years.in.US > 30 & map0$Sample.Group=="Hmong1st"]])[1:18])
hmong1
o.hmong.1 <- map0[hmong1,c("Age","BMI")]
o.hmong.1
sort(centroid.dist[rownames(map0)[map0$Sub.Study=="CS" & map0$Years.in.US > 30 & map0$Sample.Group=="Hmong1st"]])[1:18]
bp2 <- plot.b.p.ratio(map0[hmong1,], taxa, bug1=bacteroides, bug2=prevotella, outputfn="hmong1.b.p.ratio.pdf")
getwd()
map0[c("CS.347.0", "CS.164", "CS.228"),c("Age","BMI")]
d <- data.frame(x = pc[,1], y = pc[,2], group=map0$Sample.Group, distance=substring(as.character(centroid.dist[rownames(map0)]),1,4))# set the levels of Sample.Group so that it's the same every timed$group <- factor(d$group, levels=sort(as.character(unique(d$group))))group.cols <- c(alpha(wes_palette(n=5, name="Moonrise3"), .8))p <- ggplot(data=d, aes(x, y)) + geom_point(colour=alpha("gray",.5), size=2) + scale_color_manual(values=group.cols) + #sets the color palette of the fill stat_ellipse(data=d, aes(colour=group), show.legend=T, type="t", level=.6)
d <- data.frame(x = pc[,1], y = pc[,2], group=map0$Sample.Group, distance=substring(as.character(centroid.dist[rownames(map0)]),1,4))# set the levels of Sample.Group so that it's the same every timed$group <- factor(d$group, levels=sort(as.character(unique(d$group))))group.cols <- get.group.colors(groups=as.character(levels(d$group)), alpha.val=.8)p <- ggplot(data=d, aes(x, y)) + geom_point(colour=alpha("gray",.5), size=2) + scale_color_manual(values=group.cols) + #sets the color palette of the fill stat_ellipse(data=d, aes(colour=group), show.legend=T, type="t", level=.6)
p
p <- p + geom_text(data = d[hmong1, ], aes(label=hmong1) ,hjust=0, vjust=0, size=3)
p
hmongthai <- names(sort(centroid.dist[rownames(map0)[map0$Sample.Group=="HmongThai"]])[1:15])
hmongthai
hmong1 <- names(sort(centroid.dist[rownames(map0)[map0$Sub.Study=="CS" & map0$Years.in.US > 29 & map0$Sample.Group=="Hmong1st"]]))
hmong1
sort(map0[hmong1,"Years.in.US"])
sort(map0[hmong1,"Years.in.US", drop=F])
x <- map0[hmong1,"Years.in.US", drop=F]
x[order(x[,1]),]
x
x[order(x[,1]),,drop=F]
rownames(x[order(x[,1]),,drop=F])[1:5]
maybes <- rownames(x[order(x[,1]),,drop=F])[1:5]
maybes
map0[maybes,c("Age","BMI")]
bp2 <- plot.b.p.ratio(map0[hmong1,], taxa, bug1=bacteroides, bug2=prevotella, outputfn="hmong1.b.p.ratio.pdf")
d <- data.frame(x = pc[,1], y = pc[,2], group=map0$Sample.Group, distance=substring(as.character(centroid.dist[rownames(map0)]),1,4))# set the levels of Sample.Group so that it's the same every timed$group <- factor(d$group, levels=sort(as.character(unique(d$group))))group.cols <- get.group.colors(groups=as.character(levels(d$group)), alpha.val=.8)p <- ggplot(data=d, aes(x, y)) + geom_point(colour=alpha("gray",.5), size=2) + scale_color_manual(values=group.cols) + #sets the color palette of the fill stat_ellipse(data=d, aes(colour=group), show.legend=T, type="t", level=.6)# label points by distances#p <- p + geom_text(data = d[hmong1, ], aes(label=distance) ,hjust=0, vjust=0, size=3)# label points by sample namep <- p + geom_text(data = d[hmong1, ], aes(label=hmong1) ,hjust=0, vjust=0, size=3)
p
bp["CS.388",]
bp <- plot.b.p.ratio(map0[cs,], taxa, bug1=bacteroides, bug2=prevotella, outputfn="temp.b.p.ratio.pdf")
bp["CS.388",]
dim(bp)
class(bp)
mybp <- get.taxa.ratio(prevotella,bacteroides)
mybp <- get.taxa.ratio(taxa,prevotella,bacteroides)
mylogbp <- log10(mybp)
mylogbp["CS.388"]
plot(mylogbp[hmong1], map0[hmong1,"Years.in.US"])
plot(map0[hmong1,"Years.in.US"],mylogbp[hmong1])
mybp <- get.taxa.ratio(taxa,bacteroides, prevotella)
mylogbp <- log10(mybp)
plot(map0[hmong1,"Years.in.US"],mylogbp[hmong1])
mylogbp["CS.388"]
mylogbp["CS.135"]
mylogbp["CS.222"]
?pam
sessionInfo()
write.table(fake_seqs, file="possible.chimeras.txt", quote=F, row.names=F, col.names=F)
x <- humann2_genefamilies_col_norm_stratified.tsv
x <- "humann2_genefamilies_col_norm_stratified.tsv"
sub('.*\\.', "_collapsed\\.", x)
sub('\\..*$', "_collapsed\\.", x)
sub('(\\..*)$', "_collapsed\\1", x)
x <- "humann2_genefamilies_col.norm.stratified.tsv"
sub('(\\..*)$', "_collapsed\\1", x)
x
y <- TRUE
class(y)
library(ggsignif)
?geom_signif
library(lme4)library(ggpubr)library(ggplot2)library(RColorBrewer)library(ggbeeswarm)library(cowplot)library(scales)library(ggsignif)library(reshape)source("/Users/pvangay/Dropbox/UMN/KnightsLab/IMP/ANALYSES/analysis/lib/mouse.villus.crypt.r")setwd("/Users/pvangay/Dropbox/UMN/KnightsLab/IMP/ANALYSES/analysis")
vc_fn <- "/Users/pvangay/Dropbox/UMN/KnightsLab/IMP/ANALYSES/analysis/data/mouse_exp/all-cpsr-measurements.txt" mice_fn <- "/Users/pvangay/Dropbox/UMN/KnightsLab/IMP/ANALYSES/analysis/data/mouse_exp/All Mouse Data.txt" immune_fn <- "/Users/pvangay/Dropbox/UMN/KnightsLab/IMP/ANALYSES/analysis/data/mouse_exp/immune-cell-counts.txt" body_comp_fn <- "/Users/pvangay/Dropbox/UMN/KnightsLab/IMP/ANALYSES/analysis/data/mouse_exp/Body Composition.txt" mice <- read.table(file=mice_fn, sep="\t", header=T, as.is=T, quote="") villus_crypt <- read.table(file=vc_fn, sep="\t", header=T, as.is=T) immune <- read.table(file=immune_fn, sep="\t", header=T, as.is=T, check.names=F, quote="", comment="") body_comp <- read.table(file=body_comp_fn, sep="\t", header=T, as.is=T) mouse.id.levels <- paste0("M", sort(as.numeric(unique(gsub("M", "", mice$Mouse.ID))))) mice$Mouse.ID <- factor(mice$Mouse.ID, levels=mouse.id.levels) villus_crypt$Mouse.ID <- factor(villus_crypt$Mouse.ID, levels=mouse.id.levels) immune$Mouse.ID <- factor(immune$Mouse.ID, levels=mouse.id.levels) body_comp$Mouse.ID <- factor(body_comp$Mouse.ID, levels=mouse.id.levels) colnames(mice) <- gsub("\\.\\.g\\.", "", colnames(mice)) colnames(body_comp) <- gsub("\\.\\.g\\.", "", colnames(body_comp))#
mice$Group <- factor(paste(mice$Donor.Type, mice$Diet.Type, sep="."), levels=c("Thai.HighFiber", "Thai.LowFiber", "US.HighFiber", "US.LowFiber", "Cohoused.HighFiber", "Cohoused.LowFiber")) # get the start and end dates for all mice mice$Date <- as.Date(mice$Date, format="%m/%d/%y") endpoint <- aggregate(Date ~ Mouse.ID, mice, FUN=max) baseline <- aggregate(Date ~ Mouse.ID, mice, FUN=min) endpoint$Date <- as.Date(endpoint$Date) baseline$Date <- as.Date(baseline$Date) endpoint$Mouse.ID <- factor(endpoint$Mouse.ID, levels=mouse.id.levels) baseline$Mouse.ID <- factor(baseline$Mouse.ID, levels=mouse.id.levels) # transform dates into experiment week for(i in 1:nrow(baseline)) { this.mouse <- baseline$Mouse.ID[i] mice[mice$Mouse.ID == this.mouse, "Week"] <- (as.numeric(mice[mice$Mouse.ID == this.mouse, "Date"] - baseline$Date[i]))/7 }#
# global vars # Thai.HighFiber=darkorange, Thai.LowFiber=lightorange, US.HighFiber=darkblue, US.LowFiber=lightblue, Cohoused.HighFiber=darkgray, Cohoused.LowFiber=lightgray GROUP.COLORS <<- c("#F1651D", "#FEA360", "#0A97B7", "#55CFD6", "#68656E","#ABA1A0") names(GROUP.COLORS) <- levels(mice$Group)
base.cell.type <- "Count.CD3e+" #"Count.Live.CD45+" #"Count.CD3e+"#
count.cell.names <- grep("^Count", colnames(immune), value=T)#
IEL <- immune[immune$Cell.Population=="IEL",]#
# divide total count of cell types by total counts of CD45 (basic immune cell types) instead of using "per inch" estimates (biased) ratio.names <- paste0(gsub("Count\\.", "", count.cell.names)) IEL[,ratio.names] <- IEL[,count.cell.names]/IEL[,base.cell.type] end.groups <- merge(endpoint, mice[,c("Mouse.ID","Group","Date")], by=c("Mouse.ID","Date"), all.x=T) end.groups$Mouse.ID <- as.character(end.groups$Mouse.ID) gg_iel <- merge(IEL, end.groups, by="Mouse.ID")#
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=.1, size=.1) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=1) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
?geom_signif
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=1, margin_top=.5) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=1, step_increase=.03) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=2, step_increase=.03) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=2, step_increase=.06) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=2, step_increase=.06,map_signif_level=TRUE) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=2, step_increase=.08) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=1.8, step_increase=.08) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)
base.cell.type <- "Count.Live.CD45+" #"Count.CD3e+"#
count.cell.names <- grep("^Count", colnames(immune), value=T)#
IEL <- immune[immune$Cell.Population=="IEL",]#
# divide total count of cell types by total counts of CD45 (basic immune cell types) instead of using "per inch" estimates (biased) ratio.names <- paste0(gsub("Count\\.", "", count.cell.names)) IEL[,ratio.names] <- IEL[,count.cell.names]/IEL[,base.cell.type] end.groups <- merge(endpoint, mice[,c("Mouse.ID","Group","Date")], by=c("Mouse.ID","Date"), all.x=T) end.groups$Mouse.ID <- as.character(end.groups$Mouse.ID) gg_iel <- merge(IEL, end.groups, by="Mouse.ID")#
p <- list() cell.types <- ratio.names for(i in 1:length(cell.types)) { gd <- gg_iel[,c(cell.types[i], "Mouse.ID", "Group")] colnames(gd)[1] <- "Cell.Type" p[[i]] <- ggplot(gd, aes(x=Group, y=Cell.Type, group=Group, color=Group)) + geom_boxplot(aes(fill=Group), colour="black", width=.9) + scale_fill_manual(values = GROUP.COLORS) + ggtitle(cell.types[i]) + ylab("") + xlab("") + theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), strip.background = element_blank(), strip.text.x = element_blank(), legend.position="none", plot.title = element_text(size=10)) tuke <- TukeyHSD(aov(gd$Cell.Type ~ gd$Group))$"gd$Group"[,"p adj"] sig.pvals <- signif(tuke[tuke < .10],2) comparisons <- strsplit(names(sig.pvals),"-") # if there are significant comparisons, show them if(length(sig.pvals) > 0) p[[i]] <- p[[i]] + geom_signif(comparisons = comparisons, annotation=as.character(sig.pvals), color="black", tip_length=.01, textsize=1.8, step_increase=.08) } save_plot(paste0("immune-cells-per-", base.cell.type,".pdf"), plot_grid(plotlist=p, ncol=3), base_aspect_ratio = 1.8)