annotate mixomics_blocksplsda_script.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
1 #!/usr/bin/env Rscript
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
2
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
3 # Setup R error handling to go to stderr
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
4 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
5
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
6 # we need that to not crash galaxy with an UTF8 error on German LC settings.
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
7 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
8
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
9 ## Get parameters ##
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
10 suppressPackageStartupMessages(require(argparse))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
11
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
12 parser <- ArgumentParser(description='Run the mixOmics block.splsda function')
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
13
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
14 parser$add_argument('--block', dest='blocks_list', nargs=4, action="append", required=TRUE,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
15 help="Block name + nb variables to select + data matrix file + variables metadata file")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
16 parser$add_argument('--sample_metadata_in', dest='sample_metadata_in', required=TRUE,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
17 help="Samples metadata file")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
18 parser$add_argument('--sample_description_col', dest='sample_description_col', type='integer',
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
19 default=0, help="Sample description column number")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
20 parser$add_argument('--ncomp', dest='ncomp', type='integer', default=2,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
21 help="Number of components to include in the model")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
22 parser$add_argument('--correlation', dest='correlation', action="store_true",
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
23 help="Add correlation between all blocks")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
24 parser$add_argument('--scheme', dest='scheme', default="horst", help="Scheme")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
25 parser$add_argument('--mode', dest='mode', default="regression", help="Mode")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
26 parser$add_argument('--maxiter', dest='maxiter', type='integer', default=100,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
27 help="Maximum number of iterations")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
28 parser$add_argument('--scale', dest='scale', action="store_true",
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
29 help="Each block is standardized to zero means and unit variances")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
30 parser$add_argument('--check_missing_values', dest='check_missing_values', action="store_true",
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
31 help="Check for missing values and raise an error")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
32 parser$add_argument('--init', dest='init', default="svd",
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
33 help="Init (svd or svd.single)")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
34 parser$add_argument('--tol', dest='tol', type='double', default=1e-06,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
35 help="Convergence stopping value")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
36 parser$add_argument('--nearzerovar', dest='nearzerovar', action="store_true",
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
37 help="Should be set in particular for data with many zero values")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
38 parser$add_argument('--rdata_out', dest='rdata_out', required=TRUE, help="Output Rdata file")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
39 parser$add_argument('--sample_metadata_out', dest='sample_metadata_out', required=TRUE, help="Output sample metadata file")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
40 parser$add_argument('--variable_metadata_outdir', dest='variable_metadata_outdir', required=TRUE, help="Output variable metadata directory")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
41
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
42 args <- parser$parse_args()
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
43
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
44 ## Print parameters
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
45 print("Blocks:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
46 print(args$blocks_list)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
47 print("Sample metadata file:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
48 print(args$sample_metadata_in)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
49 print("Sample description column number:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
50 print(args$sample_description_col)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
51 print("Number of components:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
52 print(args$ncomp)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
53 print("Compute correlation between all blocks:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
54 print(args$correlation)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
55 print("Scheme:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
56 print(args$scheme)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
57 print("Mode:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
58 print(args$mode)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
59 print("Max nb of iterations:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
60 print(args$maxiter)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
61 print("Scale:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
62 print(args$scale)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
63 print("Check for missing values:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
64 print(args$check_missing_values)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
65 print("Tol:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
66 print(args$tol)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
67 print("near.zero.var:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
68 print(args$nearzerovar)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
69 print("Output Rdata file:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
70 print(args$rdata_out)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
71 print("Output sample metadata file:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
72 print(args$sample_metadata_out)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
73 print("Output variable metadata directory:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
74 print(args$variable_metadata_outdir)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
75
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
76 ## Loading libraries
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
77 suppressPackageStartupMessages(require(mixOmics))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
78
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
79 ## Read sample metadata file and set description factor matrix
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
80 sample_metadata <- read.table(args$sample_metadata_in, sep='\t', header=TRUE, row.names=1)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
81 sample_metadata_names <- row.names(sample_metadata)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
82 # print(sample_metadata_names)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
83
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
84 # print("Sample metadata matrix:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
85 # print(head(sample_metadata))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
86
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
87 description_column <- ncol(sample_metadata)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
88 if(args$sample_description_col > 0)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
89 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
90 description_column <- args$sample_description_col
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
91 }
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
92
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
93 Y <- factor(sample_metadata[[description_column]])
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
94
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
95 print("Y factor matrix:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
96 print(Y)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
97
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
98 ## Read and prepare block datasets
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
99 list_X <- c()
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
100 keepX <- c()
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
101
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
102 for(i in 1:nrow(args$blocks_list))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
103 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
104 # Read block input parameters
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
105 block_name <- args$blocks_list[i,1]
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
106 block_keep <- strtoi(args$blocks_list[i,2])
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
107 block_data_matrix_filename <- args$blocks_list[i,3]
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
108 # block_meta_var <- args$blocks_list[i,4]
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
109
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
110 print(sprintf("Processing block %s", block_name))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
111
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
112 # Store block data matrices
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
113 block_data_matrix <- t(read.table(block_data_matrix_filename, sep='\t', header=TRUE, row.names=1)) # transpose the matrix so that the samples become rows and the variables become columns
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
114 block_data_matrix_names <- row.names(block_data_matrix)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
115 # print(block_data_matrix_names)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
116
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
117 if(!identical(sample_metadata_names, block_data_matrix_names))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
118 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
119 stop("Sample names must be the same and in the same order in the sample metadata matrix and the block data matrix")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
120 }
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
121
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
122 list_X[[block_name]] <- block_data_matrix
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
123
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
124 # Set the nb of variables to keep
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
125 nb_variables = ncol(list_X[[block_name]])
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
126 if(block_keep > 0)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
127 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
128 keepX[[block_name]] <- rep(block_keep, args$ncomp)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
129 }
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
130 else
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
131 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
132 keepX[[block_name]] <- rep(nb_variables, args$ncomp)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
133 }
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
134 print(sprintf("Block %s contains %d variables and %d will be selected", block_name, nb_variables, block_keep))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
135 }
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
136
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
137 # print(list_X)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
138
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
139 ## Generate design matrix
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
140 block_nb <- nrow(args$blocks_list)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
141
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
142 design <- matrix(0, nrow = block_nb, ncol = block_nb)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
143
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
144 if(args$correlation)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
145 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
146 design <- matrix(1, nrow = block_nb, ncol = block_nb)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
147 diag(design) <- 0
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
148 }
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
149
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
150 # print("Design matrix:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
151 # print(design)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
152
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
153 ###################
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
154 ## Main function ##
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
155 ###################
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
156
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
157 mixomics_result <- block.splsda(X = list_X,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
158 Y = Y,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
159 ncomp = args$ncomp,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
160 keepX = keepX,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
161 design = design,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
162 scheme = args$scheme,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
163 mode = args$mode,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
164 scale = args$scale,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
165 init = args$init,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
166 tol = args$tol,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
167 max.iter = args$maxiter,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
168 near.zero.var = args$nearzerovar,
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
169 all.outputs = TRUE)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
170
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
171 print("Block.splsda object:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
172 print(mixomics_result)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
173 print(attributes(mixomics_result))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
174
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
175 ## Save output Rdata file
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
176 save(mixomics_result, file=args$rdata_out)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
177
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
178 ## Save output sample metadata file
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
179 # print("Block.splsda variates:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
180 # print(mixomics_result$variates)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
181
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
182 for(block_name in names(mixomics_result$variates))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
183 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
184 # print(block_name)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
185 # print(mixomics_result$variates[[block_name]])
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
186
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
187 # Format the column names to add the block name and replace spaces
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
188 colnames(mixomics_result$variates[[block_name]]) <- paste("block.splsda_variates", block_name, gsub(" ", "_", colnames(mixomics_result$variates[[block_name]])), sep = "_")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
189 # print(mixomics_result$variates[[block_name]])
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
190
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
191 # Append the new columns to the sample metadata matrix
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
192 sample_metadata <- cbind2(sample_metadata, mixomics_result$variates[[block_name]])
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
193 }
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
194
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
195 # print(sample_metadata)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
196
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
197 write.table(sample_metadata, file = args$sample_metadata_out, quote = TRUE, sep = "\t", row.names = TRUE, col.names = NA)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
198
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
199 ## Save output variable metadata files in output directory
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
200 # print("Block.splsda loadings:")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
201 # print(mixomics_result$loadings)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
202
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
203 for(i in 1:nrow(args$blocks_list))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
204 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
205 # Read again block input parameters
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
206 block_name <- args$blocks_list[i,1]
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
207 # block_keep <- strtoi(args$blocks_list[i,2])
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
208 # block_data_matrix_filename <- args$blocks_list[i,3]
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
209 block_meta_var <- args$blocks_list[i,4]
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
210
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
211 print(sprintf("Saving block %s output metavar", block_name))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
212
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
213 meta_variable <- mixomics_result$loadings[[block_name]]
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
214 # print(head(meta_variable))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
215
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
216 # Format the column names to add the block name and replace spaces
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
217 colnames(meta_variable) <- paste("block.splsda_loadings", gsub(" ", "_", colnames(meta_variable)), sep = "_")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
218
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
219 # Read input block variable metadata files if provided (optional)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
220 if(block_meta_var != "None")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
221 {
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
222 input_meta_variable <- read.table(block_meta_var, sep='\t', header=TRUE, row.names=1)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
223 # print(head(input_meta_variable))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
224
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
225 # Append the new columns to the variable metadata matrix
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
226 meta_variable <- cbind2(input_meta_variable, meta_variable)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
227 }
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
228
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
229 # print(head(meta_variable))
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
230
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
231 block_meta_var_output_filename <- paste("mixomics_blocksplsda_block_", block_name, "_variable_metadata.tsv", sep="")
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
232 write.table(meta_variable, file = paste(args$variable_metadata_outdir,block_meta_var_output_filename, sep='/'), quote = TRUE, sep = "\t", row.names = TRUE, col.names = NA)
d0b77b926863 "planemo upload for repository https://gitlab.com/bilille/galaxy-viscorvar commit 85dac6b13a9adce48b47b2b8cb28d2319ae9c1ca-dirty"
ppericard
parents:
diff changeset
233 }