-
Notifications
You must be signed in to change notification settings - Fork 0
/
processSubtypes.R
82 lines (62 loc) · 2.16 KB
/
processSubtypes.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
getCorData <- function(m, sub = NULL){
if(!is.null(sub)){
return(dplyr::select(as.data.frame(t(m)), any_of(sub)))
} else{
return(as.data.frame(t(m)))
}
}
buildESDF <- function(rds.file, subset){
enrichment.scores <- readRDS(rds.file)
es.df <- getCorData(enrichment.scores, sub = subset)
return(es.df)
}
getSubset <- function(p, n){
return(as.vector(n[grep(pattern = p, n)]))
}
main <- function(fpath, subset){
rds.files <- list.files(path = fpath,pattern = "\\.RDS$", full.names = TRUE)
if(length(rds.files) > 1){
enrichment.scores <- list()
es.df <- list()
for(i in seq_along(rds.files)){
fname <- mesocore::getFileName(rds.files[i])
es.df[[fname]] <- buildESDF(rds.files[i], subset = subset)
}
es.df <- Reduce(cbind, es.df)
res <- data.frame("SampleID" = rownames(es.df), es.df)
} else if(length(rds.files) == 1){
if(!is.null(subset)){
es.df <- buildESDF(rds.files[1], subset = subset)
} else{
es.df <- buildESDF(rds.files[1], subset = NULL)
}
res <- data.frame("SampleID" = rownames(es.df), es.df)
} else{
stop("Missing an enrichment score table. Please provide at least one enrichment score table to subset!")
}
outfolder <- here::here(fpath)
write.csv(res, here::here(outfolder, "enrichment_experiment_df.csv"), row.names = F)
print("Done!")
}
#---- Check Packages ----
pkgs <- c("here", "docopt")
mesocore::handleRequirements(pkgs)
#---- Header ----
"Mesothelioma AI Pipeline - Building the Correlations DF
Usage: survival_analysis.R [options]
Options:
-h --help Show this screen.
-e --enrichment_scores=<PATH> Path to the enrichment scores data frame folder.
-s --subset=<PATH> A .txt file that specifies what subset of ES to select.
"-> doc
#---- Flag Arguments ----
arguments <- docopt(doc, quoted_args = TRUE, help = TRUE)
print(arguments)
fpath <- normalizePath(arguments$enrichment_scores, winslash = "/", mustWork = FALSE)
if(arguments$subset == "NULL"){
subset <- NULL
} else{
subset <- unlist(strsplit(readLines(arguments$subset), ",\\s*"))
}
#---- Main ----
main(fpath, subset)