rm(list=ls())
setwd("~/AndreCollaborations/QueenExperimentBurnham")
Virus <- read.table("CompiledLoCalPCRdata.csv",
header=TRUE,
sep = ",",
stringsAsFactors = FALSE)
EcoDat <- read.table("EcoDat.csv",
header=TRUE,
sep = ",",
stringsAsFactors = FALSE)
OldPCR <- read.table("RNAVirus.csv",
header=TRUE,
sep = ",",
stringsAsFactors = FALSE)
PrelimClean <- function(data=MigVirus){
library(dplyr)
data <- select(data, Sample.Name, Target.Name, Cq.Mean, Cq.Standard.Deviation, Quantity.Mean, Quantity.Standard.Deviation, Run)
data<-data[!duplicated(data), ]
data<-data[!(data$Sample.Name=="No Sample"),]
data<-data[!(data$Sample.Name=="G-Block"),]
return(data)
}
VirusNorm <- function(number_bees = 50, data=data){
crude_extr <- 100
eluteRNA <- 50
GITCperbee <- 200
cDNA_eff <- 0.1
rxn_vol <- 3
total_extr_vol <- (GITCperbee * number_bees)
data$genomeCopy <- ((((((data$Quantity.Mean / cDNA_eff) / rxn_vol) * data$dil.factor) * eluteRNA) / crude_extr) * total_extr_vol) / number_bees
data$genomeCopy[is.na(data$genomeCopy)] <- 0
return(data)
}
actinNormal <- function(data=MigVirus){
ActinOnly <- data[which(data$Target.Name=="ACTIN"),]
ActinDF <- data.frame(ActinOnly$Sample.Name, ActinOnly$Run, ActinOnly$genomeCopy)
colnames(ActinDF) <- c("Sample.Name", "Run", "ACT_genomeCopy")
data <- merge(data, ActinDF, by=c("Sample.Name", "Run"), all.x=TRUE)
ActinMean <- mean(ActinOnly$genomeCopy, na.rm = TRUE)
data$NormGenomeCopy <- (data$genomeCopy/data$ACT_genomeCopy)*ActinMean
return(data)
}
CT_Threash <- function(data=data){
splitDF <- split(data, data$Target.Name)
splitDF$DWV$NormGenomeCopy[which(splitDF$DWV$Cq.Mean > 32.918)] <- 0
splitDF$BQCV$NormGenomeCopy[which(splitDF$BQCV$Cq.Mean > 32.525)] <- 0
splitDF$IAPV$NormGenomeCopy[which(splitDF$IAPV$Cq.Mean > 30.796)] <- 0
splitDF$DWV$virusBINY <- ifelse(splitDF$DWV$Cq.Mean > 32.918, 0, 1)
splitDF$BQCV$virusBINY <- ifelse(splitDF$BQCV$Cq.Mean > 32.525, 0, 1)
splitDF$IAPV$virusBINY <- ifelse(splitDF$IAPV$Cq.Mean > 30.796, 0, 1)
data <- rbind(splitDF$DWV, splitDF$BQCV, splitDF$IAPV)
data$virusBINY[is.na(data$virusBINY)] <- 0
return(data)
}
library(plyr)
library(ggplot2)
library(dplyr)
library(lme4)
library(car)
CleanVirus <- PrelimClean(data=Virus)
CleanVirus <- merge(CleanVirus, EcoDat, by="Sample.Name")
CleanVirus <- VirusNorm(data=CleanVirus, number_bees = 50)
CleanVirus <- actinNormal(data=CleanVirus)
CleanVirus <- CleanVirus[!(CleanVirus$Target.Name=="ACTIN"),]
CleanVirus <- CT_Threash(data=CleanVirus)
OldPCR <- select(OldPCR, ID, Target.Name, Time, Band_Intensity)
CleanVirus <- merge(CleanVirus, OldPCR, by=c("ID", "Target.Name", "Time"))
CleanVirus$logVirus <- log(CleanVirus$NormGenomeCopy + 1)
VirusSummary <- ddply(CleanVirus, c("Origin", "Target.Name", "Time"), summarise,
n = length(logVirus),
mean = mean(logVirus, na.rm = TRUE),
sd = sd(logVirus, na.rm = TRUE),
se = sd / sqrt(n))
splitVir <- split(VirusSummary, VirusSummary$Target.Name)
colors <- c("white", "gray32")
p1 <- ggplot(splitVir$DWV, aes(x=Time, y=mean, fill=Origin)) +
geom_bar(stat="identity", col="black",
position=position_dodge()) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=.4,
position=position_dodge(.9)) + labs(x="DWV", y = "Viral Load log(genome copies/bee)") + theme_classic(base_size = 17) + coord_cartesian(ylim = c(0, 25)) + scale_fill_manual(values=colors, name="Queen Origin", labels=c("California", "Local")) + theme(legend.position=c(.5, .9), panel.border = element_blank(),axis.line.y = element_line(colour = 'black', size=0.5, linetype='solid'), panel.grid.major = element_blank(), panel.grid.minor = element_blank())
p2 <- ggplot(splitVir$BQCV, aes(x=Time, y=mean, fill=Origin)) +
geom_bar(stat="identity", col="black",
position=position_dodge()) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=.4,
position=position_dodge(.9)) + labs(x="BQCV", y = NULL) + theme_classic(base_size = 17) + coord_cartesian(ylim = c(0, 25)) + scale_fill_manual(values=colors, name="Queen Origin", labels=c("California", "Local")) + theme(legend.position=c(3, 3), axis.text.y=element_blank(), axis.ticks.y=element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line.y = element_blank())
p3 <- ggplot(splitVir$IAPV, aes(x=Time, y=mean, fill=Origin)) +
geom_bar(stat="identity", col="black",
position=position_dodge()) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=.4,
position=position_dodge(.9)) + labs(x="IAPV", y = NULL) + theme_classic(base_size = 17) + coord_cartesian(ylim = c(0, 25)) + scale_fill_manual(values=colors, name="Queen Origin", labels=c("California", "Local")) + theme(legend.position=c(3, 3),axis.text.y=element_blank(),axis.ticks.y=element_blank(), axis.line.y = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank())
grid.newpage()
grid.draw(cbind(ggplotGrob(p1), ggplotGrob(p2), ggplotGrob(p3), size = "last"))
splitDat <- split(CleanVirus, CleanVirus$Target.Name)
aov.out <- aov(logVirus ~ Origin * Time + Error(ID), data=splitDat$IAPV)
summary(aov.out)
VirusSummary <- ddply(CleanVirus, c("Origin", "Target.Name", "Time"), summarise,
n = length(virusBINY),
mean = mean(virusBINY, na.rm = TRUE),
sd = sd(virusBINY, na.rm = TRUE),
se = sd / sqrt(n))
splitVir <- split(VirusSummary, VirusSummary$Target.Name)
colors <- c("white", "gray32")
p1 <- ggplot(splitVir$DWV, aes(x=Time, y=mean, fill=Origin)) +
geom_bar(stat="identity", col="black",
position=position_dodge()) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=.4,
position=position_dodge(.9)) + labs(x="DWV", y = "Virus Prevalence") + theme_classic(base_size = 17) + coord_cartesian(ylim = c(0, 1)) + scale_fill_manual(values=colors, name="Queen Origin", labels=c("California", "Local")) + theme(legend.position=c(3,3), panel.border = element_blank(),axis.line.y = element_line(colour = 'black', size=0.5, linetype='solid'), panel.grid.major = element_blank(), panel.grid.minor = element_blank())
p2 <- ggplot(splitVir$BQCV, aes(x=Time, y=mean, fill=Origin)) +
geom_bar(stat="identity", col="black",
position=position_dodge()) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=.4,
position=position_dodge(.9)) + labs(x="BQCV", y = NULL) + theme_classic(base_size = 17) + coord_cartesian(ylim = c(0, 1)) + scale_fill_manual(values=colors, name="Queen Origin", labels=c("California", "Local")) + theme(legend.position=c(3, 3), axis.text.y=element_blank(), axis.ticks.y=element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line.y = element_blank())
p3 <- ggplot(splitVir$IAPV, aes(x=Time, y=mean, fill=Origin)) +
geom_bar(stat="identity", col="black",
position=position_dodge()) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=.4,
position=position_dodge(.9)) + labs(x="IAPV", y = NULL) + theme_classic(base_size = 17) + coord_cartesian(ylim = c(0, 1)) + scale_fill_manual(values=colors, name="Queen Origin", labels=c("California", "Local")) + theme(legend.position=c(.5, .9),axis.text.y=element_blank(),axis.ticks.y=element_blank(), axis.line.y = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank())
grid.newpage()
grid.draw(cbind(ggplotGrob(p1), ggplotGrob(p2), ggplotGrob(p3), size = "last"))
CleanVirus$Band_Intensity
```