output <- paste("Indexed/",ID,".tmp", sep="")
output2 <- paste("Read_counts/",ID,".tmp", sep="")
output3 <- paste("Plots/",ID,".pdf", sep="")
header <- colnames(myData5)
write.table(header, "Indexed/1_header.csv", sep=",",  col.names=FALSE, row.names =FALSE)
write.table(myData5, output, sep=",",  col.names=FALSE, row.names =FALSE)
write.table(Read_counts, output2, sep=",",  col.names=FALSE, row.names =FALSE)
#Append data to dataframe All_reads
All_reads <- rbind(All_reads, myData5)
#Okey lets also make some plots
Titel <- unique(myData5$Sample)
Fig1 <- ggplot(myData5, stats = "identity", aes(Strain, fill = allel)) +
geom_col(data=myData5, aes(Strain, Relative_abundance)) +
geom_hline(yintercept = 0.017) +
background_grid(major = "none", minor = "none") + # add thin horizontal lines
#theme_classic() +
panel_border(colour = "black", size = 1) + # and a border around each panel
labs (title = Titel) +
#coord_cartesian(ylim=c(0.0001, 0.01), expand = F) + #ylim=c(-0, 12.5)
#scale_y_discrete(limits=c(0.0001,0.001,0.01,0.1,1)) +
#scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
#labels = trans_format("log10", math_format(10^.x))) +
#coord_flip() +
theme(plot.title = element_text(vjust = -5, hjust = 0.1)) +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_blank()) +
theme(legend.text=element_text(size=10)) +
theme(text=(element_text(size=10))) +
theme(axis.text=(element_text(size=5))) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(panel.background = element_blank()) +
theme(legend.key = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=0.25) +
#stat_cor(aes(color = scientific_name), label.x = 3)
theme(plot.margin=unit(c(0,1,0,0.2),"cm")) +
theme(legend.position ="top",
#legend.justification = c("right", "top"),
#legend.box.just = "right",
#scale_fill_manual(breaks=c(3)),
legend.margin = margin(2, 2, 2, 2),
#guides(color = FALSE), #,color = FALSE, size = FALSE,
legend.box.background = element_rect(fill='white'),
legend.background = element_blank(),
legend.key = element_rect(fill = NA, color = NA),
legend.spacing.x=unit(0, "cm"),
legend.spacing.y=unit(0, "cm"))
#Turn this on to output figures
#print(Fig1)
#dev.copy(pdf, output3)
#dev.off()
}
colnames(All_reads) <- (header)
write.table(All_reads, "Indexed/All_reads.csv", sep=",",  col.names=TRUE, row.names =FALSE)
#Here you can skip loop above and just read in the file
#All_reads <- read.csv("Indexed/All_reads.csv", header=TRUE) #If run before, script can be started here
#Count the occurrences of the wrong strain in the wrong population (False positives)
VGs <- subset.data.frame(All_reads, grepl('VG', All_reads$Strain))
VGs <- subset.data.frame(VGs, grepl('GP', VGs$Experiment))
VG_FP<- length(VGs$Population[VGs$Total_C > 0])
GPs <- subset.data.frame(All_reads, grepl('GP', All_reads$Strain))
GPs <- subset.data.frame(GPs, grepl('VG', GPs$Experiment))
GP_FP<- length(GPs$Population[GPs$Total_C > 0])
#The number of indisputable false positives is
VG_FP+GP_FP
#Summarize the results####
#header <- read.csv("Indexed/1_header.tmp", header = F)
#header <- t(header)
#colnames(All_reads) <- (header)
unique(All_reads$Experiment)
unique(All_reads$Treatment)
head(All_reads)
sapply(All_reads, class)
All_reads$Replicate <- as.character(as.integer(All_reads$Replicate))
unique(All_reads$Bottel)
#Out of
ncol(All_reads)
#Out of
nrow(All_reads)
View(All_reads)
#Out of
length(All_reads$Population[VGs$Total_C > 0])
#The number of indisputable false positives is
VG_FP+GP_FP
#Out of
TO <- length(All_reads$Population[VGs$Total_C > 0])
#FDR
T0/(VG_FP+GP_FP)
#Out of
T0 <- length(All_reads$Population[VGs$Total_C > 0])
#Out of
TO <- length(All_reads$Population[VGs$Total_C > 0])
#FDR
TO/(VG_FP+GP_FP)
#FDR
(VG_FP+GP_FP)/TO
#FDR is pretty high at 19%
((VG_FP+GP_FP)*2)/TO
#Lets see were FDRs are and how the data looks otherwise
All_reads$Replicate <- as.character(as.integer(All_reads$Replicate))
#Lets make a graph of only the MMs abundances.
MMsamples <- subset.data.frame(All_reads, grepl("0", All_reads$Timepoint))
MMsamples <- MMsamples[order(MMsamples$Strain),]
MMsamples$Relative_abundance[MMsamples$Relative_abundance == 0] <- NA
sapply(MMsamples, class)
AvaragesMM <- ddply(MMsamples, c("Experiment", "Strain", "allel"), summarise,
mean = mean(Relative_abundance), sd = sd(Relative_abundance))
#This way hard to make errorbars right.
Fig4 <- ggplot(AvaragesMM, stats = "identity", aes(Strain, fill = allel)) +
#ggplot(AvaragesMM, x = "Strain", y = "mean", add = "mean_sd", fill = aes(Strain, allel)) + #, fstats = "identity", aes(Strain,
geom_bar(data=AvaragesMM, aes(Strain, mean), position = "stack", stat = "identity") +
facet_grid(rows = vars(Experiment)) +
geom_hline(yintercept = 1/29) +
#geom_errorbar(aes(ymin = (mean-sd), ymax = (mean+sd), width=.4, color = Metal), position = position_dodge(0.1)) +
geom_errorbar(aes(ymin = (mean-sd), ymax = (mean+sd), width=0.2), stat = "identity") + #position = position_dodge(0.3
background_grid(major = "none", minor = "none") + # add thin horizontal lines
panel_border(colour = "black", size = 1) + # and a border around each panel
theme(plot.title = element_text(vjust = -5, hjust = 0.1)) +
scale_fill_manual(values = c("forestgreen", "darkolivegreen2", "chartreuse", "blue3", "dodgerblue2", "deepskyblue1", "darkorchid1", "grey")) +
labs (x="Strain", y="Fraction of amplicons") +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_blank()) +
theme(legend.text=element_text(size=10)) +
theme(text=(element_text(size=10))) +
theme(axis.text=(element_text(size=6))) +
theme(axis.text.y = element_text(angle = 0, hjust = 1, size=10)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, size=6)) +
theme(panel.background = element_blank()) +
theme(legend.key = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=0.25) +
theme(plot.margin=unit(c(0,1,0,0.2),"cm")) +
theme(strip.background = element_blank(),strip.text.x = element_blank()) +
theme(legend.position= c(0.83, 0.82),
#legend.box="horizontal",
#legend.justification = c("right", "top"),
#legend.box.just = "right",
#scale_fill_manual(breaks=c(3)),
legend.margin = margin(2, 2, 2, 2),
#guides(color = FALSE), #,color = FALSE, size = FALSE,
legend.box.background = element_rect(fill='white'),
legend.background = element_blank(),
legend.key = element_rect(fill = NA, color = NA),
legend.spacing.x=unit(0, "cm"),
legend.spacing.y=unit(0, "cm")) +
guides(fill=guide_legend(nrow=3,byrow=TRUE))
print(Fig4)
dev.copy(pdf, "Plots/Fig4.pdf")
dev.off()
Fig5 <- ggbarplot(MMsamples, x = "Strain", y = "Relative_abundance", add = "mean_sd", fill = "allel", size = 0,  facet.by = "Experiment") + #color=NA removes border but also error bars, ar
#geom_col(data=AvaragesMM, aes(Strain, mean)) +
#geom_bar(stat="identity",size=2) +
facet_grid(rows = vars(Experiment)) +
#coord_cartesian(ylim=c(0, 0.0029), expand = F) +
geom_hline(yintercept = 1/29) +
#geom_errorbar(aes(ymin = (mean-sd), ymax = (mean+sd), width=.4, color = Metal), position = position_dodge(0.1)) +
#geom_errorbar(aes(ymin = (mean-sd), ymax = (mean+sd), width=0.5)) + #position = position_dodge(0.3
background_grid(major = "none", minor = "none") + # add thin horizontal lines
panel_border(colour = "black", size = 1) + # and a border around each panel
theme(plot.title = element_text(vjust = -5, hjust = 0.1)) +
scale_fill_manual(values = c("forestgreen", "darkolivegreen2", "chartreuse", "blue3", "dodgerblue2", "deepskyblue1", "darkorchid1", "grey")) +
labs (x="Strain", y="Fraction of amplicons") +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_blank()) +
theme(legend.text=element_text(size=10)) +
theme(text=(element_text(size=10))) +
theme(axis.text=(element_text(size=6))) +
theme(axis.text.y = element_text(angle = 0, hjust = 1, size=10)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, size=6)) +
theme(panel.background = element_blank()) +
theme(legend.key = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=0.25) +
theme(plot.margin=unit(c(0,1,0,0.2),"cm")) +
theme(strip.background = element_blank(),strip.text.x = element_blank()) +
theme(legend.position= c(0.83, 0.82),
#legend.box="horizontal",
#legend.justification = c("right", "top"),
#legend.box.just = "right",
#scale_fill_manual(breaks=c(3)),
legend.margin = margin(2, 2, 2, 2),
#guides(color = FALSE), #,color = FALSE, size = FALSE,
legend.box.background = element_rect(fill='white'),
legend.background = element_blank(),
legend.key = element_rect(fill = NA, color = NA),
legend.spacing.x=unit(0, "cm"),
legend.spacing.y=unit(0, "cm")) +
guides(fill=guide_legend(nrow=3,byrow=TRUE))
print(Fig5)
dev.copy(pdf, "Plots/Fig5.pdf")
dev.off()
subset.data.frame(MMsamples, grepl("GP2-4_52", MMsamples$Strain))
Lets pick one strain at a time (Then Loop this)
df_uniq <- unique(All_reads$Strain)
colourCount = length(unique(mtcars$hp))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
df_uniq
#Lets make an Dataframe to save all ratios in
#AlleleRatios <- as.data.frame("x", header('ID', "Barcode1_RA", "Barcode2_RA", "AllelRatio"))
AlleleRatios <- data.frame(ID=character(),
Barcode1=character(),
Barcode1_RA=numeric(),
Total1=numeric(),
Barcode2=character(),
Barcode2_RA=numeric(),
Total2=numeric(),
AllelRatio=numeric(),
stringsAsFactors=FALSE)
#sapply(OneStrain, class)
quartz()
#THIS LOOP KEEPS FAILING DUE TO GGPLOT ERRORWarningsS (in last FigStrains part)
#Stop loop before plots to finish rest of script
#df_uniq
for (i in df_uniq) {
OneStrain <- subset.data.frame(All_reads, grepl(paste("\\b",i,"\\b", sep = ""), All_reads$Strain))
PIPT <- subset.data.frame(OneStrain, grepl(pattern = 'GP|VG', OneStrain$Experiment))
PIPT <- subset.data.frame(PIPT, grepl(pattern = 'GP|VG', PIPT$Population))
Strain2 <- subset.data.frame(OneStrain, grepl('Strain', OneStrain$Experiment))
output <- paste("Plots/Strains/",i,".pdf", sep="")
output2 <- paste("Plots/Strains/",i,"_Strains.pdf", sep="")
#Lets plot how the allel ratios vary with abundance. Should be no correlation and close to 1
OneStrain2 <- subset.data.frame(All_reads, grepl(paste("\\b",i,"\\b", sep = ""), All_reads$Strain))
Barcode1 <- subset.data.frame(OneStrain2, grepl("C12W1_1", OneStrain2$Barcode))
Barcode1 <- select(Barcode1, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
Barcode2 <- subset.data.frame(OneStrain2, grepl("C12W1_2", OneStrain2$Barcode))
Barcode2 <- select(Barcode2, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
OneStrain3 <- join(Barcode1, Barcode2, by = "ID")
colnames(OneStrain3) <- (c('ID', "Barcode1", "Barcode1_RA", "Total1", "Barcode2", "Barcode2_RA", "Total2"))
OneStrain3$AllelRatio <- OneStrain3$Barcode1_RA/OneStrain3$Barcode2_RA
OneStrain3$ReadSum <- OneStrain3$Total1+OneStrain3$Total2
?select
#append results here
AlleleRatios <- rbind(AlleleRatios, OneStrain3)
#End below here to generate data but avoid crash on figures
#}
#quartz()
suppressWarnings(FigStrains <- ggplot(Strain2, aes(Sample, Relative_abundance)) + #, message=FALSE
geom_point(mapping = aes(color = Barcode), size = 2, shape = 1) +
coord_cartesian(ylim=c(0.0001, 1), expand = F) + #ylim=c(-0, 12.5)
scale_y_log10(breaks = trans_breaks("log10", function(y) 10^y),
labels = trans_format("log10", math_format(10^.x))) + #change the scale on y axis
background_grid(major = "none", minor = "none") + # add thin horizontal lines
panel_border(colour = "black", size = 1) + # and a border around each panel
labs (x=("Strain Genotype sample"), y=("Relative abundance"), title = i) +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_text(size=12)) +
theme(legend.text=element_text(size=6)) +
theme(text=(element_text(size=10))) +
theme(axis.text=(element_text(size=6))) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(panel.background = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=0.25) +
theme(legend.position ="top"))
suppressWarnings(print(FigStrains))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output2))
suppressWarnings(dev.off())
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigRA <- ggplot(PIPT, aes(Timepoint, Relative_abundance), message=FALSE) +
geom_point(mapping = aes(shape = Barcode, color = Replicate), size = 2) +
facet_wrap(~Experiment + Treatment) +
theme(strip.text.x = element_text(size=12, angle=0, face = "italic"),
strip.background = element_rect(colour="white", fill="white")) +
geom_path(mapping = aes(color = Replicate, linetype = Barcode), size = 0.5) +
#scale_color_brewer(palette = "Paired") +
#geom_errorbar(aes(xmin = (Low), xmax = (High), width=.4), position = position_dodge(0)) +
#geom_vline(xintercept = 0.86, color="red") +
#geom_vline(xintercept = 8,6, color="red", linetype = "dashed") +
#scale_shape_manual(values=c(19, 0, 1, 2)) +
scale_color_manual(values = getPalette(colourCount)) +
#scale_color_brewer(values = getPalette(colourCount)) +
#geom_line(mapping = aes(t_SM ~ Ratio, color = Model_SM)) +
#scale_linetype_manual(values = 2) +
coord_cartesian(ylim=c(0.0001, 1), xlim=c(-1, 44), expand = F) + #ylim=c(-0, 12.5)
#scale_y_discrete(limits=c(0,-3,-6,-9,-12,-15,-18)) +
scale_y_log10(breaks = trans_breaks("log10", function(y) 10^y),
labels = trans_format("log10", math_format(10^.x))) + #change the scale on y axis
#annotation_logticks(sides = "b", size = 0.1) + # adds linier tickmarks
#theme(axis.text.x = element_text(angle = 45, hjust = 1)) + #adjust text tilt and possition
background_grid(major = "none", minor = "none") + # add thin horizontal lines
panel_border(colour = "black", size = 1) + # and a border around each panel
labs (x=("Time (days)"), y=("Relative abundance"), title = i) +
#theme(plot.title = element_text(vjust = - 13, hjust = 0.04)) +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_text(size=12)) +
theme(legend.text=element_text(size=6)) +
theme(text=(element_text(size=12))) +
theme(axis.text=(element_text(size=12))) +
theme(panel.background = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=1))
suppressWarnings(print(FigRA))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output))
suppressWarnings(dev.off())
#End here to also make figures (crashes the loop unpredictably for me)
}
#i <- "GP2-4_44"
for (i in df_uniq) {
OneStrain <- subset.data.frame(All_reads, grepl(paste("\\b",i,"\\b", sep = ""), All_reads$Strain))
PIPT <- subset.data.frame(OneStrain, grepl(pattern = 'GP|VG', OneStrain$Experiment))
PIPT <- subset.data.frame(PIPT, grepl(pattern = 'GP|VG', PIPT$Population))
Strain2 <- subset.data.frame(OneStrain, grepl('Strain', OneStrain$Experiment))
output <- paste("Plots/Strains/",i,".pdf", sep="")
output2 <- paste("Plots/Strains/",i,"_Strains.pdf", sep="")
#Lets plot how the allel ratios vary with abundance. Should be no correlation and close to 1
OneStrain2 <- subset.data.frame(All_reads, grepl(paste("\\b",i,"\\b", sep = ""), All_reads$Strain))
Barcode1 <- subset.data.frame(OneStrain2, grepl("C12W1_1", OneStrain2$Barcode))
Barcode1 <- select(Barcode1, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
Barcode2 <- subset.data.frame(OneStrain2, grepl("C12W1_2", OneStrain2$Barcode))
Barcode2 <- select(Barcode2, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
OneStrain3 <- join(Barcode1, Barcode2, by = "ID")
colnames(OneStrain3) <- (c('ID', "Barcode1", "Barcode1_RA", "Total1", "Barcode2", "Barcode2_RA", "Total2"))
OneStrain3$AllelRatio <- OneStrain3$Barcode1_RA/OneStrain3$Barcode2_RA
OneStrain3$ReadSum <- OneStrain3$Total1+OneStrain3$Total2
?select
#append results here
AlleleRatios <- rbind(AlleleRatios, OneStrain3)
#End below here to generate data but avoid crash on figures
#}
#quartz()
suppressWarnings(FigStrains <- ggplot(Strain2, aes(Sample, Relative_abundance)) + #, message=FALSE
geom_point(mapping = aes(color = Barcode), size = 2, shape = 1) +
coord_cartesian(ylim=c(0.0001, 1), expand = F) + #ylim=c(-0, 12.5)
scale_y_log10(breaks = trans_breaks("log10", function(y) 10^y),
labels = trans_format("log10", math_format(10^.x))) + #change the scale on y axis
background_grid(major = "none", minor = "none") + # add thin horizontal lines
panel_border(colour = "black", size = 1) + # and a border around each panel
labs (x=("Strain Genotype sample"), y=("Relative abundance"), title = i) +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_text(size=12)) +
theme(legend.text=element_text(size=6)) +
theme(text=(element_text(size=10))) +
theme(axis.text=(element_text(size=6))) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(panel.background = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=0.25) +
theme(legend.position ="top"))
suppressWarnings(print(FigStrains))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output2))
suppressWarnings(dev.off())
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigRA <- ggplot(PIPT, aes(Timepoint, Relative_abundance), message=FALSE) +
geom_point(mapping = aes(shape = Barcode, color = Replicate), size = 2) +
facet_wrap(~Experiment + Treatment) +
theme(strip.text.x = element_text(size=12, angle=0, face = "italic"),
strip.background = element_rect(colour="white", fill="white")) +
geom_path(mapping = aes(color = Replicate, linetype = Barcode), size = 0.5) +
#scale_color_brewer(palette = "Paired") +
#geom_errorbar(aes(xmin = (Low), xmax = (High), width=.4), position = position_dodge(0)) +
#geom_vline(xintercept = 0.86, color="red") +
#geom_vline(xintercept = 8,6, color="red", linetype = "dashed") +
#scale_shape_manual(values=c(19, 0, 1, 2)) +
scale_color_manual(values = getPalette(colourCount)) +
#scale_color_brewer(values = getPalette(colourCount)) +
#geom_line(mapping = aes(t_SM ~ Ratio, color = Model_SM)) +
#scale_linetype_manual(values = 2) +
coord_cartesian(ylim=c(0.0001, 1), xlim=c(-1, 44), expand = F) + #ylim=c(-0, 12.5)
#scale_y_discrete(limits=c(0,-3,-6,-9,-12,-15,-18)) +
scale_y_log10(breaks = trans_breaks("log10", function(y) 10^y),
labels = trans_format("log10", math_format(10^.x))) + #change the scale on y axis
#annotation_logticks(sides = "b", size = 0.1) + # adds linier tickmarks
#theme(axis.text.x = element_text(angle = 45, hjust = 1)) + #adjust text tilt and possition
background_grid(major = "none", minor = "none") + # add thin horizontal lines
panel_border(colour = "black", size = 1) + # and a border around each panel
labs (x=("Time (days)"), y=("Relative abundance"), title = i) +
#theme(plot.title = element_text(vjust = - 13, hjust = 0.04)) +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_text(size=12)) +
theme(legend.text=element_text(size=6)) +
theme(text=(element_text(size=12))) +
theme(axis.text=(element_text(size=12))) +
theme(panel.background = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=1))
suppressWarnings(print(FigRA))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output))
suppressWarnings(dev.off())
#End here to also make figures (crashes the loop unpredictably for me)
}
df_uniq <- unique(All_reads$Strain)
colourCount = length(unique(mtcars$hp))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
df_uniq
#Lets make an Dataframe to save all ratios in
#AlleleRatios <- as.data.frame("x", header('ID', "Barcode1_RA", "Barcode2_RA", "AllelRatio"))
AlleleRatios <- data.frame(ID=character(),
Barcode1=character(),
Barcode1_RA=numeric(),
Total1=numeric(),
Barcode2=character(),
Barcode2_RA=numeric(),
Total2=numeric(),
AllelRatio=numeric(),
stringsAsFactors=FALSE)
#sapply(OneStrain, class)
quartz()
#THIS LOOP KEEPS FAILING DUE TO GGPLOT ERRORWarningsS (in last FigStrains part)
#Stop loop before plots to finish rest of script
#df_uniq
#i <- "GP2-4_44"
for (i in df_uniq) {
OneStrain <- subset.data.frame(All_reads, grepl(paste("\\b",i,"\\b", sep = ""), All_reads$Strain))
PIPT <- subset.data.frame(OneStrain, grepl(pattern = 'GP|VG', OneStrain$Experiment))
PIPT <- subset.data.frame(PIPT, grepl(pattern = 'GP|VG', PIPT$Population))
Strain2 <- subset.data.frame(OneStrain, grepl('Strain', OneStrain$Experiment))
output <- paste("Plots/Strains/",i,".pdf", sep="")
output2 <- paste("Plots/Strains/",i,"_Strains.pdf", sep="")
#Lets plot how the allel ratios vary with abundance. Should be no correlation and close to 1
OneStrain2 <- subset.data.frame(All_reads, grepl(paste("\\b",i,"\\b", sep = ""), All_reads$Strain))
Barcode1 <- subset.data.frame(OneStrain2, grepl("C12W1_1", OneStrain2$Barcode))
Barcode1 <- select(Barcode1, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
Barcode2 <- subset.data.frame(OneStrain2, grepl("C12W1_2", OneStrain2$Barcode))
Barcode2 <- select(Barcode2, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
OneStrain3 <- join(Barcode1, Barcode2, by = "ID")
colnames(OneStrain3) <- (c('ID', "Barcode1", "Barcode1_RA", "Total1", "Barcode2", "Barcode2_RA", "Total2"))
OneStrain3$AllelRatio <- OneStrain3$Barcode1_RA/OneStrain3$Barcode2_RA
OneStrain3$ReadSum <- OneStrain3$Total1+OneStrain3$Total2
?select
#append results here
AlleleRatios <- rbind(AlleleRatios, OneStrain3)
#End below here to generate data but avoid crash on figures
#}
#quartz()
suppressWarnings(FigStrains <- ggplot(Strain2, aes(Sample, Relative_abundance)) + #, message=FALSE
geom_point(mapping = aes(color = Barcode), size = 2, shape = 1) +
coord_cartesian(ylim=c(0.0001, 1), expand = F) + #ylim=c(-0, 12.5)
scale_y_log10(breaks = trans_breaks("log10", function(y) 10^y),
labels = trans_format("log10", math_format(10^.x))) + #change the scale on y axis
background_grid(major = "none", minor = "none") + # add thin horizontal lines
panel_border(colour = "black", size = 1) + # and a border around each panel
labs (x=("Strain Genotype sample"), y=("Relative abundance"), title = i) +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_text(size=12)) +
theme(legend.text=element_text(size=6)) +
theme(text=(element_text(size=10))) +
theme(axis.text=(element_text(size=6))) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(panel.background = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=0.25) +
theme(legend.position ="top"))
suppressWarnings(print(FigStrains))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output2))
suppressWarnings(dev.off())
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigRA <- ggplot(PIPT, aes(Timepoint, Relative_abundance), message=FALSE) +
geom_point(mapping = aes(shape = Barcode, color = Replicate), size = 2) +
facet_wrap(~Experiment + Treatment) +
theme(strip.text.x = element_text(size=12, angle=0, face = "italic"),
strip.background = element_rect(colour="white", fill="white")) +
geom_path(mapping = aes(color = Replicate, linetype = Barcode), size = 0.5) +
#scale_color_brewer(palette = "Paired") +
#geom_errorbar(aes(xmin = (Low), xmax = (High), width=.4), position = position_dodge(0)) +
#geom_vline(xintercept = 0.86, color="red") +
#geom_vline(xintercept = 8,6, color="red", linetype = "dashed") +
#scale_shape_manual(values=c(19, 0, 1, 2)) +
scale_color_manual(values = getPalette(colourCount)) +
#scale_color_brewer(values = getPalette(colourCount)) +
#geom_line(mapping = aes(t_SM ~ Ratio, color = Model_SM)) +
#scale_linetype_manual(values = 2) +
coord_cartesian(ylim=c(0.0001, 1), xlim=c(-1, 44), expand = F) + #ylim=c(-0, 12.5)
#scale_y_discrete(limits=c(0,-3,-6,-9,-12,-15,-18)) +
scale_y_log10(breaks = trans_breaks("log10", function(y) 10^y),
labels = trans_format("log10", math_format(10^.x))) + #change the scale on y axis
#annotation_logticks(sides = "b", size = 0.1) + # adds linier tickmarks
#theme(axis.text.x = element_text(angle = 45, hjust = 1)) + #adjust text tilt and possition
background_grid(major = "none", minor = "none") + # add thin horizontal lines
panel_border(colour = "black", size = 1) + # and a border around each panel
labs (x=("Time (days)"), y=("Relative abundance"), title = i) +
#theme(plot.title = element_text(vjust = - 13, hjust = 0.04)) +
theme(panel.spacing = unit(0.1, "lines")) +
theme(legend.title=element_text(size=12)) +
theme(legend.text=element_text(size=6)) +
theme(text=(element_text(size=12))) +
theme(axis.text=(element_text(size=12))) +
theme(panel.background = element_blank()) +
theme(legend.text = element_text(face = "italic")) +
theme(aspect.ratio=1))
suppressWarnings(print(FigRA))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output))
suppressWarnings(dev.off())
#End here to also make figures (crashes the loop unpredictably for me)
}
i <- "GP2-4_44"
OneStrain <- subset.data.frame(All_reads, grepl(paste("\\b",i,"\\b", sep = ""), All_reads$Strain))
PIPT <- subset.data.frame(OneStrain, grepl(pattern = 'GP|VG', OneStrain$Experiment))
PIPT <- subset.data.frame(PIPT, grepl(pattern = 'GP|VG', PIPT$Population))
Strain2 <- subset.data.frame(OneStrain, grepl('Strain', OneStrain$Experiment))
output <- paste("Plots/Strains/",i,".pdf", sep="")
output2 <- paste("Plots/Strains/",i,"_Strains.pdf", sep="")
OneStrain2 <- subset.data.frame(All_reads, grepl(paste("\\b",i,"\\b", sep = ""), All_reads$Strain))
Barcode1 <- subset.data.frame(OneStrain2, grepl("C12W1_1", OneStrain2$Barcode))
Barcode1 <- select(Barcode1, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
Barcode2 <- subset.data.frame(OneStrain2, grepl("C12W1_2", OneStrain2$Barcode))
Barcode2 <- select(Barcode2, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
OneStrain3 <- join(Barcode1, Barcode2, by = "ID")
colnames(OneStrain3) <- (c('ID', "Barcode1", "Barcode1_RA", "Total1", "Barcode2", "Barcode2_RA", "Total2"))
OneStrain3$AllelRatio <- OneStrain3$Barcode1_RA/OneStrain3$Barcode2_RA
OneStrain3$ReadSum <- OneStrain3$Total1+OneStrain3$Total2
?select
Barcode1 <- select(Barcode1, c('ID',  "Barcode", "Relative_abundance", "Total_C"))
?select
