Mercurial > repos > ppericard > viscorvar
comparison mixomics_blocksplsda_script.R @ 1:e93350dc99f1 draft
"planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 1eda261d4fe137d6e8806b0c6af7eaf12d11ac95"
author | ppericard |
---|---|
date | Thu, 15 Oct 2020 12:22:25 +0000 |
parents | d0b77b926863 |
children |
comparison
equal
deleted
inserted
replaced
0:d0b77b926863 | 1:e93350dc99f1 |
---|---|
34 parser$add_argument('--tol', dest='tol', type='double', default=1e-06, | 34 parser$add_argument('--tol', dest='tol', type='double', default=1e-06, |
35 help="Convergence stopping value") | 35 help="Convergence stopping value") |
36 parser$add_argument('--nearzerovar', dest='nearzerovar', action="store_true", | 36 parser$add_argument('--nearzerovar', dest='nearzerovar', action="store_true", |
37 help="Should be set in particular for data with many zero values") | 37 help="Should be set in particular for data with many zero values") |
38 parser$add_argument('--rdata_out', dest='rdata_out', required=TRUE, help="Output Rdata file") | 38 parser$add_argument('--rdata_out', dest='rdata_out', required=TRUE, help="Output Rdata file") |
39 parser$add_argument('--sample_metadata_out', dest='sample_metadata_out', required=TRUE, help="Output sample metadata file") | 39 # parser$add_argument('--sample_metadata_out', dest='sample_metadata_out', required=TRUE, help="Output sample metadata file") |
40 parser$add_argument('--variable_metadata_outdir', dest='variable_metadata_outdir', required=TRUE, help="Output variable metadata directory") | 40 parser$add_argument('--variable_metadata_outdir', dest='variable_metadata_outdir', required=TRUE, help="Output variable metadata directory") |
41 | 41 |
42 args <- parser$parse_args() | 42 args <- parser$parse_args() |
43 | 43 |
44 ## Print parameters | 44 ## Print parameters |
66 print(args$tol) | 66 print(args$tol) |
67 print("near.zero.var:") | 67 print("near.zero.var:") |
68 print(args$nearzerovar) | 68 print(args$nearzerovar) |
69 print("Output Rdata file:") | 69 print("Output Rdata file:") |
70 print(args$rdata_out) | 70 print(args$rdata_out) |
71 print("Output sample metadata file:") | 71 # print("Output sample metadata file:") |
72 print(args$sample_metadata_out) | 72 # print(args$sample_metadata_out) |
73 print("Output variable metadata directory:") | 73 print("Output variable metadata directory:") |
74 print(args$variable_metadata_outdir) | 74 print(args$variable_metadata_outdir) |
75 | 75 |
76 ## Loading libraries | 76 ## Loading libraries |
77 suppressPackageStartupMessages(require(mixOmics)) | 77 suppressPackageStartupMessages(require(mixOmics)) |
115 # print(block_data_matrix_names) | 115 # print(block_data_matrix_names) |
116 | 116 |
117 if(!identical(sample_metadata_names, block_data_matrix_names)) | 117 if(!identical(sample_metadata_names, block_data_matrix_names)) |
118 { | 118 { |
119 stop("Sample names must be the same and in the same order in the sample metadata matrix and the block data matrix") | 119 stop("Sample names must be the same and in the same order in the sample metadata matrix and the block data matrix") |
120 } | |
121 | |
122 if(any(is.na(block_data_matrix))) | |
123 { | |
124 stop(sprintf("Block %s contains missing values. We recommend not to perform data integration with missing values. If you want to force run, change the advanced parameter 'Check for missing values' to 'No'.", block_name)) | |
120 } | 125 } |
121 | 126 |
122 list_X[[block_name]] <- block_data_matrix | 127 list_X[[block_name]] <- block_data_matrix |
123 | 128 |
124 # Set the nb of variables to keep | 129 # Set the nb of variables to keep |
173 print(attributes(mixomics_result)) | 178 print(attributes(mixomics_result)) |
174 | 179 |
175 ## Save output Rdata file | 180 ## Save output Rdata file |
176 save(mixomics_result, file=args$rdata_out) | 181 save(mixomics_result, file=args$rdata_out) |
177 | 182 |
183 # R script call | |
184 source_local <- function(fname) | |
185 { | |
186 argv <- commandArgs(trailingOnly = FALSE) | |
187 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | |
188 source(paste(base_dir, fname, sep="/")) | |
189 } | |
190 | |
191 # Load library | |
192 source_local("additional_functions_block_splsda.R") | |
193 | |
194 | |
195 | |
196 list_union_selected_block_variables = unionSelectBlockVariables(mixomics_result) | |
197 | |
178 ## Save output sample metadata file | 198 ## Save output sample metadata file |
179 # print("Block.splsda variates:") | 199 # print("Block.splsda variates:") |
180 # print(mixomics_result$variates) | 200 # print(mixomics_result$variates) |
181 | 201 |
182 for(block_name in names(mixomics_result$variates)) | 202 # for(block_name in names(mixomics_result$variates)) |
183 { | 203 # { |
184 # print(block_name) | 204 # # print(block_name) |
185 # print(mixomics_result$variates[[block_name]]) | 205 # # print(mixomics_result$variates[[block_name]]) |
186 | 206 |
187 # Format the column names to add the block name and replace spaces | 207 # # Format the column names to add the block name and replace spaces |
188 colnames(mixomics_result$variates[[block_name]]) <- paste("block.splsda_variates", block_name, gsub(" ", "_", colnames(mixomics_result$variates[[block_name]])), sep = "_") | 208 # colnames(mixomics_result$variates[[block_name]]) <- paste("block.splsda_variates", block_name, gsub(" ", "_", colnames(mixomics_result$variates[[block_name]])), sep = "_") |
189 # print(mixomics_result$variates[[block_name]]) | 209 # # print(mixomics_result$variates[[block_name]]) |
190 | 210 |
191 # Append the new columns to the sample metadata matrix | 211 # # Append the new columns to the sample metadata matrix |
192 sample_metadata <- cbind2(sample_metadata, mixomics_result$variates[[block_name]]) | 212 # sample_metadata <- cbind2(sample_metadata, mixomics_result$variates[[block_name]]) |
193 } | 213 # } |
194 | 214 |
195 # print(sample_metadata) | 215 # print(sample_metadata) |
196 | 216 |
197 write.table(sample_metadata, file = args$sample_metadata_out, quote = TRUE, sep = "\t", row.names = TRUE, col.names = NA) | 217 # write.table(sample_metadata, file = args$sample_metadata_out, quote = TRUE, sep = "\t", row.names = TRUE, col.names = NA) |
198 | 218 |
199 ## Save output variable metadata files in output directory | 219 ## Save output variable metadata files in output directory |
200 # print("Block.splsda loadings:") | 220 # print("Block.splsda loadings:") |
201 # print(mixomics_result$loadings) | 221 # print(mixomics_result$loadings) |
202 | 222 |
208 # block_data_matrix_filename <- args$blocks_list[i,3] | 228 # block_data_matrix_filename <- args$blocks_list[i,3] |
209 block_meta_var <- args$blocks_list[i,4] | 229 block_meta_var <- args$blocks_list[i,4] |
210 | 230 |
211 print(sprintf("Saving block %s output metavar", block_name)) | 231 print(sprintf("Saving block %s output metavar", block_name)) |
212 | 232 |
213 meta_variable <- mixomics_result$loadings[[block_name]] | 233 |
234 meta_variable <- list_union_selected_block_variables[[i]] | |
235 colnames(meta_variable) <- "block.splsda_var_select" | |
236 | |
237 # meta_variable <- mixomics_result$loadings[[block_name]] | |
214 # print(head(meta_variable)) | 238 # print(head(meta_variable)) |
215 | 239 |
216 # Format the column names to add the block name and replace spaces | 240 # Format the column names to add the block name and replace spaces |
217 colnames(meta_variable) <- paste("block.splsda_loadings", gsub(" ", "_", colnames(meta_variable)), sep = "_") | 241 # colnames(meta_variable) <- paste("block.splsda_loadings", gsub(" ", "_", colnames(meta_variable)), sep = "_") |
218 | 242 |
219 # Read input block variable metadata files if provided (optional) | 243 # Read input block variable metadata files if provided (optional) |
220 if(block_meta_var != "None") | 244 if(block_meta_var != "None") |
221 { | 245 { |
222 input_meta_variable <- read.table(block_meta_var, sep='\t', header=TRUE, row.names=1) | 246 input_meta_variable <- read.table(block_meta_var, sep='\t', header=TRUE, row.names=1) |