123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- library(plyr)
- library(dplyr)
- library(sos)
- args <- commandArgs(TRUE)
- if (length(args) >= 1) {
- finalTable <- file.path(args[1])
- } else {
- finalTable <- "REMcRdy_lm_only.csv-finalTable.csv"
- }
- if (length(args) >= 2) {
- shiftFile <- file.path(args[2])
- } else {
- shiftFile <- "Shift_only.csv"
- }
- if (length(args) >= 3) {
- studyInfo <- file.path(args[3])
- } else {
- studyInfo <- "../Code/StudyInfo.csv"
- }
- if (length(args) >= 4) {
- output <- file.path(args[4])
- } else {
- output <- "REMcHeatmaps/REMcWithShift.csv"
- }
- X <- data.frame(read.csv(file = finalTable, header = TRUE, stringsAsFactors = FALSE))
- Y <- data.frame(read.csv(file = shiftFile, header = TRUE, stringsAsFactors = FALSE))
- Labels <- read.delim(studyInfo, skip = 0, as.is = TRUE, row.names = 1, strip.white = TRUE)
- Xcolnum <- length(X[1, ])
- ADDnum <- Xcolnum + length(Y[1, ]) - 2
- Xtemp <- X
- Xtemp[, (Xcolnum + 1):ADDnum] <- NA
- shiftTbl < - as.data.frame(matrix(nrow = 1, ncol = length(Y) - 2))
- for (i in 1:length(X[, 1])) {
- Shiftrownum <- match(X[i, 2], Y[, 1])
- shiftTbl[i, ] <- Y[Shiftrownum, 3:length(Y[1, ])]
- Xtemp[i, (Xcolnum + 1):ADDnum] <- Y[Shiftrownum, 3:length(Y[1, ])]
- }
- headerX <- colnames(Xtemp)
- headerY <- colnames(Y)
- shfHdr <- headerY[3:length(headerY)]
- combTbl <- X[, 1:3]
- lmTbl <- select(Xtemp, contains("Z_lm"))
- shiftTbl <- select(Xtemp, contains("V"))
- clustTbl <- select(Xtemp, contains("cluster."))
- Xcols <- colnames(X)
- Ycols <- colnames(Y)[3:length(Y[1, ])]
- newCols <- c(Xcols[1:Xcolnum], Ycols)
- combI <- combTbl
- headersRemc <- newCols
- newHeaders <- newCols[1:3]
- lmHdr <- colnames(lmTbl)
- clstHdr <- colnames(clustTbl)
- intLvHdr <- vector()
- for (i in 1:(length(shiftTbl[1, ]))) {
- combI <- cbind.data.frame(combI, shiftTbl[i])
- combI <- cbind.data.frame(combI, lmTbl[i])
- intLvHdrx <- c(shfHdr[i], lmHdr[i])
- intLvHdr <- c(intLvHdr, intLvHdrx)
- }
- combIHdr <- c(colnames(combTbl), intLvHdr, clstHdr)
- combI <- cbind.data.frame(combI, clustTbl)
- colnames(combI) <- combIHdr
- write.csv(combI, file = output, row.names = FALSE)
|