Rollup before removing NAs from joinInteractExps.R

This commit is contained in:
2024-08-15 15:02:53 -04:00
parent 6992d5eec0
commit 38b3f66695
3 changed files with 169 additions and 117 deletions

View File

@@ -21,7 +21,7 @@ if (length(args) >= 2) {
sd <- 2 # default value
}
sprintf("SD value is: %f", sd)
sprintf("SD value is: %d", sd)
# Set study_info file
if (length(args) >= 3) {
@@ -30,15 +30,23 @@ if (length(args) >= 3) {
study_info <- "../Code/StudyInfo.csv" # for legacy workflow
}
studies <- args[3:length(args)]
studies <- args[4:length(args)]
print(studies)
input_files <- c()
for (study in 1:length(studies)) {
for (i in seq_along(studies)) {
study <- studies[i]
zs_file <- file.path(study, "zscores", "zscores_interaction.csv")
if (file.exists(zs_file)) {
input_files[study] <- zs_file
input_files[i] <- zs_file
}
}
rm(zs_file, study)
for (var in ls()) {
print(paste(var, ":", get(var)))
}
print(input_files)
print(length(input_files))
# TODO this is better handled in a loop in case you want to compare more experiments?
@@ -47,7 +55,12 @@ print(length(input_files))
# Join the two files at a time as a function of how many inputFile
# list the larger file first ? in this example X2 has the larger number of genes
# If X1 has a larger number of genes, switch the order of X1 and X2
if (length(input_files) == 2) {
if (length(input_files) == 1) {
print("Only one experiment to compare, skipping join")
stop("Exiting script")
}
if (length(input_files) >= 2) {
X1 <- read.csv(file = input_files[1], stringsAsFactors = FALSE)
X2 <- read.csv(file = input_files[2], stringsAsFactors = FALSE)
X <- join(X1, X2, by = "OrfRep")
@@ -57,11 +70,10 @@ if (length(input_files) == 2) {
headSel <- select(headSel, -"Gene.1") # remove "Gene.1 column
headSel2 <- select(OBH, contains("OrfRep"), matches("Gene")) #Frame for interleaving Z_lm with Shift colums
headSel2 <- select(headSel2, -"Gene.1") # remove "Gene.1 column #Frame for interleaving Z_lm with Shift colums
} else if (length(input_files) == 3) {
X1 <- read.csv(file = input_files[1], stringsAsFactors = FALSE) # exp1File,stringsAsFactors = FALSE)
X2 <- read.csv(file = input_files[2], stringsAsFactors = FALSE) # exp2File,stringsAsFactors = FALSE)
X3 <- read.csv(file = input_files[3], stringsAsFactors = FALSE) # exp3File,stringsAsFactors = FALSE)
X <- join(X1, X2, by = "OrfRep")
}
if (length(input_files) >= 3) {
X3 <- read.csv(file = input_files[3], stringsAsFactors = FALSE)
X <- join(X, X3, by = "OrfRep")
OBH <- X[, order(colnames(X))] # OrderByHeader
headSel <- select(OBH, contains("OrfRep"), matches("Gene"),
@@ -69,14 +81,10 @@ if (length(input_files) == 2) {
headSel <- select(headSel, -"Gene.1", -"Gene.2")
headSel2 <- select(OBH, contains("OrfRep"), matches("Gene"))
headSel2 <- select(headSel2, -"Gene.1", -"Gene.2")
} else if (length(input_files) == 4) {
X1 <- read.csv(file = input_files[1], stringsAsFactors = FALSE) # exp1File,stringsAsFactors = FALSE)
X2 <- read.csv(file = input_files[2], stringsAsFactors = FALSE) # exp2File,stringsAsFactors = FALSE)
X3 <- read.csv(file = input_files[3], stringsAsFactors = FALSE) # exp3File,stringsAsFactors = FALSE)
X4 <- read.csv(file = input_files[4], stringsAsFactors = FALSE) # exp4File,stringsAsFactors = FALSE)
X <- join(X1, X2, by = "OrfRep")
X <- join(X, X3, by = "OrfRep")
}
if (length(input_files) >= 4) {
X4 <- read.csv(file = input_files[4], stringsAsFactors = FALSE)
X <- join(X, X4, by = "OrfRep")
OBH <- X[, order(colnames(X))] # OrderByHeader
headSel <- select(OBH, contains("OrfRep"), matches("Gene"),
@@ -103,7 +111,7 @@ REMcRdy <- select(headSel, contains("OrfRep"), matches("Gene"), contains("Z_lm_
shiftOnly <- select(headSel, contains("OrfRep"), matches("Gene"), contains("Z_Shift"))
# Code to replace the numeric (.1 .2 .3) headers with experiment names from StudyInfo.txt
Labels <- read.csv(file = "../Code/StudyInfo.csv", stringsAsFactors = FALSE, sep = ",")
Labels <- read.csv(file = study_info, stringsAsFactors = FALSE, sep = ",")
# Using Text search grepl to relabel headers
REMcRdyHdr <- colnames(REMcRdy)
@@ -168,10 +176,10 @@ Vec7 <- NA
Vec8 <- NA
if (length(REMcRdy) == 6) {
Vec1 <- abs(REMcRdy[, 3]) >= std
Vec2 <- abs(REMcRdy[, 4]) >= std
Vec3 <- abs(REMcRdy[, 5]) >= std
Vec4 <- abs(REMcRdy[, 6]) >= std
Vec1 <- abs(REMcRdy[, 3]) >= sd
Vec2 <- abs(REMcRdy[, 4]) >= sd
Vec3 <- abs(REMcRdy[, 5]) >= sd
Vec4 <- abs(REMcRdy[, 6]) >= sd
bolVec <- Vec1 | Vec2 | Vec3 | Vec4
REMcRdyGT2 <- REMcRdy[bolVec, 1:2]
REMcRdyGT2[, 3:6] <- REMcRdy[bolVec, 3:6]
@@ -180,12 +188,12 @@ if (length(REMcRdy) == 6) {
}
if (length(REMcRdy) == 8) {
Vec1 <- abs(REMcRdy[, 3]) >= std
Vec2 <- abs(REMcRdy[, 4]) >= std
Vec3 <- abs(REMcRdy[, 5]) >= std
Vec4 <- abs(REMcRdy[, 6]) >= std
Vec5 <- abs(REMcRdy[, 7]) >= std
Vec6 <- abs(REMcRdy[, 8]) >= std
Vec1 <- abs(REMcRdy[, 3]) >= sd
Vec2 <- abs(REMcRdy[, 4]) >= sd
Vec3 <- abs(REMcRdy[, 5]) >= sd
Vec4 <- abs(REMcRdy[, 6]) >= sd
Vec5 <- abs(REMcRdy[, 7]) >= sd
Vec6 <- abs(REMcRdy[, 8]) >= sd
bolVec <- Vec1 | Vec2 | Vec3 | Vec4 | Vec5 | Vec6
REMcRdyGT2 <- REMcRdy[bolVec, 1:2]
REMcRdyGT2[, 3:8] <- REMcRdy[bolVec, 3:8]
@@ -194,14 +202,14 @@ if (length(REMcRdy) == 8) {
}
if (length(REMcRdy) == 10) {
Vec1 <- abs(REMcRdy[, 3]) >= std
Vec2 <- abs(REMcRdy[, 4]) >= std
Vec3 <- abs(REMcRdy[, 5]) >= std
Vec4 <- abs(REMcRdy[, 6]) >= std
Vec5 <- abs(REMcRdy[, 7]) >= std
Vec6 <- abs(REMcRdy[, 8]) >= std
Vec7 <- abs(REMcRdy[, 9]) >= std
Vec8 <- abs(REMcRdy[, 10]) >= std
Vec1 <- abs(REMcRdy[, 3]) >= sd
Vec2 <- abs(REMcRdy[, 4]) >= sd
Vec3 <- abs(REMcRdy[, 5]) >= sd
Vec4 <- abs(REMcRdy[, 6]) >= sd
Vec5 <- abs(REMcRdy[, 7]) >= sd
Vec6 <- abs(REMcRdy[, 8]) >= sd
Vec7 <- abs(REMcRdy[, 9]) >= sd
Vec8 <- abs(REMcRdy[, 10]) >= sd
bolVec <- Vec1 | Vec2 | Vec3 | Vec4 | Vec5 | Vec6 | Vec7 | Vec8
REMcRdyGT2 <- REMcRdy[bolVec, 1:2]
REMcRdyGT2[, 3:10] <- REMcRdy[bolVec, 3:10]
@@ -209,12 +217,12 @@ if (length(REMcRdy) == 10) {
shiftOnlyGT2[, 3:10] <- shiftOnly[bolVec, 3:10]
}
if (std != 0) {
if (sd != 0) {
REMcRdy <- REMcRdyGT2 # [,2:length(REMcRdyGT2)]
shiftOnly <- shiftOnlyGT2 # [,2:length(shiftOnlyGT2)]
}
if (std == 0) {
if (sd == 0) {
REMcRdy <- REMcRdy # [,2:length(REMcRdy)]
shiftOnly <- shiftOnly # [,2:length(shiftOnly)]
}
@@ -228,7 +236,7 @@ write.csv(shiftOnly, file.path(out_dir, "Shift_only.csv"), row.names = FALSE, qu
#LabelStd <- read.table(file="./parameters.csv",stringsAsFactors = FALSE,sep = ",")
LabelStd <- read.csv(file = study_info, stringsAsFactors = FALSE)
print(std)
LabelStd[, 4] <- as.numeric(std)
print(sd)
LabelStd[, 4] <- as.numeric(sd)
write.csv(LabelStd, file = file.path(out_dir, "parameters.csv"), row.names = FALSE)
write.csv(LabelStd, file = study_info, row.names = FALSE)