comparison viscorvar_circlecor.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='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(visCorVar))
56
57 # R script call
58 source_local <- function(fname)
59 {
60 argv <- commandArgs(trailingOnly = FALSE)
61 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
62 source(paste(base_dir, fname, sep="/"))
63 }
64
65 # Loading input Rdata file
66 # loads res_matCorAddVar object
67 load(args$input_rdata)
68
69 mat_cor_comp1 = res_matCorAddVar$mat_cor_comp1
70 mat_cor_comp2 = res_matCorAddVar$mat_cor_comp2
71 cutoff_comp = res_matCorAddVar$cutoff_comp
72 comp = res_matCorAddVar$comp
73 list_vec_index_block_select = res_matCorAddVar$list_vec_index_block_select
74 list_vec_names_blocks = res_matCorAddVar$list_vec_names_blocks
75 list_cor_comp_selected_var_resp_var = res_matCorAddVar$list_cor_comp_selected_var_resp_var
76 res_compute_cor_var_interest = res_matCorAddVar$res_compute_cor_var_interest
77 res_block_splsda = res_matCorAddVar$res_block_splsda
78
79 #
80 print("mat_cor_comp1:")
81 print(mat_cor_comp1)
82 print("mat_cor_comp2:")
83 print(mat_cor_comp2)
84 print("cutoff_comp:")
85 print(cutoff_comp)
86 print("comp:")
87 print(comp)
88 print("list_vec_index_block_select:")
89 print(list_vec_index_block_select)
90 print("list_vec_names_blocks:")
91 print(list_vec_names_blocks)
92 print("list_cor_comp_selected_var_resp_var:")
93 print(list_cor_comp_selected_var_resp_var)
94 print("res_compute_cor_var_interest:")
95 print(res_compute_cor_var_interest)
96
97 # Open output pdf file
98 pdf(args$output_pdf, width=8, height=7)
99 mar = c(5, 5, 2, 8)
100 par(mar = mar)
101
102 selected_variables = circleCor(list_dataframe_cor_comp_var_global = list_cor_comp_selected_var_resp_var,
103 list_vec_index_block_select = list_vec_index_block_select,
104 mat_cor_comp1 = mat_cor_comp1,
105 mat_cor_comp2 = mat_cor_comp2,
106 names_blocks = names_blocks,
107 names_response_variables = names_response_variables,
108 comp = comp,
109 cutoff = 0.80,
110 min.X = args$x_min,
111 max.X = args$x_max,
112 min.Y = args$y_min,
113 max.Y = args$y_max,
114 # vec_col = vec_col,
115 rad.in = 0.5,
116 cex = 0.7,
117 cex_legend = 0.8,
118 pos = c(1.2, 0),
119 pch = 20)
120
121 dev.off()
122
123 write(selected_variables, file=args$output_var, ncolumns=1)