Working_directory ="T:\\TimelapseData\\201029GA14" setwd(Working_directory) data = read.table("allquant.csv",header=TRUE, row.names=NULL, sep=";") data$SumCh02 = ifelse(data$SumCh02 <=0, 0.00000001, data$SumCh02) data$MeanCh02 = data$SumCh02/data$Area data$MeanCh03 = data$SumCh03/data$Area data$SumCh02_log = log10(data$SumCh02) data$SumCh03_log = log10(data$SumCh03) data$MeanCh02_log = log10(data$MeanCh02) data$MeanCh03_log = log10(data$MeanCh03) data$Mash1_log = log10(data$SumCh02) data$mCherry_log = log10(data$SumCh03) data$Mash1 = data$SumCh02 data$mCherry = data$SumCh03 data$PositionComment = as.character(data$PositionComment) temp = strsplit(data$PositionComment,split = " ") data$Comment = sapply(temp,"[[",1) Mash1IRESDsRed_pos = c("B2","B4","B6", "B10","F2","F6","F10") pMash1IRESDsRed_pos = c("B3","B5","B7", "B11","F3","F7","F11") NoVirus_pos = c("C4") data$Virus = NA data[data$Comment %in% Mash1IRESDsRed_pos,]$Virus = "Mash1IRESDsRed" data[data$Comment %in% pMash1IRESDsRed_pos,]$Virus = "pMash1IRESDsRed" data[data$Comment %in% Novirus_pos,]$Virus ="No Virus" data$StimCond = NA Teststim_1 = c("B2","B3","C2","C3") Teststim_2 = c("B6","B7","C6","C7") No_light = c("B4","B5","C4","C5","F4","F5","G4","G5") Teststim_3 = c("B10","B11","C10","C11") Teststim_4 = c("F2","F3","G2","G3") Teststim_5 = c("F6","G6","F7","G7") Teststim_6 = c("F10","F11","G10","G11") ##### 6 hr on means "1 min on 15 min off" within that 6 hr duration data[data$Comment %in% Teststim_1,]$StimCond = "3d on" data[data$Comment %in% Teststim_2,]$StimCond = "6 hr on 12 hr off" data[data$Comment %in% No_light,]$StimCond = "No light" data[data$Comment %in% Teststim_3,]$StimCond = "12 hr on 12 hr off" data[data$Comment %in% Teststim_4,]$StimCond = "24hr on" data[data$Comment %in% Teststim_5,]$StimCond = "12 hr on" data[data$Comment %in% Teststim_6,]$StimCond = "6hr on" data$StimCond = factor(data$StimCond) temp_Mash1_TP1 = median(data[data$Comment %in% No_light & data$Comment %in% Mash1IRESDsRed_pos & data$TimePoint %in% c("1"),]$Mash1) temp_pMash1_TP1 = median(data[data$Comment %in% No_light & data$Comment %in% pMash1IRESDsRed_pos & data$TimePoint %in% c("1"),]$Mash1) temp_Mash1_TP2 = median(data[data$Comment %in% No_light & data$Comment %in% Mash1IRESDsRed_pos & data$TimePoint %in% c("2"),]$Mash1) temp_pMash1_TP2 = median(data[data$Comment %in% No_light & data$Comment %in% pMash1IRESDsRed_pos & data$TimePoint %in% c("2"),]$Mash1) data$Mash1_norm = NA data[data$TimePoint %in% c("1") & data$Comment %in% Mash1IRESDsRed_pos,]$Mash1_norm = data[data$TimePoint %in% c("1") & data$Comment %in% Mash1IRESDsRed_pos,]$Mash1/temp_Mash1_TP1 data[data$TimePoint %in% c("1") & data$Comment %in% pMash1IRESDsRed_pos,]$Mash1_norm = data[data$TimePoint %in% c("1") & data$Comment %in% pMash1IRESDsRed_pos,]$Mash1/temp_pMash1_TP1 data[data$TimePoint %in% c("2") & data$Comment %in% Mash1IRESDsRed_pos,]$Mash1_norm = data[data$TimePoint %in% c("2") & data$Comment %in% Mash1IRESDsRed_pos,]$Mash1/temp_Mash1_TP2 data[data$TimePoint %in% c("2") & data$Comment %in% pMash1IRESDsRed_pos,]$Mash1_norm = data[data$TimePoint %in% c("2") & data$Comment %in% pMash1IRESDsRed_pos,]$Mash1/temp_pMash1_TP2 data[data$TimePoint %in% c("1") & data$Comment %in% NoVirus_pos,]$Mash1_norm = data[data$TimePoint %in% c("1") & data$Comment %in% NoVirus_pos,]$Mash1/temp_Mash1_TP1 data[data$TimePoint %in% c("2") & data$Comment %in% NoVirus_pos,]$Mash1_norm = data[data$TimePoint %in% c("2") & data$Comment %in% NoVirus_pos,]$Mash1/temp_Mash1_TP1 data$Mash1_norm_log = log10(data$Mash1_norm) temp_DsRed_TP1 = median(data[data$Comment %in% No_light & data$Comment %in% Mash1IRESDsRed_pos & data$TimePoint %in% c("1"),]$mCherry) temp_pDsRed_TP1 = median(data[data$Comment %in% No_light & data$Comment %in% pMash1IRESDsRed_pos & data$TimePoint %in% c("1"),]$mCherry) temp_DsRed_TP2 = median(data[data$Comment %in% No_light & data$Comment %in% Mash1IRESDsRed_pos & data$TimePoint %in% c("2"),]$mCherry) temp_pDsRed_TP2 = median(data[data$Comment %in% No_light & data$Comment %in% pMash1IRESDsRed_pos & data$TimePoint %in% c("2"),]$mCherry) data$mCherry_norm = NA data[data$TimePoint %in% c("1") & data$Comment %in% Mash1IRESDsRed_pos,]$mCherry_norm = data[data$TimePoint %in% c("1") & data$Comment %in% Mash1IRESDsRed_pos,]$mCherry/temp_DsRed_TP1 data[data$TimePoint %in% c("1") & data$Comment %in% pMash1IRESDsRed_pos,]$mCherry_norm = data[data$TimePoint %in% c("1") & data$Comment %in% pMash1IRESDsRed_pos,]$mCherry/temp_pDsRed_TP1 data[data$TimePoint %in% c("2") & data$Comment %in% Mash1IRESDsRed_pos,]$mCherry_norm = data[data$TimePoint %in% c("2") & data$Comment %in% Mash1IRESDsRed_pos,]$mCherry/temp_DsRed_TP2 data[data$TimePoint %in% c("2") & data$Comment %in% pMash1IRESDsRed_pos,]$mCherry_norm = data[data$TimePoint %in% c("2") & data$Comment %in% pMash1IRESDsRed_pos,]$mCherry/temp_pDsRed_TP2 data[data$TimePoint %in% c("1") & data$Comment %in% NoVirus_pos,]$mCherry_norm = data[data$TimePoint %in% c("1") & data$Comment %in% NoVirus_pos,]$mCherry/temp_DsRed_TP1 data[data$TimePoint %in% c("2") & data$Comment %in% NoVirus_pos,]$mCherry_norm = data[data$TimePoint %in% c("2") & data$Comment %in% NoVirus_pos,]$mCherry/temp_DsRed_TP1 data$mCherry_norm_log = log10(data$mCherry_norm) data = data[!is.na(data$StimCond),] # data$M1 = NA # data[which(data$SumCh02_log<=1.25),]$M1 = 0 # data[which(data$SumCh02_log>1.25),]$M1 = 1 # # data$mCh = NA # data[which(data$SumCh03_log<=1.19),]$mCh = 0 # data[which(data$SumCh03_log>1.19),]$mCh = 1 # # data$B3 = NA # data[which(data$SumCh04_log<=1.63),]$B3 = 0 # data[which(data$SumCh04_log>1.63),]$B3 = 1 library("ggplot2") Mash1_negthreshold_TP1_Rep1 = data.frame(matrix(ncol=2,nrow=1, dimnames=list(NULL, c("Pos", "Threshold_Norm")))) Postobeanalyzed = NoVirus_pos for (i in 1:length(Postobeanalyzed)){ temp = quantile(data[data$Comment %in% Postobeanalyzed[i] & data$TimePoint %in% c("1"),]$Mash1_norm_log,0.99) Mash1_negthreshold_TP1_Rep1 = rbind(Mash1_negthreshold_TP1_Rep1, c(Postobeanalyzed[i],temp)) } mCherry_negthreshold_TP1_Rep1 = data.frame(matrix(ncol=2,nrow=1, dimnames=list(NULL, c("Pos", "Threshold_Norm")))) Postobeanalyzed = NoVirus_pos for (i in 1:length(Postobeanalyzed)){ temp = quantile(data[data$Comment %in% Postobeanalyzed[i] & data$TimePoint %in% c("2"),]$mCherry_norm_log,0.99) mCherry_negthreshold_TP1_Rep1 = rbind(mCherry_negthreshold_TP1_Rep1, c(Postobeanalyzed[i],temp)) } cbbPalette<- c("#000000", "#0072B2", "#CC79A7","#F0E442","#009E73", "#E69F00", "#56B4E9", "#D55E00") cbbPalette_mod <- c("#000000", "#E69F00", "#56B4E9", "#D55E00","#F0E442","#009E73", "#0072B2", "#CC79A7") #Pos_tobeplotted = Novirus_pos #Pos_tobeplotted = c("B2","B6","B10","B4","F2","F6") Pos_tobeplotted = Mash1IRESDsRed_pos TimePoint_tobeplotted = c(1) Idx = data$Comment %in% Pos_tobeplotted & data$TimePoint %in% TimePoint_tobeplotted #data$temp = log(data$SumBaSiCWithRatioflatCh04) ggplot(data[Idx,], aes(x = Mash1_norm_log)) + geom_density(size=1) + #scale_x_log10()+ facet_wrap(~ StimCond+Virus+Comment, scales = "fixed") + theme_bw() + coord_cartesian(xlim=c(-1,2))+ geom_vline(xintercept = 0.4, color="#CC79A7",size=1)+ theme(axis.text.x = element_text(angle = 90, hjust = 1), strip.text = element_text(size = 10, face ="bold"), axis.text = element_text(size = 20, face = "bold"), axis.title=element_text(size=14,face="bold")) + labs(x = "Mash1 (log transformed)")+ scale_color_manual(values = cbbPalette_mod) Pos_tobeplotted = Mash1IRESDsRed_pos TimePoint_tobeplotted = c(2) Idx = data$Comment %in% Pos_tobeplotted & data$TimePoint %in% TimePoint_tobeplotted #data$temp = log(data$SumBaSiCWithRatioflatCh04) ggplot(data[Idx,], aes(x = mCherry_norm_log)) + geom_density(size=1) + #scale_x_log10()+ facet_wrap(~ StimCond+Virus+Comment, scales = "fixed") + theme_bw() + coord_cartesian(xlim=c(-0.5,0.75))+ geom_vline(xintercept = 0.14, color="#CC79A7",size=1)+ theme(axis.text.x = element_text(angle = 90, hjust = 1), strip.text = element_text(size = 10, face ="bold"), axis.text = element_text(size = 20, face = "bold"), axis.title=element_text(size=14,face="bold")) + labs(x = "Dsred (log transformed)")+ scale_color_manual(values = cbbPalette_mod) Pos_tobeplotted = Mash1IRESDsRed_pos TimePoint_tobeplotted = c(2) Idx = data$Comment %in% Pos_tobeplotted & data$TimePoint %in% TimePoint_tobeplotted #data$temp = log(data$SumBaSiCWithRatioflatCh04) ggplot(data[Idx,], aes(x = mCherry_norm_log, y= Mash1_norm_log)) + geom_point() + #scale_x_log10()+ facet_wrap(~ StimCond+Virus+Comment, scales = "fixed") + theme_bw() + #coord_cartesian(xlim=c(-0.5,0.75))+ geom_vline(xintercept = 0.14, color="#CC79A7",size=1)+ geom_hline(yintercept = 0.4, color="#CC79A7",size=1)+ theme(axis.text.x = element_text(angle = 90, hjust = 1), strip.text = element_text(size = 10, face ="bold"), axis.text = element_text(size = 20, face = "bold"), axis.title=element_text(size=14,face="bold")) + labs(x = "Dsred (log transformed)",y="Mash1(log transformed)")+ scale_color_manual(values = cbbPalette_mod) data$M1 = NA data[which(data$TimePoint==1 & data$Comment %in% Mash1IRESDsRed_pos & data$Mash1_norm_log<=0.43),]$M1 = 0 data[which(data$TimePoint==1 & data$Comment %in% Mash1IRESDsRed_pos & data$Mash1_norm_log>0.43),]$M1 = 1 data[which(data$TimePoint==2 & data$Comment %in% Mash1IRESDsRed_pos & data$Mash1_norm_log<=0.4),]$M1 = 0 data[which(data$TimePoint==2 & data$Comment %in% Mash1IRESDsRed_pos & data$Mash1_norm_log>0.4),]$M1 = 1 data$DR = NA data[which(data$TimePoint==1 & data$Comment %in% Mash1IRESDsRed_pos & data$mCherry_norm_log<=0.225),]$DR = 0 data[which(data$TimePoint==1 & data$Comment %in% Mash1IRESDsRed_pos & data$mCherry_norm_log>0.225),]$DR = 1 data[which(data$TimePoint==2 & data$Comment %in% Mash1IRESDsRed_pos & data$mCherry_norm_log<=0.14),]$DR = 0 data[which(data$TimePoint==2 & data$Comment %in% Mash1IRESDsRed_pos & data$mCherry_norm_log>0.14),]$DR = 1 write.csv(data,"allquant_withthresholds.csv", row.names=FALSE) library(dplyr) count_data = data %>% group_by(TimePoint,Virus,StimCond,Comment,M1,DR) %>% summarise (n = n()) %>% mutate(freq = n / sum(n)) write.csv(count_data,"count_data_Mash1posorneg.csv", row.names=FALSE) data_TP2$M1 = NA data_TP2[which(data_TP2$SumCh02_log<=1.15),]$M1 = 0 data_TP2[which(data_TP2$SumCh02_log>1.15),]$M1 = 1 library(dplyr) count_data_TP2 = data_TP2 %>% group_by(Virus,StimCond,M1) %>% summarise (n = n()) %>% mutate(freq = n / sum(n)) write.csv(count_data_TP2,"count_data_TP2_Mash1posorneg.csv", row.names=FALSE)