comparison viscorvar_matcoraddvar.R @ 2:c8533e9298e5 draft

"planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 8cb5630238352459037b3647eebfabb5554566f6-dirty"
author ppericard
date Fri, 23 Oct 2020 10:15:56 +0000
parents
children
comparison
equal deleted inserted replaced
1:e93350dc99f1 2:c8533e9298e5
1 #!/usr/bin/env Rscript
2
3 # Setup R error handling to go to stderr
4 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
5
6 # we need that to not crash galaxy with an UTF8 error on German LC settings.
7 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
8
9 ## Get parameters ##
10 suppressPackageStartupMessages(require(argparse))
11
12 parser <- ArgumentParser(description='Compute the matCorEtBlockSelect and addVariablesReponses functions')
13
14 parser$add_argument('--input_rdata', dest='input_rdata', required=TRUE, help="Input RData file")
15 parser$add_argument('--cutoff_comp', dest='cutoff_comp', type='double', required=TRUE, help="")
16 parser$add_argument('--interest_var_file', dest='interest_var_file', required=FALSE, help="Variables of interest file")
17 parser$add_argument('--block_Y_file', dest='block_Y_file', required=TRUE, help="Block Y filepath")
18 parser$add_argument('--output_rdata', dest='output_rdata', required=TRUE, help="Output RData file")
19 parser$add_argument('--output_response_var', dest='output_response_var', required=TRUE, help="Output response variables file")
20 parser$add_argument('--output_blocks_comb', dest='output_blocks_comb', required=TRUE, help="Output blocks combinations file")
21
22 args <- parser$parse_args()
23
24 ## Print parameters
25 print("Input RData:")
26 print(args$input_rdata)
27 print("Cutoff comp:")
28 print(args$cutoff_comp)
29 print("Variables of interest:")
30 print(args$interest_var_file)
31 print("Block Y file:")
32 print(args$block_Y_file)
33 print("Output RData:")
34 print(args$output_rdata)
35 print("Output Response variables:")
36 print(args$output_response_var)
37 print("Output Blocks combinations:")
38 print(args$output_blocks_comb)
39
40 ## Loading libraries
41 suppressPackageStartupMessages(require(visCorVar))
42
43 # R script call
44 source_local <- function(fname)
45 {
46 argv <- commandArgs(trailingOnly = FALSE)
47 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
48 source(paste(base_dir, fname, sep="/"))
49 }
50
51 # Loading input Rdata file
52 load(args$input_rdata)
53
54 ncomp = mixomics_result$ncomp
55
56 # Reading Block Y matrix
57 print("Reading Block Y")
58 mat_block_Y = read.table(args$block_Y_file, header=TRUE, row.names=1)
59 print(mat_block_Y)
60
61 response_var = colnames(mat_block_Y)
62
63 print("response_var:")
64 print(response_var)
65
66 # Write response variables to output file
67 invisible(lapply(response_var, write, file=args$output_response_var, append=TRUE, ncolumns=1))
68
69 # Reading var of intereset file
70 interest_var_vec = NULL
71 if (args$interest_var_file != 'None') {
72 interest_var_vec = as.character(read.table(args$interest_var_file, header=FALSE)[[1]])
73 }
74
75 #
76 comp = 1:2
77
78 # Running main function
79 res_matCorAddVar = matCorAddVar(res_block_splsda = mixomics_result,
80 block_Y = mat_block_Y,
81 cutoff_comp = args$cutoff_comp,
82 var_interest = interest_var_vec,
83 comp = comp)
84
85 #
86 mat_cor_comp1 = res_matCorAddVar$mat_cor_comp1
87 mat_cor_comp2 = res_matCorAddVar$mat_cor_comp2
88 list_vec_index_block_select = res_matCorAddVar$list_vec_index_block_select
89 list_vec_names_blocks = res_matCorAddVar$list_vec_names_blocks
90 list_cor_comp_selected_var_resp_var = res_matCorAddVar$list_cor_comp_selected_var_resp_var
91 res_compute_cor_var_interest = res_matCorAddVar$res_compute_cor_var_interest
92
93 #
94 print("mat_cor_comp1:")
95 print(mat_cor_comp1)
96 print("mat_cor_comp2:")
97 print(mat_cor_comp2)
98 print("list_vec_index_block_select:")
99 print(list_vec_index_block_select)
100 print("list_vec_names_blocks:")
101 print(list_vec_names_blocks)
102 print("list_cor_comp_selected_var_resp_var:")
103 print(list_cor_comp_selected_var_resp_var)
104 print("res_compute_cor_var_interest:")
105 print(res_compute_cor_var_interest)
106
107 # Write all possible blocks combinations to output file
108 invisible(lapply(list_vec_names_blocks, write, file=args$output_blocks_comb, append=TRUE, ncolumns=100, sep=","))
109
110 # Save all objects in Rdata output file
111 save(res_matCorAddVar,
112 file = args$output_rdata)