-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeToRunMetaByGene.R
57 lines (32 loc) · 1.64 KB
/
makeToRunMetaByGene.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
library(PharmacoGx)
library(data.table)
method <- "perm"
args <- commandArgs(trailingOnly = TRUE)
myToRunFileName <- args[[1]]
home <- Sys.getenv("HOME")
scratch <- Sys.getenv("SCRATCH")
project <- Sys.getenv("PROJECT")
dataDir <- Sys.getenv("DATA")
myDataDir <- dataDir
mySigDir <- file.path(project, paste0("pearson_",method,"_res"))
myRunDir <- file.path(project, "runlist_files")
## dealing with possibly running in the cloud
containername <- Sys.getenv("containername", unset=NA_character_)
if(!is.na(containername)){
mySigDir <- file.path(containername, mySigDir)
myRunDir <- file.path(containername, myRunDir)
}
# myToRunFileName <- file.path(myRunDir,"geneExpressionMasterToRunList.txt")
toRun <- fread(myToRunFileName, header=FALSE)
colnames(toRun) <- c("Gene", "Tissue", "Drug", "PSet")
toRunFirstStage <- unique(toRun[,.(PSet, Drug, Tissue)])
toRunFirstStage[,sig.file.path := file.path(mySigDir, make.names(paste0("signature_", PSet, "_", Drug, "_", Tissue, ".rds")))]
toRunFirstStage[,sig.obj := lapply(sig.file.path, readRDS)]
# toRunFirstStageRes <- toRunFirstStage[,.(Gene = rownames(sig.obj[[1]]),
# Significant = sig.obj[[1]][,1,"significant"],
# Estimate = sig.obj[[1]][,1,"estimate"]), .(PSet, Drug, Tissue)]
toRunFirstStageRes <- toRunFirstStage[,.(Gene = rownames(sig.obj[[1]]),
Significant = sig.obj[[1]][,1,"significant"]), .(PSet, Drug, Tissue)]
toRunFirstStageRes[,Gene := gsub(Gene, pat="\\..+", rep="")]
toRunFirstStageRes <- merge(toRun, toRunFirstStageRes, by=c("Gene", "Tissue", "Drug", "PSet"), all.x=TRUE)
fwrite(toRunFirstStageRes, file=file.path(myRunDir,"toRunMetaByGene.txt"), sep=",", col.names=FALSE, quote=FALSE)