-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetwork_Wrapper.R
More file actions
197 lines (163 loc) · 8.22 KB
/
Network_Wrapper.R
File metadata and controls
197 lines (163 loc) · 8.22 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Calling in Libraries ----------------------------------------------------
system('module load mpi/openmpi-x86_64')
library(dplyr, quietly = TRUE)
library(glmnet, quietly = TRUE)
library(randomForest, quietly = TRUE)
library(Hmisc, quietly = TRUE)
library(lars, quietly = TRUE)
library(WGCNA, quietly = TRUE)
library(synapser, quietly = TRUE)
library(metanetwork, quietly = TRUE)
library(githubr, quietly = TRUE)
library(c3net, quietly = TRUE)
library(config, quietly = TRUE)
library(optparse, quietly = TRUE)
library(data.table, quietly = TRUE)
library(parmigene, quietly = TRUE)
library(reader, quietly = TRUE)
library(Rmpi)
library(parallel)
library(doParallel)
#library(utilityFunctions) -->installation error
# Obtaining the data - From User --------------------------------------------
option_list <- list(make_option(c("-u","--synapse_user"), type="character", action = "store",
help = "Synapse User name"),
make_option(c("-p","--synapse_pass"), type="character", action = "store",
help = "Synapse User Password"),
make_option(c("-c","--config_file"), type="character", action = "store",
help = "Path to the complete config file"))
req_args <- parse_args(OptionParser(option_list=option_list))
# Obtaining the data - From Synapse --------------------------------------------
#Setting up the cofig file
Sys.setenv(R_CONFIG_ACTIVE = "default")
config <- config::get(file = req_args$config_file)
setwd(config$input_profile$temp_storage_loc)
synLogin(email = req_args$synapse_user, password = req_args$synapse_pass)
#Linking with Project
project = Project(config$input_profile$project_id)
project <- synStore(project)
# Data
synID_input = config$input_profile$input_synid
data = synGet(synID_input, downloadLocation = config$input_profile$temp_storage_loc)
# Registering the parallel clusters
if(config$computing_specs$medium_ncores>0){
nslaves = config$computing_specs$medium_ncores
mpi.spawn.Rslaves(nslaves=nslaves,hosts=NULL);
}
if(config$computing_specs$heavy_ncores>0){
nslaves = config$computing_specs$heavy_ncores
mpi.spawn.Rslaves(nslaves=nslaves,hosts=NULL);
}
# Performing the analysis -------------------------------------------------
net_methods = config$input_profile$network_method
data = reader::reader(data$path)
if (is.null(config$input_profile$na_fill)){
print('Data not normalized for missing values. Ignore if using mrnet method.')
} else if (config$input_profile$na_fill == 'Winsorize'){
data <- metanetwork::winsorizeData(data)
}
for (method in net_methods){# Assuming we have more methods - not developing for now
switch(method,
"c3net" = c3netWrapper(data, path = NULL, pval = config$input_profile$p_val_c3net, config$output_profile$output_path),# What does this path define in main function?
"mrnet" = mrnetWrapper(data, path = NULL, pval = config$input_profile$p_val_mrnet, config$output_profile$output_path),
"wgcna" = wgcnaTOM(data, path = NULL, pval = config$input_profile$p_val_wgcna, config$output_profile$output_path,
config$input_profile$rsquaredcut, config$input_profile$defaultnaPower),
"lassoAIC" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"lassoBIC" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"lassoCV1se" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"lassoCVmin" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"ridgeAIC" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"ridgeBIC" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"ridgeCV1se" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"ridgeCVmin" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"sparrowZ" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"sparrow2Z" = mpiWrapper(data, nodes = config$computing_specs$medium_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"genie3" = mpiWrapper(data, nodes = config$computing_specs$heavy_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path),
"tigress" = mpiWrapper(data, nodes = config$computing_specs$heavy_ncores, pathv = NULL, regressionFunction = method,
outputpath = config$output_profile$output_path))
output_filename <- list.files(pattern = method )
}
if(config$computing_specs$heavy_ncores>0){
mpi.close.Rslaves()
}
if(config$computing_specs$medium_ncores>0){
mpi.close.Rslaves()
}
# Obtaining the data - For provenance --------------------------------------------
activity <- synapser::synGet(config$input_profile$project_id)
dataFolder <- Folder(method,parent = config$input_profile$project_id)
dataFolder <- synStore(dataFolder)
for (filePath in output_filename){
file <- File(path = filePath, parent = dataFolder)
file <- synStore(file)
}
all.annotations <- synGetAnnotations(config$input_profile$input_synid)
checkAnnotations <- function(annotations, config){
annot_default <- list(
dataType = NULL,
resourceType = NULL,
metadataType = NULL,
isModelSystem = NULL,
isMultiSpecimen = NULL,
fileFormat = NULL,
grant = NULL,
species = NULL,
organ = NULL,
tissue = NULL,
study = NULL,
consortium = NULL,
assay = NULL
)
for (item in names(annot_default)){
if (!is.null(config$provenance$annotations$item)){
annot_default$item = config$provenance$annotations$item[[1]]
}
else if (!is.null(annotations$item)){
annot_default$item = annotations$item[[1]]
}
}
}
all.annotations <- checkAnnotations(all.annotations,config)
thisRepo = NULL
thisFile = NULL
try(
thisRepo <- githubr::getRepo(
repository = config$provenance$code_annotations$repository,
ref = config$provenance$code_annotations$ref,
refName = config$provenance$code_annotations$ref_name
), silent = TRUE
)
try(
thisFile <- githubr::getPermlink(
repository = thisRepo,
repositoryPath = config$provenance$code_annotations$repository_path
), silent = TRUE
)
ENRICH_OBJ <- synapser::synStore( synapser::File(
path = output_filename[length(output_filename)],
name = config$output_profile$output_name,
parentId = activity$properties$id),
used = config$input_profile$input_synid,
activityName = config$provenance$activity_name,
executed = thisFile,
activityDescription = config$provenance$activity_description
)
synapser::synSetAnnotations(ENRICH_OBJ, annotations = all.annotations)
# Formatting the network to md5 format --------------------------------------------
md5Command <- paste0('md5sum ', output_filename[length(output_filename)])
md5 <- strsplit(system(md5Command, intern = TRUE), ' ')[[1]][1]
cat(md5, '\n', file = config$output_profile$md5_output_path, sep = '')
if((!is.na(config$computing_specs$heavy_ncores)) || (!is.na(config$computing_specs$medium_ncores))){
mpi.quit(save = "no")
}