EASY rewrite

This commit is contained in:
2024-07-23 10:54:58 -04:00
parent 0440912859
commit 811a1c2dc4
26 changed files with 5472 additions and 167 deletions

View File

@@ -1,6 +1,15 @@
#Based on InteractionTemplate.R which is based on Sean Santose's Interaction_V5 script.
#Adapt SS For Structured Data storage but using command line scripts
###Set up the required libraries, call required plot theme elements and set up the command line arguments
#!/usr/bin/env R
# Based on InteractionTemplate.R which is based on Sean Santos's Interaction_V5 script
#
# Updated 2024 Bryan C Roessler to improve file operations and portability
# NOTE: The script now has 1 REQUIRED argument and 4 OPTIONAL arguments:
# 1. Path to input file
# 2. /output/ directory
# 3. Path to StudyInfo.csv
# 4. Path to SGDgeneList
# 5. Standard deviation value
# Load libraries
library("ggplot2")
library("plyr")
library("extrafont")
@@ -8,73 +17,76 @@ library("gridExtra")
library("gplots")
library("RColorBrewer")
library("stringr")
#library("gdata")
library(plotly)
library(htmlwidgets)
library("gdata")
library("plotly")
library("htmlwidgets")
Args <- commandArgs(TRUE)
input_file <- Args[1] #"!!Results_17_0827_yor1null-rpl12anull misLabeledAsFrom MI 17_0919_yor1-curated.txt" #Args[1] #Arg 1 #"!!ResultsStd_JS 19_1224_HLEG_P53.txt" is the !!results ... .txt
#Tool to find a file and copy it to desired location
destDir= getwd()
#srcFile= file.choose()
#file.copy(srcFile, destDir)
#input_file= tail(strsplit(srcFile,"[/]")[[1]],1)
# Parse arguments
args <- commandArgs(TRUE)
# Set input file (required)
inputFile <- args[1]
#Path to Output Directory
#W=getwd() #R is F'd up, Can't use, Any legitamate platform could build out dirs from this
outDir <- "ZScores/" #"Args[2] #paste0(W,"/ZScores/")
subDir <- outDir #Args[2]
if (file.exists(subDir)){
outputpath <- subDir
# Set output dir
if (length(args) > 2) {
outDir <- args[2]
} else {
dir.create(file.path(subDir))
outDir <- "/ZScores/"
}
if (file.exists(paste(subDir,"QC/",sep=""))){
outputpath_QC <- paste(subDir,"QC/",sep="")
# Set StudyInfo file path
if (length(args) > 3) {
studyInfo <- args[3]
} else {
dir.create(file.path(paste(subDir,"QC/",sep="")))
outputpath_QC <- paste(subDir,"QC/",sep="")
studyInfo <- "../Code/StudyInfo.csv"
}
#define the output path (formerly the second argument from Rscript)
outputpath <- outDir
#Set Args[2] the Background contamination noise filter as a function of standard deviation
#std= as.numeric(Args[2])
#Sean recommends 3 or 5 SD factor.
#Capture Exp_ number,use it to Save Args[2]{std}to Labels field and then Write to Labels to studyInfo.txt for future reference
Labels <- read.csv(file= "../Code/StudyInfo.csv",stringsAsFactors = FALSE) #,sep= ",")
print("Be sure to enter Background noise filter standard deviation i.e., 3 or 5 per Sean")
# Set SGDgeneList file path
if (length(args) > 4) {
SGDgeneList <- args[4]
} else {
SGDgeneList <- "../Code/SGD_features.tab"
}
#User prompt for std multiplier Value
cat("Enter a Standard Deviation value to noise filter \n")
inpChar<- readLines(file("stdin"), n = 1L)
cat(paste("Standard Deviation Value is", inpChar, "\n"))
inpNum= as.numeric(inpChar)
#set std deviation multiplier default if no user entry
if(!is.na(inpNum)){
std= inpNum
}else{std= 3}
# Set standard deviation
if (length(args) > 5) {
delBGFactor <- args[5]
} else {
# User prompt for std multiplier Value
print("Enter a Standard Deviation value for noise filter")
print("Sean Santos recommends 3 or 5")
delBGFactor <- readLines(file("stdin"), n = 1L)
}
delBGFactor <- as.numeric(delBGFactor)
if(is.na(delBGFactor)){
delBGFactor <- 3 # Recommended by Sean
}
print(paste("The Standard Deviation Value is: ", delBGFactor))
outDir_QC <- paste(outDir,"QC/",sep="")
if !(file.exists(outDir)){
dir.create(file.path(outDir))
}
if !(file.exists(outDir_QC)){
dir.create(file.path(outDir_QC))
}
# Capture Exp_ number,use it to Save args[2]{std}to Labels field and then
# write to Labels to studyInfo.txt for future reference
Labels <- read.csv(file=studyInfo,stringsAsFactors = FALSE) # sep= ","
expNumber <- as.numeric(sub("^.*?(\\d+)$", "\\1", getwd()))
Labels[expNumber,3] <- delBGFactor
write.csv(Labels,file=studyInfo,row.names = FALSE)
expNumber<- as.numeric(sub("^.*?(\\d+)$", "\\1", getwd()))
Labels[expNumber,3]= as.numeric(std)
Delta_Background_sdFactor <- std
DelBGFactr <- as.numeric(Delta_Background_sdFactor)
#Write Background SD value to studyInfo.txt file
#write.csv(Labels,file=paste("../Code/StudyInfo.csv"),row.names = FALSE)
write.csv(Labels,file=paste("../Code/StudyInfo.csv"),row.names = FALSE)
print('ln 50 write StudyInfo.csv ')
#write.table(Labels,file=paste(outputpath,"StudyInfo.txt"),sep = "\t",row.names = FALSE)
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++BEGIN USER DATA SELECTION SECTION+++++++++++++++++++++++++++++++++++++++++++++++++
###############################################################################
################### BEGIN USER DATA SELECTION SECTION #########################
###############################################################################
#read in the data
X <- read.delim(input_file,skip=2,as.is=T,row.names=1,strip.white=TRUE)
X <- read.delim(inputFile,skip=2,as.is=T,row.names=1,strip.white=TRUE)
X <- X[!(X[[1]]%in%c("","Scan")),]
#X <- X[!(X[[1]]%in%c(61:76)),] #Remove dAmp plates which are Scans 61 thru 76
@@ -145,7 +157,6 @@ Xbu= X
#Inserted to use SGDgenelist to update orfs and replace empty geneName cells with ORF name (adapted from Sean's Merge script). This is to 'fix' the naming for everything that follows (REMc, Heatmaps ... et.al) rather than do it piece meal later
#Sean's Match Script( which was adapted here) was fixed 2022_0608 so as not to write over the RF1&RF2 geneNames which caused a variance with his code results
#in the Z_lm_L,K,r&AUC output values. Values correlated well but were off by a multiplier factor.
SGDgeneList= "../Code/SGD_features.tab"
genes = data.frame(read.delim(file=SGDgeneList,quote="",header=FALSE,colClasses = c(rep("NULL",3), rep("character", 2), rep("NULL", 11))))
for(i in 1:length(X[,14])){
ii= as.numeric(i)
@@ -315,17 +326,17 @@ X$Delta_Backgrd <- X$LstBackgrd - X$X1stBackgrd
Raw_l_vs_K_beforeQC <- ggplot(X,aes(l,K,color=as.factor(Conc_Num))) + geom_point(aes(ORF=ORF,Gene=Gene,Delta_Backgrd=Delta_Backgrd),shape=3) +
ggtitle("Raw L vs K before QC") +
theme_Publication_legend_right()
pdf(paste(outputpath_QC,"Raw_L_vs_K_beforeQC.pdf",sep=""),width = 12,height = 8)
pdf(paste(outDir_QC,"Raw_L_vs_K_beforeQC.pdf",sep=""),width = 12,height = 8)
Raw_l_vs_K_beforeQC
dev.off()
pgg <- ggplotly(Raw_l_vs_K_beforeQC)
#pgg
plotly_path <- paste(getwd(),"/",outputpath_QC,"Raw_L_vs_K_beforeQC.html",sep="")
plotly_path <- paste(outDir_QC,"Raw_L_vs_K_beforeQC.html",sep="")
saveWidget(pgg, file=plotly_path, selfcontained =TRUE)
#set delta background tolerance based on 3 sds from the mean delta background
Delta_Background_Tolerance <- mean(X$Delta_Backgrd)+(DelBGFactr*sd(X$Delta_Backgrd))
Delta_Background_Tolerance <- mean(X$Delta_Backgrd)+(delBGFactor*sd(X$Delta_Backgrd))
#Delta_Background_Tolerance <- mean(X$Delta_Backgrd)+(3*sd(X$Delta_Backgrd))
print(paste("Delta_Background_Tolerance is",Delta_Background_Tolerance,sep=" "))
@@ -350,12 +361,12 @@ X_Delta_Backgrd_above_Tolerance_L_vs_K <- ggplot(X_Delta_Backgrd_above_Tolerance
annotate("text",x=X_Delta_Backgrd_above_Tolerance_L_halfmedian,y=X_Delta_Backgrd_above_Tolerance_K_halfmedian,
label = paste("Strains above delta background tolerance = ",X_Delta_Backgrd_above_Tolerance_toRemove)) +
theme_Publication_legend_right()
pdf(paste(outputpath_QC,"Raw_L_vs_K_for_strains_above_deltabackgrd_threshold.pdf",sep=""),width = 12,height = 8)
pdf(paste(outDir_QC,"Raw_L_vs_K_for_strains_above_deltabackgrd_threshold.pdf",sep=""),width = 12,height = 8)
X_Delta_Backgrd_above_Tolerance_L_vs_K
dev.off()
pgg <- ggplotly(X_Delta_Backgrd_above_Tolerance_L_vs_K)
#pgg
plotly_path <- paste(getwd(),"/",outputpath_QC,"Raw_L_vs_K_for_strains_above_deltabackgrd_threshold.html",sep="")
plotly_path <- paste(outDir_QC,"Raw_L_vs_K_for_strains_above_deltabackgrd_threshold.html",sep="")
saveWidget(pgg, file=plotly_path, selfcontained =TRUE)
#frequency plot for all data vs. the delta_background
@@ -366,7 +377,7 @@ DeltaBackground_Frequency_Plot <- ggplot(X,aes(Delta_Backgrd,color=as.factor(Con
DeltaBackground_Bar_Plot <- ggplot(X,aes(Delta_Backgrd,color=as.factor(Conc_Num))) + geom_bar() +
ggtitle("Bar plot for Delta Background by Conc All Data") + theme_Publication_legend_right()
pdf(file = paste(outputpath_QC,"Frequency_Delta_Background.pdf",sep=""),width = 12,height = 8)
pdf(file = paste(outDir_QC,"Frequency_Delta_Background.pdf",sep=""),width = 12,height = 8)
print(DeltaBackground_Frequency_Plot)
print(DeltaBackground_Bar_Plot)
dev.off()
@@ -432,7 +443,7 @@ Plate_Analysis_Delta_Backgrd_Box_afterQC <- ggplot(X,aes(as.factor(Scan),Delta_B
ggtitle("Plate analysis by Drug Conc for Delta_Backgrd after quality control") + theme_Publication()
#print the plate analysis data before and after QC
pdf(file=paste(outputpath_QC,"Plate_Analysis.pdf",sep=""),width = 14,height=9)
pdf(file=paste(outDir_QC,"Plate_Analysis.pdf",sep=""),width = 14,height=9)
Plate_Analysis_L
Plate_Analysis_L_afterQC
Plate_Analysis_K
@@ -446,7 +457,7 @@ Plate_Analysis_Delta_Backgrd_afterQC
dev.off()
#print the plate analysis data before and after QC
pdf(file=paste(outputpath_QC,"Plate_Analysis_Boxplots.pdf",sep=""),width = 18,height=9)
pdf(file=paste(outDir_QC,"Plate_Analysis_Boxplots.pdf",sep=""),width = 18,height=9)
Plate_Analysis_L_Box
Plate_Analysis_L_Box_afterQC
Plate_Analysis_K_Box
@@ -503,7 +514,7 @@ Plate_Analysis_Delta_Backgrd_Box_afterQC_Z <- ggplot(X_noZero,aes(as.factor(Scan
ggtitle("Plate analysis by Drug Conc for Delta_Backgrd after quality control") + theme_Publication()
#print the plate analysis data before and after QC
pdf(file=paste(outputpath_QC,"Plate_Analysis_noZeros.pdf",sep=""),width = 14,height=9)
pdf(file=paste(outDir_QC,"Plate_Analysis_noZeros.pdf",sep=""),width = 14,height=9)
Plate_Analysis_L_afterQC_Z
Plate_Analysis_K_afterQC_Z
Plate_Analysis_r_afterQC_Z
@@ -512,7 +523,7 @@ Plate_Analysis_Delta_Backgrd_afterQC_Z
dev.off()
#print the plate analysis data before and after QC
pdf(file=paste(outputpath_QC,"Plate_Analysis_noZeros_Boxplots.pdf",sep=""),width = 18,height=9)
pdf(file=paste(outDir_QC,"Plate_Analysis_noZeros_Boxplots.pdf",sep=""),width = 18,height=9)
Plate_Analysis_L_Box_afterQC_Z
Plate_Analysis_K_Box_afterQC_Z
Plate_Analysis_r_Box_afterQC_Z
@@ -556,7 +567,7 @@ X_stats_ALL <- ddply(X, c("Conc_Num","Conc_Num_Factor"), summarise,
)
#print(X_stats_ALL_L)
write.csv(X_stats_ALL,file=paste(outputpath,"SummaryStats_ALLSTRAINS.csv"),row.names = FALSE)
write.csv(X_stats_ALL,file=paste(outDir,"SummaryStats_ALLSTRAINS.csv"),row.names = FALSE)
#+++++END QC SECTION+++++++++++++++++++++++++++++++++++++++++++++++++++++++
##### Part 3 - Generate summary statistics and calculate the max theoretical L value
@@ -660,7 +671,7 @@ for(s in Background_Strains){
se_AUC = sd_AUC / sqrt(N-1)
)
write.csv(X_stats_BY,file=paste(outputpath,"SummaryStats_BackgroundStrains.csv"),row.names=FALSE)
write.csv(X_stats_BY,file=paste(outDir,"SummaryStats_BackgroundStrains.csv"),row.names=FALSE)
#calculate the max theoretical L values
#only look for max values when K is within 2SD of the ref strain
@@ -708,7 +719,7 @@ for(s in Background_Strains){
)
print(X_stats_BY_L_within_2SD_K)
X1_SD_within_2SD_K <- max(X_stats_BY_L_within_2SD_K$sd)
write.csv(X_stats_BY_L_within_2SD_K,file=paste(outputpath_QC,"Max_Observed_L_Vals_for_spots_within_2SD_K.csv",sep=""),row.names=FALSE)
write.csv(X_stats_BY_L_within_2SD_K,file=paste(outDir_QC,"Max_Observed_L_Vals_for_spots_within_2SD_K.csv",sep=""),row.names=FALSE)
X_stats_BY_L_outside_2SD_K <- ddply(X_outside_2SD_K, c("Conc_Num","Conc_Num_Factor"), summarise,
N = (length(l)),
@@ -725,22 +736,22 @@ for(s in Background_Strains){
#X1_SD_outside_2SD_K <- X[X$l %in% X1_SD_within_2SD_K$l,]
Outside_2SD_K_L_vs_K <- ggplot(X_outside_2SD_K,aes(l,K,color=as.factor(Conc_Num))) + geom_point(aes(ORF=ORF,Gene=Gene,Delta_Backgrd=Delta_Backgrd),shape=3) +
ggtitle("Raw L vs K for strains falling outside 2SD of the K mean at each conc") + theme_Publication_legend_right()
pdf(paste(outputpath_QC,"Raw_L_vs_K_for_strains_2SD_outside_mean_K.pdf",sep=""),width = 10,height = 8)
pdf(paste(outDir_QC,"Raw_L_vs_K_for_strains_2SD_outside_mean_K.pdf",sep=""),width = 10,height = 8)
print(Outside_2SD_K_L_vs_K)
dev.off()
pgg <- ggplotly(Outside_2SD_K_L_vs_K)
plotly_path <- paste(getwd(),"/",outputpath_QC,"RawL_vs_K_for_strains_outside_2SD_K.html",sep="")
plotly_path <- paste(outDir_QC,"RawL_vs_K_for_strains_outside_2SD_K.html",sep="")
saveWidget(pgg, file=plotly_path, selfcontained =TRUE)
Outside_2SD_K_delta_background_vs_K <- ggplot(X_outside_2SD_K,aes(Delta_Backgrd,K,color=as.factor(Conc_Num))) + geom_point(aes(l=l,ORF=ORF,Gene=Gene),shape=3,position="jitter") +
ggtitle("DeltaBackground vs K for strains falling outside 2SD of the K mean at each conc") + theme_Publication_legend_right()
pdf(paste(outputpath_QC,"DeltaBackground_vs_K_for_strains_2SD_outside_mean_K.pdf",sep=""),width = 10,height = 8)
pdf(paste(outDir_QC,"DeltaBackground_vs_K_for_strains_2SD_outside_mean_K.pdf",sep=""),width = 10,height = 8)
Outside_2SD_K_delta_background_vs_K
dev.off()
pgg <- ggplotly(Outside_2SD_K_delta_background_vs_K)
#pgg
plotly_path <- paste(getwd(),"/",outputpath_QC,"DeltaBackground_vs_K_for_strains_outside_2SD_K.html",sep="")
plotly_path <- paste(outDir_QC,"DeltaBackground_vs_K_for_strains_outside_2SD_K.html",sep="")
saveWidget(pgg, file=plotly_path, selfcontained =TRUE)
@@ -1160,7 +1171,7 @@ for(s in Background_Strains){
InteractionScores_RF <- InteractionScores_RF[order(InteractionScores_RF$Z_lm_L,decreasing=TRUE),]
InteractionScores_RF <- InteractionScores_RF[order(InteractionScores_RF$NG,decreasing=TRUE),]
write.csv(InteractionScores_RF,paste(outputpath,"RF_ZScores_Interaction.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_RF,paste(outDir,"RF_ZScores_Interaction.csv",sep=""),row.names=FALSE)
for(i in 1:num_genes_RF){
@@ -1234,7 +1245,7 @@ for(s in Background_Strains){
}
}
print("Pass RF ggplot loop")
write.csv(X_stats_interaction_ALL_RF_final,paste(outputpath,"RF_ZScore_Calculations.csv",sep=""),row.names = FALSE)
write.csv(X_stats_interaction_ALL_RF_final,paste(outDir,"RF_ZScore_Calculations.csv",sep=""),row.names = FALSE)
####### Part 5 - Get Zscores for Gene deletion strains
@@ -1564,7 +1575,7 @@ for(s in Background_Strains){
InteractionScores <- InteractionScores[order(InteractionScores$NG,decreasing=TRUE),]
df_order_by_OrfRep <- unique(InteractionScores$OrfRep)
#X_stats_interaction_ALL <- X_stats_interaction_ALL[order(X_stats_interaction_ALL$NG,decreasing=TRUE),]
write.csv(InteractionScores,paste(outputpath,"ZScores_Interaction.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores,paste(outDir,"ZScores_Interaction.csv",sep=""),row.names=FALSE)
InteractionScores_deletion_enhancers_L <- InteractionScores[InteractionScores$Avg_Zscore_L >= 2,]
InteractionScores_deletion_enhancers_K <- InteractionScores[InteractionScores$Avg_Zscore_K <= -2,]
@@ -1588,16 +1599,16 @@ for(s in Background_Strains){
InteractionScores_deletion_enhancers_lm_Suppressors_AvgZscore_K <- InteractionScores_deletion_enhancers_lm_Suppressors_AvgZscore_K[!is.na(InteractionScores_deletion_enhancers_lm_Suppressors_AvgZscore_K$OrfRep),]
InteractionScores_deletion_enhancers_Avg_Zscore_Suppressors_lm_K <- InteractionScores_deletion_enhancers_Avg_Zscore_Suppressors_lm_K[!is.na(InteractionScores_deletion_enhancers_Avg_Zscore_Suppressors_lm_K$OrfRep),]
write.csv(InteractionScores_deletion_enhancers_L,paste(outputpath,"ZScores_Interaction_DeletionEnhancers_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_K,paste(outputpath,"ZScores_Interaction_DeletionEnhancers_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_suppressors_L,paste(outputpath,"ZScores_Interaction_DeletionSuppressors_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_suppressors_K,paste(outputpath,"ZScores_Interaction_DeletionSuppressors_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_and_Suppressors_L,paste(outputpath,"ZScores_Interaction_DeletionEnhancers_and_Suppressors_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_and_Suppressors_K,paste(outputpath,"ZScores_Interaction_DeletionEnhancers_and_Suppressors_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_lm_Suppressors_AvgZscore_L,paste(outputpath,"ZScores_Interaction_Suppressors_and_lm_Enhancers_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_Avg_Zscore_Suppressors_lm_L,paste(outputpath,"ZScores_Interaction_Enhancers_and_lm_Suppressors_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_lm_Suppressors_AvgZscore_K,paste(outputpath,"ZScores_Interaction_Suppressors_and_lm_Enhancers_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_Avg_Zscore_Suppressors_lm_K,paste(outputpath,"ZScores_Interaction_Enhancers_and_lm_Suppressors_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_L,paste(outDir,"ZScores_Interaction_DeletionEnhancers_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_K,paste(outDir,"ZScores_Interaction_DeletionEnhancers_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_suppressors_L,paste(outDir,"ZScores_Interaction_DeletionSuppressors_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_suppressors_K,paste(outDir,"ZScores_Interaction_DeletionSuppressors_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_and_Suppressors_L,paste(outDir,"ZScores_Interaction_DeletionEnhancers_and_Suppressors_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_and_Suppressors_K,paste(outDir,"ZScores_Interaction_DeletionEnhancers_and_Suppressors_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_lm_Suppressors_AvgZscore_L,paste(outDir,"ZScores_Interaction_Suppressors_and_lm_Enhancers_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_Avg_Zscore_Suppressors_lm_L,paste(outDir,"ZScores_Interaction_Enhancers_and_lm_Suppressors_L.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_lm_Suppressors_AvgZscore_K,paste(outDir,"ZScores_Interaction_Suppressors_and_lm_Enhancers_K.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_Avg_Zscore_Suppressors_lm_K,paste(outDir,"ZScores_Interaction_Enhancers_and_lm_Suppressors_K.csv",sep=""),row.names=FALSE)
#get enhancers and suppressors for linear regression
InteractionScores_deletion_enhancers_L_lm <- InteractionScores[InteractionScores$Z_lm_L >= 2,]
@@ -1614,15 +1625,15 @@ for(s in Background_Strains){
InteractionScores_deletion_enhancers_and_Suppressors_L_lm <- InteractionScores_deletion_enhancers_and_Suppressors_L_lm[!is.na(InteractionScores_deletion_enhancers_and_Suppressors_L_lm$OrfRep),]
InteractionScores_deletion_enhancers_and_Suppressors_K_lm <- InteractionScores_deletion_enhancers_and_Suppressors_K_lm[!is.na(InteractionScores_deletion_enhancers_and_Suppressors_K_lm$OrfRep),]
write.csv(InteractionScores_deletion_enhancers_L_lm,paste(outputpath,"ZScores_Interaction_DeletionEnhancers_L_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_K_lm,paste(outputpath,"ZScores_Interaction_DeletionEnhancers_K_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_suppressors_L_lm,paste(outputpath,"ZScores_Interaction_DeletionSuppressors_L_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_suppressors_K_lm,paste(outputpath,"ZScores_Interaction_DeletionSuppressors_K_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_and_Suppressors_L_lm,paste(outputpath,"ZScores_Interaction_DeletionEnhancers_and_Suppressors_L_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_and_Suppressors_K_lm,paste(outputpath,"ZScores_Interaction_DeletionEnhancers_and_Suppressors_K_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_L_lm,paste(outDir,"ZScores_Interaction_DeletionEnhancers_L_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_K_lm,paste(outDir,"ZScores_Interaction_DeletionEnhancers_K_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_suppressors_L_lm,paste(outDir,"ZScores_Interaction_DeletionSuppressors_L_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_suppressors_K_lm,paste(outDir,"ZScores_Interaction_DeletionSuppressors_K_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_and_Suppressors_L_lm,paste(outDir,"ZScores_Interaction_DeletionEnhancers_and_Suppressors_L_lm.csv",sep=""),row.names=FALSE)
write.csv(InteractionScores_deletion_enhancers_and_Suppressors_K_lm,paste(outDir,"ZScores_Interaction_DeletionEnhancers_and_Suppressors_K_lm.csv",sep=""),row.names=FALSE)
write.csv(Labels,file=paste("../Code/StudyInfo.csv"),row.names = FALSE)
write.csv(Labels,file=paste(StudyInfo),row.names = FALSE)
print('ln 1570 write StudyInfo.csv after ')
#write.table(Labels,file=paste("../Code/StudyInfo.txt"),sep="\t",row.names = FALSE)
@@ -1697,7 +1708,7 @@ for(s in Background_Strains){
}
}
print("Pass Int ggplot loop")
write.csv(X_stats_interaction_ALL_final,paste(outputpath,"ZScore_Calculations.csv",sep=""),row.names = FALSE)
write.csv(X_stats_interaction_ALL_final,paste(outDir,"ZScore_Calculations.csv",sep=""),row.names = FALSE)
@@ -1706,7 +1717,7 @@ for(s in Background_Strains){
Blank <- ggplot(X2_RF) + geom_blank()
pdf(paste(outputpath,"InteractionPlots.pdf",sep=""),width = 16, height = 16, onefile = TRUE)
pdf(paste(outDir,"InteractionPlots.pdf",sep=""),width = 16, height = 16, onefile = TRUE)
X_stats_X2_RF <- ddply(X2_RF, c("Conc_Num","Conc_Num_Factor"), summarise,
mean_L = mean(l,na.rm=TRUE),
@@ -1863,7 +1874,7 @@ for(s in Background_Strains){
pdf(paste(outputpath,"RF_InteractionPlots.pdf",sep=""),width = 16, height = 16, onefile = TRUE)
pdf(paste(outDir,"RF_InteractionPlots.pdf",sep=""),width = 16, height = 16, onefile = TRUE)
X_stats_X2_RF <- ddply(X2_RF, c("Conc_Num","Conc_Num_Factor"), summarise,
mean_L = mean(l,na.rm=TRUE),
@@ -2155,7 +2166,7 @@ for(s in Background_Strains){
theme_Publication()
pdf(paste(outputpath,"RankPlots.pdf",sep=""),width = 18, height = 12, onefile = TRUE)
pdf(paste(outDir,"RankPlots.pdf",sep=""),width = 18, height = 12, onefile = TRUE)
grid.arrange(Rank_L_1SD,Rank_L_2SD,Rank_L_3SD,Rank_K_1SD,Rank_K_2SD,Rank_K_3SD,ncol=3,nrow=2)
grid.arrange(Rank_L_1SD_notext,Rank_L_2SD_notext,Rank_L_3SD_notext,Rank_K_1SD_notext,Rank_K_2SD_notext,Rank_K_3SD_notext,ncol=3,nrow=2)
@@ -2262,7 +2273,7 @@ for(s in Background_Strains){
geom_hline(yintercept=c(-3,3)) + geom_point(size=0.1,shape=3) +
theme_Publication()
pdf(paste(outputpath,"RankPlots_lm.pdf",sep=""),width = 18, height = 12, onefile = TRUE)
pdf(paste(outDir,"RankPlots_lm.pdf",sep=""),width = 18, height = 12, onefile = TRUE)
grid.arrange(Rank_L_1SD_lm,Rank_L_2SD_lm,Rank_L_3SD_lm,Rank_K_1SD_lm,Rank_K_2SD_lm,Rank_K_3SD_lm,ncol=3,nrow=2)
grid.arrange(Rank_L_1SD_notext_lm,Rank_L_2SD_notext_lm,Rank_L_3SD_notext_lm,Rank_K_1SD_notext_lm,Rank_K_2SD_notext_lm,Rank_K_3SD_notext_lm,ncol=3,nrow=2)
@@ -2297,7 +2308,7 @@ for(s in Background_Strains){
get_lm_AUC <- lm(X_NArm$Z_lm_AUC~X_NArm$Avg_Zscore_AUC)
AUC_lm <- summary(get_lm_AUC)
pdf(paste(outputpath,"Avg_Zscore_vs_lm_NA_rm.pdf",sep=""),width = 16, height = 12, onefile = TRUE)
pdf(paste(outDir,"Avg_Zscore_vs_lm_NA_rm.pdf",sep=""),width = 16, height = 12, onefile = TRUE)
print(ggplot(X_NArm,aes(Avg_Zscore_L,Z_lm_L)) + geom_point(aes(color=Overlap),shape=3) + geom_smooth(method = "lm",color=1) +
ggtitle("Avg Zscore vs lm L") +
@@ -2329,7 +2340,7 @@ for(s in Background_Strains){
pgg <- ggplotly(lm_v_Zscore_L)
#pgg
plotly_path <- paste(getwd(),"/",outputpath,"Avg_Zscore_vs_lm_NA_rm.html",sep="")
plotly_path <- paste(outDir,"Avg_Zscore_vs_lm_NA_rm.html",sep="")
saveWidget(pgg, file=plotly_path, selfcontained =TRUE)
X_NArm$L_Rank <- rank(X_NArm$Avg_Zscore_L)
@@ -2357,7 +2368,7 @@ for(s in Background_Strains){
num_genes_NArm2 <- (dim(X_NArm)[1])/2
pdf(paste(outputpath,"Avg_Zscore_vs_lm_ranked_NA_rm.pdf",sep=""),width = 16, height = 12, onefile = TRUE)
pdf(paste(outDir,"Avg_Zscore_vs_lm_ranked_NA_rm.pdf",sep=""),width = 16, height = 12, onefile = TRUE)
print(ggplot(X_NArm,aes(L_Rank,L_Rank_lm)) + geom_point(aes(color=Overlap),shape=3) + geom_smooth(method = "lm",color=1) +
ggtitle("Rank Avg Zscore vs lm L") +
@@ -2481,7 +2492,7 @@ for(s in Background_Strains){
theme_Publication()
pdf(paste(outputpath,"RankPlots_naRM.pdf",sep=""),width = 18, height = 12, onefile = TRUE)
pdf(paste(outDir,"RankPlots_naRM.pdf",sep=""),width = 18, height = 12, onefile = TRUE)
grid.arrange(Rank_L_1SD,Rank_L_2SD,Rank_L_3SD,Rank_K_1SD,Rank_K_2SD,Rank_K_3SD,ncol=3,nrow=2)
grid.arrange(Rank_L_1SD_notext,Rank_L_2SD_notext,Rank_L_3SD_notext,Rank_K_1SD_notext,Rank_K_2SD_notext,Rank_K_3SD_notext,ncol=3,nrow=2)
@@ -2588,7 +2599,7 @@ for(s in Background_Strains){
geom_hline(yintercept=c(-3,3)) + geom_point(size=0.1,shape=3) +
theme_Publication()
pdf(paste(outputpath,"RankPlots_lm_naRM.pdf",sep=""),width = 18, height = 12, onefile = TRUE)
pdf(paste(outDir,"RankPlots_lm_naRM.pdf",sep=""),width = 18, height = 12, onefile = TRUE)
grid.arrange(Rank_L_1SD_lm,Rank_L_2SD_lm,Rank_L_3SD_lm,Rank_K_1SD_lm,Rank_K_2SD_lm,Rank_K_3SD_lm,ncol=3,nrow=2)
grid.arrange(Rank_L_1SD_notext_lm,Rank_L_2SD_notext_lm,Rank_L_3SD_notext_lm,Rank_K_1SD_notext_lm,Rank_K_2SD_notext_lm,Rank_K_3SD_notext_lm,ncol=3,nrow=2)
@@ -2619,7 +2630,7 @@ get_lm_6 <- lm(X_NArm$Z_lm_AUC~X_NArm$Z_lm_r)
L_lm_6 <- summary(get_lm_6)
pdf(file=paste(outputpath,"Correlation_CPPs.pdf",sep=""),width = 10, height = 7, onefile = TRUE)
pdf(file=paste(outDir,"Correlation_CPPs.pdf",sep=""),width = 10, height = 7, onefile = TRUE)
ggplot(X_NArm,aes(Z_lm_L,Z_lm_K)) + geom_point(shape=3,color="gray70") +
geom_smooth(method="lm",color="tomato3") +
@@ -2707,24 +2718,7 @@ ggplot(X_NArm,aes(Z_lm_r,Z_lm_AUC)) + geom_point(shape=3,color="gray70") +
theme_Publication_legend_right() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.text.x = element_text(size=16),axis.title.x = element_text(size=18), axis.text.y = element_text(size=16),axis.title.y = element_text(size=18))
dev.off()
#write.csv(Labels,file=paste("../Code/Parameters.csv"),row.names = FALSE)
timestamp()
#BoneYard***********************************************
#I'm thinking this parameter needs to be save somewhere "permanent' for the record so outputs can be reproduced.
#take this out of the Arguments. In Matlab I could for future in .mat file. Maybe I could save the SD Args[2] as part of the StudyInfo.txt.
#Corruptable but better than nothing.
#if(is.na(Args[2])){
# std=3
#}else {
# std= Arg[2]
#Delta_Background_sdFactor <- 2 #Args[3]
#DelBGFactr <- as.numeric(Delta_Background_sdFactor)
#}