comparison ramclustr_wrapper.R @ 0:36104baf75da draft

"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/ramclustr commit 4d2ac914c951166e386a94d8ebb8cb1becfac122"
author recetox
date Tue, 22 Mar 2022 16:09:16 +0000
parents
children 75dafb766417
comparison
equal deleted inserted replaced
-1:000000000000 0:36104baf75da
1 store_output <- function(
2 ramclustr_obj,
3 output_merge_msp,
4 output_spec_abundance,
5 msp_file) {
6 RAMClustR::write.msp(ramclustr_obj, one.file = output_merge_msp)
7 write.csv(ramclustr_obj$SpecAbund, file = output_spec_abundance, row.names = TRUE)
8
9 if (!is.null(msp_file)) {
10 exp.name <- ramclustr_obj$ExpDes[[1]][which(row.names(ramclustr_obj$ExpDes[[1]]) == "Experiment"), 1]
11 filename <- paste("spectra/", exp.name, ".msp", sep = "")
12 file.copy(from = filename, to = msp_file, overwrite = TRUE)
13 }
14 }
15
16 load_experiment_definition <- function(filename) {
17 experiment <- RAMClustR::defineExperiment(csv = filename)
18 return(experiment)
19 }
20
21 read_metadata <- function(filename) {
22 data <- read.csv(filename, header = TRUE, stringsAsFactors = FALSE)
23
24 if (!"qc" %in% colnames(data)) {
25 if ("sampleType" %in% colnames(data)) {
26 data$qc <- ifelse(data$sampleType == "qc", TRUE, FALSE)
27 }
28 }
29
30 if (!"order" %in% colnames(data)) {
31 if ("injectionOrder" %in% colnames(data)) {
32 names(data)[names(data) == "injectionOrder"] <- "order"
33 }
34 }
35
36 return(data)
37 }
38
39 ramclustr_xcms <- function(
40 input_xcms,
41 use_pheno,
42 sr,
43 st = NULL,
44 cor_method,
45 maxt,
46 linkage,
47 min_module_size,
48 hmax,
49 deep_split,
50 normalize,
51 metadata_file = NULL,
52 qc_inj_range,
53 block_size,
54 mult,
55 mzdec,
56 rt_only_low_n,
57 replace_zeros,
58 exp_design = NULL
59 ) {
60 obj <- load(input_xcms)
61
62 batch <- NULL
63 order <- NULL
64 qc <- NULL
65
66 if (!is.null(metadata_file)) {
67 metadata <- read_metadata(metadata_file)
68 batch <- metadata$batch
69 order <- metadata$order
70 qc <- metadata$qc
71 }
72
73 experiment <- NULL
74
75 if (!is.null(exp_design)) {
76 experiment <- load_experiment_definition(exp_design)
77 }
78
79 x <- RAMClustR::ramclustR(
80 xcmsObj = xdata,
81 st = st,
82 maxt = maxt,
83 sr = sr,
84 deepSplit = deep_split,
85 blocksize = block_size,
86 mult = mult,
87 hmax = hmax,
88 usePheno = use_pheno,
89 mspout = FALSE,
90 qc.inj.range = qc_inj_range,
91 normalize = normalize,
92 minModuleSize = min_module_size,
93 linkage = linkage,
94 mzdec = mzdec,
95 cor.method = cor_method,
96 rt.only.low.n = rt_only_low_n,
97 fftempdir = NULL,
98 replace.zeros = replace_zeros,
99 batch = batch,
100 order = order,
101 qc = qc,
102 ExpDes = experiment
103 )
104 return(x)
105 }
106
107 ramclustr_csv <- function(
108 ms,
109 idmsms,
110 sr,
111 st,
112 cor_method,
113 maxt,
114 linkage,
115 min_module_size,
116 hmax,
117 deep_split,
118 normalize,
119 metadata_file = NULL,
120 qc_inj_range,
121 block_size,
122 mult,
123 mzdec,
124 rt_only_low_n,
125 replace_zeros,
126 exp_design = NULL
127 ) {
128 if (!file.exists(idmsms))
129 idmsms <- NULL
130
131 batch <- NULL
132 order <- NULL
133 qc <- NULL
134
135 if (!is.null(metadata_file)) {
136 metadata <- read_metadata(metadata_file)
137 batch <- metadata$batch
138 order <- metadata$order
139 qc <- metadata$qc
140 }
141
142 experiment <- NULL
143
144 if (!is.null(exp_design)) {
145 experiment <- load_experiment_definition(exp_design)
146 }
147
148 x <- RAMClustR::ramclustR(
149 ms = ms,
150 idmsms = idmsms,
151 st = st,
152 maxt = maxt,
153 sr = sr,
154 deepSplit = deep_split,
155 blocksize = block_size,
156 mult = mult,
157 hmax = hmax,
158 mspout = FALSE,
159 qc.inj.range = qc_inj_range,
160 normalize = normalize,
161 minModuleSize = min_module_size,
162 linkage = linkage,
163 mzdec = mzdec,
164 cor.method = cor_method,
165 rt.only.low.n = rt_only_low_n,
166 fftempdir = NULL,
167 replace.zeros = replace_zeros,
168 batch = batch,
169 order = order,
170 qc = qc,
171 ExpDes = experiment
172 )
173 return(x)
174 }