Jun 21, 2016
Fix param
|
|
|
1 |
#(1) Setup paths and environment. |
|
2 |
library(BTR) |
|
3 |
library(doParallel) |
|
4 |
|
|
5 |
path='~/btr_output/' |
|
6 |
setwd(path) |
|
7 |
|
|
8 |
inter_bool = T |
|
9 |
max_varperrule = 6 |
|
10 |
acyclic = T |
|
11 |
initial_model = F |
|
12 |
single_cell = F |
|
13 |
|
|
14 |
#Setting up for parallel processing. |
|
15 |
num_cores = 4 |
|
16 |
registerDoParallel(cores=num_cores) #this automatically calls mclapply() when no cl is given. |
|
17 |
|
|
18 |
#Setting random seed for reproducibility. |
|
19 |
set.seed(1) |
|
20 |
|
|
21 |
test_result = c() |
|
22 |
#file_ind = 1 |
|
23 |
for(file_ind in 1:5) |
|
24 |
{ |
|
25 |
#Load data. |
|
26 |
load(paste(path, ifelse(acyclic, 'acyclic', 'cyclic'), '_data/test_data_yeast', file_ind,'_20n30s10g.rda', sep='')) #test_data. |
|
27 |
|
|
28 |
#Making model inference. |
|
29 |
start_time = proc.time() |
|
30 |
if(initial_model) |
|
31 |
{ |
|
32 |
ind_i = sample(seq(1,length(test_data$bm_modmodel)), 1) |
|
33 |
ind_j = 5 |
|
34 |
if(single_cell) |
|
35 |
{ |
|
36 |
result = model_train(cdata=test_data$sc_cdata, bmodel=test_data$bm_modmodel[[ind_i]][[ind_j]], istate=test_data$istate, and_bool=inter_bool, verbose=T, self_loop=F) |
|
37 |
} else |
|
38 |
{ |
|
39 |
result = model_train(cdata=test_data$cdata, bmodel=test_data$bm_modmodel[[ind_i]][[ind_j]], istate=test_data$istate, and_bool=inter_bool, verbose=T, self_loop=F) |
|
40 |
} |
|
41 |
} else |
|
42 |
{ |
|
43 |
if(single_cell) |
|
44 |
{ |
|
45 |
result = model_train(cdata=test_data$sc_cdata, istate=test_data$istate, and_bool=inter_bool, verbose=T, self_loop=F) |
|
46 |
} else |
|
47 |
{ |
|
48 |
result = model_train(cdata=test_data$cdata, istate=test_data$istate, and_bool=inter_bool, verbose=T, self_loop=F) |
|
49 |
} |
|
50 |
} |
|
51 |
adj_mat = abs(bm_to_amat(result)) |
|
52 |
end_time = proc.time() |
|
53 |
time_taken = end_time - start_time |
|
54 |
|
|
55 |
#Perform model validation. |
|
56 |
true_adj_mat = abs(test_data$true_amat) |
|
57 |
val_res = validate_adjmat(adj_mat, true_adj_mat) |
|
58 |
perf_score = calc_roc(val_res) |
|
59 |
|
|
60 |
#Record results. |
|
61 |
tmp = c(list(true_adj_mat=true_adj_mat), list(adj_mat=adj_mat), list(perf_score=perf_score), list(time_taken=time_taken)) |
|
62 |
test_result = c(test_result, list(tmp)) |
|
63 |
} |
|
64 |
|
|
65 |
#Open file connection for writing output. |
|
66 |
file_name = paste('result_btr-', ifelse(initial_model, 'wi', 'wo'), '_train_', ifelse(acyclic, 'acyclic_', 'cyclic_'), ifelse(single_cell, 'sc', 'nonsc'), '_yeast1.rda', sep='') |
|
67 |
save(test_result, file=file_name) |
|
68 |
|
|
69 |
#Cleaning up. |
|
70 |
stopImplicitCluster() |