comparison matCorAddVar_wrapper.R @ 0:d0b77b926863 draft

"planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
author ppericard
date Tue, 23 Jun 2020 19:57:35 -0400
parents
children e93350dc99f1
comparison
equal deleted inserted replaced
-1:000000000000 0:d0b77b926863
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 # source_local("mixomics-blocksplsda-integration/integration_block_splsda_func.R")
42 install.packages("https://gitlab.com/bilille/mixomics-blocksplsda-integration/-/raw/master/visCorVar_0.3.tar.gz", repos=NULL)
43 suppressPackageStartupMessages(require(visCorVar))
44 print("visCorVar has been loaded")
45
46 # R script call
47 source_local <- function(fname)
48 {
49 argv <- commandArgs(trailingOnly = FALSE)
50 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
51 source(paste(base_dir, fname, sep="/"))
52 }
53
54 # Loading input Rdata file
55 load(args$input_rdata)
56
57 ncomp = mixomics_result$ncomp
58
59 # Reading Block Y matrix
60 print("Reading Block Y")
61 mat_block_Y = read.table(args$block_Y_file, header=TRUE, row.names=1)
62 print(mat_block_Y)
63
64 response_var = colnames(mat_block_Y)
65
66 print("response_var:")
67 print(response_var)
68
69 # Write response variables to output file
70 invisible(lapply(response_var, write, file=args$output_response_var, append=TRUE, ncolumns=1))
71
72 # Reading var of intereset file
73 interest_var_vec = NULL
74 if (args$interest_var_file != 'None') {
75 interest_var_vec = as.character(read.table(args$interest_var_file, header=FALSE)[[1]])
76 }
77
78 #
79 comp = 1:2
80
81 # Running main function
82 res_matCorAddVar = matCorAddVar(res_block_splsda = mixomics_result,
83 block_Y = mat_block_Y,
84 cutoff_comp = args$cutoff_comp,
85 var_interest = interest_var_vec,
86 comp = comp)
87
88 #
89 mat_cor_comp1 = res_matCorAddVar$mat_cor_comp1
90 mat_cor_comp2 = res_matCorAddVar$mat_cor_comp2
91 list_vec_index_block_select = res_matCorAddVar$list_vec_index_block_select
92 list_vec_names_blocks = res_matCorAddVar$list_vec_names_blocks
93 list_cor_comp_selected_var_resp_var = res_matCorAddVar$list_cor_comp_selected_var_resp_var
94 res_compute_cor_var_interest = res_matCorAddVar$res_compute_cor_var_interest
95
96 #
97 print("mat_cor_comp1:")
98 print(mat_cor_comp1)
99 print("mat_cor_comp2:")
100 print(mat_cor_comp2)
101 print("list_vec_index_block_select:")
102 print(list_vec_index_block_select)
103 print("list_vec_names_blocks:")
104 print(list_vec_names_blocks)
105 print("list_cor_comp_selected_var_resp_var:")
106 print(list_cor_comp_selected_var_resp_var)
107 print("res_compute_cor_var_interest:")
108 print(res_compute_cor_var_interest)
109
110 # Write all possible blocks combinations to output file
111 invisible(lapply(list_vec_names_blocks, write, file=args$output_blocks_comb, append=TRUE, ncolumns=100, sep=","))
112
113 # Save all objects in Rdata output file
114 save(res_matCorAddVar,
115 file = args$output_rdata)