symm=F,symkey=T,symbreaks=F)
MM_all <- subset.data.frame(High_RA_means, grepl(pattern = '\\b[0-9]\\b', High_RA_means$ID))
Indexed_MM_all <- data.frame(ID=character(),
Index=character(),
Total=numeric(),
stringsAsFactors=FALSE)
#Lets change structure so we can index samples and plot them.
for (i in InputFiles) {
Name <- gsub(".tsv", "", i)
N <- nrow(MM_all)
ID <- rep(Name, each = N)
Index <- MM_all$"ID"
Total <- MM_all[grep(Name, names(MM_all))]
colnames(Total) <- c("Total")
Column <- cbind.data.frame(ID, Index, Total)
Indexed_MM_all <- rbind(Indexed_MM_all, Column)
}
Indexing <- read.delim("../Indexing.txt", header=TRUE)
Indexed_MM_all2 <- join(Indexed_MM_all, Indexing, by = "ID")
#Lets plot them
df_uniq <- unique(Indexed_MM_all2$Index)
colourCount = length(unique(Indexed_MM_all2$Replicates))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
df_uniq
Indexed_MM_all2$Replicate <- as.character(as.integer(Indexed_MM_all2$Replicate))
#i <- "6"
for (i in df_uniq) {
OneAmplicon <- subset.data.frame(Indexed_MM_all2, grepl(paste("\\b",i,"\\b", sep = ""), Indexed_MM_all2$Index))
StrainAmplicon <- subset.data.frame(OneAmplicon, grepl('Strain', OneAmplicon$Experiment))
ExperimentAmplicon <- subset.data.frame(OneAmplicon, grepl(pattern = 'GP|VG', OneAmplicon$Experiment))
output <- paste("Plots/HighAbundance/",i,".pdf", sep="")
output2 <- paste("Plots/HighAbundance/",i,"_Strains.pdf", sep="")
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigTotal <- ggplot(ExperimentAmplicon, aes(Timepoint, Total), message=FALSE) +
geom_point(mapping = aes(color = Replicate), size = 2, shape = 1) + #shape = Barcode,
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), 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_manual(values = c("firebrick", "orange", "gold", "blue", "cyan", "magenta")) +
#scale_color_brewer(values = getPalette(colourCount)) +
#geom_line(mapping = aes(t_SM ~ Ratio, color = Model_SM)) +
#scale_linetype_manual(values = 2) +
coord_cartesian(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=("Counts"), 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(FigTotal))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output))
suppressWarnings(dev.off())
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigStrains <- ggplot(StrainAmplicon, aes(Sample, Total)) + #, message=FALSE
geom_point(mapping = aes(), size = 2, shape = 1) +
coord_cartesian(xlim = c(), 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=("Counts"), 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())
}
#Lets make a heatmapp
V <- as.vector(MM_all$ID)
MM_allM <- subset(MM_all, select = -c(Unknown.barcode, Sum, ID))
#Reformat to Matrix
MatrixAll2 <- as.matrix(MM_allM)
class(MatrixAll2) <-"numeric"
#MatrixAll2 <- MatrixAll2[,-1]
row.names(MatrixAll2)=V
MatrixAll2 <- t(MatrixAll2)
#Lets change INDEX of samples
INDEX = as.data.frame(rownames(MatrixAll2))
colnames(INDEX) <- c("ID")
V <- join(INDEX, Indexing)
V <- as.vector(V$Sample)
row.names(MatrixAll2)=V
MatrixAll2_log <- log10(MatrixAll2+1)
#Make a heatmap without clustering
quartz()
colRamp <- colorRampPalette(c("white", "red", "black", "green"), space="rgb")(64)
heatmap(MatrixAll2, col = colRamp, Rowv = NA, Colv = NA, cexRow=0.2, cexCol=0.2, na.rm = TRUE, distfun = dist)
dev.copy(pdf, "Plots/MM_Heat_raw.pdf")
dev.off()
MatrixAll2_cF <- scale(MatrixAll2, scale = T, center = F) #center = F, scale = T)
MatrixAll2_cT <- scale(MatrixAll2, scale = T, center = T) #center = T, scale = T)
#Change NAs to 0 for clustering
MatrixAll2_cT[is.na(MatrixAll2_cT)] <- 0
MatrixAll2_cF[is.na(MatrixAll2_cF)] <- 0
MatrixAll2[is.na(MatrixAll2)] <- 0
MatrixAll2_log[is.na(MatrixAll2_log)] <- 0
#2#Apply clustering (Eucladian distances)
quartz()
heatmap.2(MatrixAll2_cF, col = colRamp, scale="none", revC = T, margins = c(8,6),
xlab = "UnknowAmplicon_ID", ylab = "Sample", trace="none", cexRow=0.2, cexCol=1,
symm=F,symkey=T,symbreaks=F)
dev.copy(pdf, "Plots/MM_Heat_cF.pdf")
dev.off()
heatmap.2(MatrixAll2, col = colRamp, scale="none", revC = T, margins = c(8,6),
xlab = "UnknowAmplicon", ylab = "Sample", trace="none", cexRow=0.2, cexCol=1,
symm=F,symkey=T,symbreaks=F)
dev.copy(pdf, "Plots/MM_Heat_Raw2.pdf")
dev.off()
Allel_count_GP
plot(GP_MMall2$mean~GP_MMall2$CV, log="xy")
abline(h=20, col="green")
log="xy"
scale_y_log10()
dev.copy(pdf, "Plots/GP_Unknows_plot.pdf")
dev.off()
Unknowns2 <- unknowns %>% filter(mean > 10)
#Are they all uniqe?
#No 25 overlapp
nrow(unknowns)
df_uniq <- unique(unknowns$Unknown.barcode)
length(df_uniq)
nrow(Unknowns2)
df_uniq <- unique(Unknowns2$Unknown.barcode)
length(df_uniq)
write.table(Unknowns2, "Results/unknow_allels.txt", sep='\t',  col.names=TRUE, row.names =FALSE)
High_RA <- data.frame(Unknowns2$Unknown.barcode)
colnames(High_RA) <- c("Unknown.barcode")
#i <- "P21502_109.tsv"
#This takes about 20 min to run, OPTIONAL to skip and READ in file below.
for (i in InputFiles) {
#Import data (too be looped)
input=paste("Input/",i,"", sep="")
myData <- read.table(file = input, sep = '\t', header = TRUE)
ID <- gsub(".tsv", "", i)
colnames(myData) <- c(ID, "Unknown.barcode")
#Normalization to RA
Nreads <- sum(myData[,1])
myData[,1] <- (myData[,1]/Nreads)
High_RA <- join(High_RA, myData, by = "Unknown.barcode", type = "full")
}
#Write out the results.
write.table(High_RA, "Results/Summary_all_unknow_allels_RA.txt", sep='\t',  col.names=TRUE, row.names =FALSE)
High_RA2 <- High_RA
View(High_RA)
#Lets add up the RA to get a sense of which amplicons are present at high concentrations in multiple samples
High_RA_means <- High_RA2 %>%
mutate(ID = row_number()) %>%
group_by(ID) %>%
do(data.frame(., Sum = sum(unlist(.[c(2:102)]), na.rm=T)))
#Maybe counting the number of observations is a better filter? (it is not)
#High_RA_means <- High_RA_means %>%
# mutate(ID) %>%
#group_by(ID) %>%
#do(data.frame(., N = sum(!is.na(.[c(2:107)]), na.rm=T)))
#GP_MMall_allels <- subset.data.frame(GP_MMall_allels, grepl("GP", GP_MMall_allels$Strain))
#Allel_count_GP <- mean(GP_MMall_allels$Total)
#So we have quite a few amplicons showing up at >100 observations, fewer over 500, and max 5000.
hist(High_RA_means$Sum, xlim=c(0,0.4), ylim = c(0,100), breaks=80, main="Sum RA unknown")
dev.copy(pdf, "Plots/All_unknowns_total_observations.pdf")
dev.off()
#Lets remove everything below 100 (or simillar number for the RA, this get abput 50% reads overrepresented in MM, which is good)
High_RA_means100 <- High_RA_means %>% filter(Sum > 0.025)
High_RA_means500 <- High_RA_means %>% filter(Sum > 0.1)
High_RA_means_less100 <- High_RA_means %>% filter(Sum < 100)
#hahah ca. 175,000 amplicons are only seen once (only works on raw reads)
hist(High_RA_means_less100$Sum, xlim=c(0,1), breaks=100, main="Sum low abundance unknown")
#dev.copy(pdf, "Plots/All_unknowns_less100observations.pdf")
#dev.off()
#903 amplicons seen more t
#Now lets focus in the >500 group. Where are these reads?
#How many observations do we have?
High_RA_means500 <- High_RA_means500 %>%
mutate(ID) %>%
group_by(ID) %>%
do(data.frame(., N = sum(!is.na(.[c(2:102)]), na.rm=T)))
#Lets index the samples
#IDs <- unique(High_RA_means500$ID)
#IDs <- as.character(as.integer(IDs))
Indexed500 <- data.frame(ID=character(),
Index=character(),
Total=numeric(),
stringsAsFactors=FALSE)
#Lets change structure so we can index samples and plot them.
for (i in InputFiles) {
Name <- gsub(".tsv", "", i)
N <- nrow(High_RA_means500)
ID <- rep(Name, each = N)
Index <- High_RA_means500$"ID"
Total <- High_RA_means500[grep(Name, names(High_RA_means500))]
colnames(Total) <- c("Total")
Column <- cbind.data.frame(ID, Index, Total)
Indexed500 <- rbind(Indexed500, Column)
}
Indexing <- read.delim("../Indexing.txt", header=TRUE)
Indexed500_2 <- join(Indexed500, Indexing, by = "ID")
#Lets plot them
df_uniq <- unique(Indexed500_2$Index)
colourCount = length(unique(Indexed500_2$Replicates))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
df_uniq
Indexed500_2$Replicate <- as.character(as.integer(Indexed500_2$Replicate))
#i <- "6"
for (i in df_uniq) {
OneAmplicon <- subset.data.frame(Indexed500_2, grepl(paste("\\b",i,"\\b", sep = ""), Indexed500_2$Index))
StrainAmplicon <- subset.data.frame(OneAmplicon, grepl('Strain', OneAmplicon$Experiment))
ExperimentAmplicon <- subset.data.frame(OneAmplicon, grepl(pattern = 'GP|VG', OneAmplicon$Experiment))
output <- paste("Plots/HighAbundance/",i,".pdf", sep="")
output2 <- paste("Plots/HighAbundance/",i,"_Strains.pdf", sep="")
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigTotal <- ggplot(ExperimentAmplicon, aes(Timepoint, Total), message=FALSE) +
geom_point(mapping = aes(color = Replicate), size = 2, shape = 1) + #shape = Barcode,
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), 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_manual(values = c("firebrick", "orange", "gold", "blue", "cyan", "magenta")) +
#scale_color_brewer(values = getPalette(colourCount)) +
#geom_line(mapping = aes(t_SM ~ Ratio, color = Model_SM)) +
#scale_linetype_manual(values = 2) +
coord_cartesian(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=("Counts"), 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(FigTotal))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output))
suppressWarnings(dev.off())
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigStrains <- ggplot(StrainAmplicon, aes(Sample, Total)) + #, message=FALSE
geom_point(mapping = aes(), size = 2, shape = 1) +
coord_cartesian(xlim = c(), 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=("Counts"), 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())
}
#Lets make a heatmap
V <- as.vector(High_RA_means500$ID)
High_RA_means500M <- subset(High_RA_means500, select = -c(Unknown.barcode, Sum, ID, N))
#Reformat to Matrix
MatrixAll2 <- as.matrix(High_RA_means500M)
class(MatrixAll2) <-"numeric"
#MatrixAll2 <- MatrixAll2[,-1]
row.names(MatrixAll2)=V
MatrixAll2 <- t(MatrixAll2)
#Lets change INDEX of samples
INDEX = as.data.frame(rownames(MatrixAll2))
colnames(INDEX) <- c("ID")
V <- join(INDEX, Indexing)
V <- as.vector(V$Sample)
row.names(MatrixAll2)=V
#Logtransform matrix
MatrixAll2_log <- log10(MatrixAll2+1)
#Make a heatmap without clustering
quartz()
colRamp <- colorRampPalette(c("white", "red", "black", "green"), space="rgb")(64)
heatmap(MatrixAll2, col = colRamp, Rowv = NA, Colv = NA, cexRow=0.2, cexCol=0.2, na.rm = TRUE, distfun = dist)
dev.copy(pdf, "Plots/UnknownHeat_raw.pdf")
dev.off()
MatrixAll2_cF <- scale(MatrixAll2, scale = T, center = F) #center = F, scale = T)
MatrixAll2_cT <- scale(MatrixAll2, scale = T, center = T) #center = T, scale = T)
#Change NAs to 0 for clustering
MatrixAll2_cT[is.na(MatrixAll2_cT)] <- 0
MatrixAll2_cF[is.na(MatrixAll2_cF)] <- 0
MatrixAll2[is.na(MatrixAll2)] <- 0
MatrixAll2_log[is.na(MatrixAll2_log)] <- 0
#2#Apply clustering (Eucladian distances)
quartz()
heatmap.2(MatrixAll2_cF, col = colRamp, scale="none", revC = T, margins = c(8,6),
xlab = "UnknowAmplicon_ID", ylab = "Sample", trace="none", cexRow=0.2, cexCol=0.1,
symm=F,symkey=T,symbreaks=F)
dev.copy(pdf, "Plots/UnknownHeat_cF.pdf")
dev.off()
heatmap.2(MatrixAll2, col = colRamp, scale="none", revC = T, margins = c(8,6),
xlab = "UnknowAmplicon", ylab = "Sample", trace="none", cexRow=0.2, cexCol=0.1,
symm=F,symkey=T,symbreaks=F)
dev.copy(pdf, "Plots/UnknownHeat_Raw2.pdf")
dev.off()
#By looking them over i think most are artefacts associate with one strain, here are the once that are not:
Real <- c("6", "9", "10", "11", "62", "63")
Real <- subset.data.frame(High_RA_means500, grepl(pattern = '\\b6\\b|\\b9\\b|\\b10\\b|\\b11\\b|\\b62\\b|\\b63\\b', High_RA_means500$ID))
Real
#SEARCH for  a sequence####
DNA <- "CCTCAAACCCCATCGAATACAAACTCTCCATATGCATCAAAAGCTGTGCCGCCTTATCACTCGCCCCCTTTTCCAATGAATTGGCATAGGCATTAATAATCGCACCAAATGTCAATGCGTCGGGTAGTAAATCATCATCCCCCTCATTGTACAGACGGCCCATTTCATCTAGTAAAAACTTGGCACGATCGGCGCAATTCTTGTCACGGGAACGTGCTACTGCGTTGATTACCGCGTTGAAGGATCGTGCATCGGGTTTGCAGTTTATGTCTAGTCCACTATCGTTATTGTAAAAGTCGTACATGTTACGGAGCAATTCTTCTGCTTTACGTGCCGATCCTCGTTCATTGCTACGTGCCCATGCCGTGATGACGGAGTTGTAACTAATTTTGTTTGGTTTGACATGATCCCATTTTCCATCGATATTATGTTTGGGAGAGGAGTAGAGGTGCAGCATTTGATCGAGGAGGGCTTGTGCGTGCTTTGCGGAATCTTTGCGTGTGCATCGTGCC"
DNApresenet <- subset.data.frame(High_RA_means100, grepl(print(DNA), High_RA_means100$Unknown.barcode))
DNApresenet
#Adapth the plots to the abundant Mastermix samples instead####
MM_all <- subset.data.frame(High_RA_means, grepl(pattern = '\\b1[0-1][0-9]\\b|\\b[0-9][0-9]\\b|\\b[0-9]\\b', High_RA_means$ID))
#Adapth the plots to the abundant Mastermix samples instead####
MM_all <- subset.data.frame(High_RA_means, grepl(pattern = '\\b[8-9][0-3]\\b|\\b[0-8][0-9]\\b|\\b[0-9]\\b', High_RA_means$ID))
Indexed_MM_all <- data.frame(ID=character(),
Index=character(),
Total=numeric(),
stringsAsFactors=FALSE)
#Lets change structure so we can index samples and plot them.
for (i in InputFiles) {
Name <- gsub(".tsv", "", i)
N <- nrow(MM_all)
ID <- rep(Name, each = N)
Index <- MM_all$"ID"
Total <- MM_all[grep(Name, names(MM_all))]
colnames(Total) <- c("Total")
Column <- cbind.data.frame(ID, Index, Total)
Indexed_MM_all <- rbind(Indexed_MM_all, Column)
}
Indexing <- read.delim("../Indexing.txt", header=TRUE)
Indexed_MM_all2 <- join(Indexed_MM_all, Indexing, by = "ID")
#Lets plot them
df_uniq <- unique(Indexed_MM_all2$Index)
colourCount = length(unique(Indexed_MM_all2$Replicates))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
df_uniq
Indexed_MM_all2$Replicate <- as.character(as.integer(Indexed_MM_all2$Replicate))
#i <- "6"
for (i in df_uniq) {
OneAmplicon <- subset.data.frame(Indexed_MM_all2, grepl(paste("\\b",i,"\\b", sep = ""), Indexed_MM_all2$Index))
StrainAmplicon <- subset.data.frame(OneAmplicon, grepl('Strain', OneAmplicon$Experiment))
ExperimentAmplicon <- subset.data.frame(OneAmplicon, grepl(pattern = 'GP|VG', OneAmplicon$Experiment))
output <- paste("Plots/HighAbundance/",i,".pdf", sep="")
output2 <- paste("Plots/HighAbundance/",i,"_Strains.pdf", sep="")
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigTotal <- ggplot(ExperimentAmplicon, aes(Timepoint, Total), message=FALSE) +
geom_point(mapping = aes(color = Replicate), size = 2, shape = 1) + #shape = Barcode,
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), 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_manual(values = c("firebrick", "orange", "gold", "blue", "cyan", "magenta")) +
#scale_color_brewer(values = getPalette(colourCount)) +
#geom_line(mapping = aes(t_SM ~ Ratio, color = Model_SM)) +
#scale_linetype_manual(values = 2) +
coord_cartesian(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=("Counts"), 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(FigTotal))
#Sys.sleep(1)
suppressWarnings(dev.copy(pdf, output))
suppressWarnings(dev.off())
#This needs to be here for some annoying reason, loop terminates otherwise
#quartz()
suppressWarnings(FigStrains <- ggplot(StrainAmplicon, aes(Sample, Total)) + #, message=FALSE
geom_point(mapping = aes(), size = 2, shape = 1) +
coord_cartesian(xlim = c(), 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=("Counts"), 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())
}
#Lets make a heatmapp
V <- as.vector(MM_all$ID)
MM_allM <- subset(MM_all, select = -c(Unknown.barcode, Sum, ID))
#Reformat to Matrix
MatrixAll2 <- as.matrix(MM_allM)
class(MatrixAll2) <-"numeric"
#MatrixAll2 <- MatrixAll2[,-1]
row.names(MatrixAll2)=V
MatrixAll2 <- t(MatrixAll2)
#Lets change INDEX of samples
INDEX = as.data.frame(rownames(MatrixAll2))
colnames(INDEX) <- c("ID")
V <- join(INDEX, Indexing)
V <- as.vector(V$Sample)
row.names(MatrixAll2)=V
MatrixAll2_log <- log10(MatrixAll2+1)
#Make a heatmap without clustering
quartz()
colRamp <- colorRampPalette(c("white", "red", "black", "green"), space="rgb")(64)
heatmap(MatrixAll2, col = colRamp, Rowv = NA, Colv = NA, cexRow=0.2, cexCol=0.2, na.rm = TRUE, distfun = dist)
dev.copy(pdf, "Plots/MM_Heat_raw.pdf")
dev.off()
MatrixAll2_cF <- scale(MatrixAll2, scale = T, center = F) #center = F, scale = T)
MatrixAll2_cT <- scale(MatrixAll2, scale = T, center = T) #center = T, scale = T)
#Change NAs to 0 for clustering
MatrixAll2_cT[is.na(MatrixAll2_cT)] <- 0
MatrixAll2_cF[is.na(MatrixAll2_cF)] <- 0
MatrixAll2[is.na(MatrixAll2)] <- 0
MatrixAll2_log[is.na(MatrixAll2_log)] <- 0
#2#Apply clustering (Eucladian distances)
quartz()
heatmap.2(MatrixAll2_cF, col = colRamp, scale="none", revC = T, margins = c(8,6),
xlab = "UnknowAmplicon_ID", ylab = "Sample", trace="none", cexRow=0.2, cexCol=1,
symm=F,symkey=T,symbreaks=F)
dev.copy(pdf, "Plots/MM_Heat_cF.pdf")
dev.off()
heatmap.2(MatrixAll2, col = colRamp, scale="none", revC = T, margins = c(8,6),
xlab = "UnknowAmplicon", ylab = "Sample", trace="none", cexRow=0.2, cexCol=1,
symm=F,symkey=T,symbreaks=F)
dev.copy(pdf, "Plots/MM_Heat_Raw2.pdf")
dev.off()
write.table(MM_all, "Results/unknow_allels_MM.txt", sep='\t',  col.names=TRUE, row.names =FALSE)
#amplicon artefacts of VG90
#109, 113, 160, 155, 171, 149, 157, 110, 156, 166, 91, 105, 154, 98, 153, 78, 82, 92, 76, 130, 67
#2#Apply clustering (Eucladian distances)
quartz()
heatmap.2(MatrixAll2_cF, col = colRamp, scale="none", revC = T, margins = c(8,6),
xlab = "UnknowAmplicon_ID", ylab = "Sample", trace="none", cexRow=0.2, cexCol=0.2,
symm=F,symkey=T,symbreaks=F)
dev.copy(pdf, "Plots/MM_Heat_cF.pdf")
dev.off()
heatmap.2(MatrixAll2, col = colRamp, scale="none", revC = T, margins = c(8,6),
xlab = "UnknowAmplicon", ylab = "Sample", trace="none", cexRow=0.2, cexCol=0.2,
symm=F,symkey=T,symbreaks=F)
dev.copy(pdf, "Plots/MM_Heat_Raw2.pdf")
dev.off()
write.table(MM_all, "Results/unknow_allels_MM.txt", sep='\t',  col.names=TRUE, row.names =FALSE)
write.table(Unknowns2, "Results/unknow_allels.txt", sep='\t',  col.names=TRUE, row.names =FALSE)
View(High_RA_means500)
write.table(High_RA_means500, "Results/unknow_allels_AbuntantAllS.txt", sep='\t',  col.names=TRUE, row.names =FALSE)
