comparison circleCor_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='Run the circleCor function')
13
14 parser$add_argument('--input_rdata', dest='input_rdata', required=TRUE, help="Input RData file")
15 parser$add_argument('--blocks_vec', dest='blocks_vec', required=TRUE, help="Blocks vector")
16 parser$add_argument('--responses_var', dest='responses_var', required=TRUE, help="Responses variables")
17 parser$add_argument('--x_min', dest='x_min', type='double', required=TRUE, help="X min")
18 parser$add_argument('--x_max', dest='x_max', type='double', required=TRUE, help="X max")
19 parser$add_argument('--y_min', dest='y_min', type='double', required=TRUE, help="Y min")
20 parser$add_argument('--y_max', dest='y_max', type='double', required=TRUE, help="Y max")
21 parser$add_argument('--output_var', dest='output_var', required=TRUE, help="Output variables file")
22 parser$add_argument('--output_pdf', dest='output_pdf', required=TRUE, help="Output PDF file")
23
24 args <- parser$parse_args()
25
26 ## Print parameters
27 print("Input RData:")
28 print(args$input_rdata)
29 print("Blocks vector:")
30 print(args$blocks_vec)
31 print("Response variables:")
32 print(args$responses_var)
33 print("X min:")
34 print(args$x_min)
35 print("X max:")
36 print(args$x_max)
37 print("Y min:")
38 print(args$y_min)
39 print("Y max:")
40 print(args$y_max)
41 print("Output variables file:")
42 print(args$output_var)
43 print("Output PDF file:")
44 print(args$output_pdf)
45
46 names_blocks = strsplit(args$blocks_vec, ",")[[1]]
47 names_response_variables = strsplit(args$responses_var, ",")[[1]]
48
49 print("names_blocks:")
50 print(names_blocks)
51 print("names_response_variables:")
52 print(names_response_variables)
53
54 ## Loading libraries
55 # suppressPackageStartupMessages(require(ellipse))
56 # suppressPackageStartupMessages(require(grDevices))
57 # suppressPackageStartupMessages(require(RColorBrewer))
58 # suppressPackageStartupMessages(require(mixOmics))
59 ## Loading local functions
60 # source_local("mixomics-blocksplsda-integration/integration_block_splsda_func.R")
61 install.packages("https://gitlab.com/bilille/mixomics-blocksplsda-integration/-/raw/master/visCorVar_0.3.tar.gz", repos=NULL)
62 suppressPackageStartupMessages(require(visCorVar))
63 print("visCorVar has been loaded")
64
65 # R script call
66 source_local <- function(fname)
67 {
68 argv <- commandArgs(trailingOnly = FALSE)
69 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
70 source(paste(base_dir, fname, sep="/"))
71 }
72
73 # Loading input Rdata file
74 # loads res_matCorAddVar object
75 load(args$input_rdata)
76
77 mat_cor_comp1 = res_matCorAddVar$mat_cor_comp1
78 mat_cor_comp2 = res_matCorAddVar$mat_cor_comp2
79 cutoff_comp = res_matCorAddVar$cutoff_comp
80 comp = res_matCorAddVar$comp
81 list_vec_index_block_select = res_matCorAddVar$list_vec_index_block_select
82 list_vec_names_blocks = res_matCorAddVar$list_vec_names_blocks
83 list_cor_comp_selected_var_resp_var = res_matCorAddVar$list_cor_comp_selected_var_resp_var
84 res_compute_cor_var_interest = res_matCorAddVar$res_compute_cor_var_interest
85 res_block_splsda = res_matCorAddVar$res_block_splsda
86
87 #
88 print("mat_cor_comp1:")
89 print(mat_cor_comp1)
90 print("mat_cor_comp2:")
91 print(mat_cor_comp2)
92 print("cutoff_comp:")
93 print(cutoff_comp)
94 print("comp:")
95 print(comp)
96 print("list_vec_index_block_select:")
97 print(list_vec_index_block_select)
98 print("list_vec_names_blocks:")
99 print(list_vec_names_blocks)
100 print("list_cor_comp_selected_var_resp_var:")
101 print(list_cor_comp_selected_var_resp_var)
102 print("res_compute_cor_var_interest:")
103 print(res_compute_cor_var_interest)
104
105 # Open output pdf file
106 pdf(args$output_pdf, width=8, height=7)
107 mar = c(5, 5, 2, 8)
108 par(mar = mar)
109
110 selected_variables = circleCor(list_dataframe_cor_comp_var_global = list_cor_comp_selected_var_resp_var,
111 list_vec_index_block_select = list_vec_index_block_select,
112 mat_cor_comp1 = mat_cor_comp1,
113 mat_cor_comp2 = mat_cor_comp2,
114 names_blocks = names_blocks,
115 names_response_variables = names_response_variables,
116 comp = comp,
117 cutoff = 0.85,
118 min.X = args$x_min,
119 max.X = args$x_max,
120 min.Y = args$y_min,
121 max.Y = args$y_max,
122 # vec_col = vec_col,
123 rad.in = 0.5,
124 cex = 0.7,
125 cex_legend = 0.8,
126 pos = c(1.2, 0),
127 pch = 20)
128
129 dev.off()
130
131 write(selected_variables, file=args$output_var, ncolumns=1)