annotate mixomics_blocksplsda.R @ 4:d4e9f7546dfa draft

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