annotate mixomics_blocksplsda_script.R @ 6:bc28839b17fb draft default tip

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