Mercurial > repos > recetox > ramclustr
comparison ramclustr_wrapper.R @ 4:050cfef6ba65 draft
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/ramclustr commit 981ab05cdced6cbcbb1f13aa492e127365a4e9ed
| author | recetox |
|---|---|
| date | Thu, 15 Jun 2023 14:01:48 +0000 |
| parents | 2ec9253a647e |
| children | 09cabbc3d12d |
comparison
equal
deleted
inserted
replaced
| 3:2ec9253a647e | 4:050cfef6ba65 |
|---|---|
| 1 store_output <- function(ramclustr_obj, | 1 store_output <- function(ramclustr_obj, |
| 2 output_merge_msp, | 2 output_merge_msp, |
| 3 output_spec_abundance, | 3 output_spec_abundance, |
| 4 msp_file) { | 4 msp_file) { |
| 5 RAMClustR::write.msp(ramclustr_obj, one.file = output_merge_msp) | 5 RAMClustR::write.msp(ramclustr_obj, one.file = output_merge_msp) |
| 6 write.csv(ramclustr_obj$SpecAbund, file = output_spec_abundance, row.names = TRUE, quote = FALSE) | 6 write.csv(ramclustr_obj$SpecAbund, |
| 7 file = output_spec_abundance, | |
| 8 row.names = TRUE, quote = FALSE | |
| 9 ) | |
| 7 | 10 |
| 8 if (!is.null(msp_file)) { | 11 if (!is.null(msp_file)) { |
| 9 exp_name <- ramclustr_obj$ExpDes[[1]][which(row.names(ramclustr_obj$ExpDes[[1]]) == "Experiment"), 1] | 12 exp_name <- ramclustr_obj$ExpDes[[1]][which( |
| 13 row.names(ramclustr_obj$ExpDes[[1]]) == "Experiment" | |
| 14 ), 1] | |
| 10 filename <- paste("spectra/", exp_name, ".msp", sep = "") | 15 filename <- paste("spectra/", exp_name, ".msp", sep = "") |
| 11 file.copy(from = filename, to = msp_file, overwrite = TRUE) | 16 file.copy(from = filename, to = msp_file, overwrite = TRUE) |
| 12 } | 17 } |
| 13 } | 18 } |
| 14 | 19 |
| 33 } | 38 } |
| 34 | 39 |
| 35 return(data) | 40 return(data) |
| 36 } | 41 } |
| 37 | 42 |
| 38 ramclustr_xcms <- function(input_xcms, | 43 read_ramclustr_aplcms <- function(ms1_featuredefinitions = NULL, |
| 39 use_pheno, | 44 ms1_featurevalues = NULL, |
| 40 sr, | 45 df_phenodata = NULL, |
| 41 st = NULL, | 46 phenodata_ext = NULL, |
| 42 cor_method, | 47 exp_des = NULL, |
| 43 maxt, | 48 st = NULL, |
| 44 linkage, | 49 ensure_no_na = TRUE) { |
| 45 min_module_size, | 50 ms1_featuredefinitions <- arrow::read_parquet(ms1_featuredefinitions) |
| 46 hmax, | 51 ms1_featurevalues <- arrow::read_parquet(ms1_featurevalues) |
| 47 deep_split, | |
| 48 normalize, | |
| 49 metadata_file = NULL, | |
| 50 qc_inj_range, | |
| 51 block_size, | |
| 52 mult, | |
| 53 mzdec, | |
| 54 rt_only_low_n, | |
| 55 replace_zeros, | |
| 56 exp_design = NULL) { | |
| 57 obj <- load(input_xcms) | |
| 58 | 52 |
| 53 if (!is.null(df_phenodata)) { | |
| 54 if (phenodata_ext == "csv") { | |
| 55 df_phenodata <- read.csv( | |
| 56 file = df_phenodata, | |
| 57 header = TRUE, check.names = FALSE | |
| 58 ) | |
| 59 } else { | |
| 60 df_phenodata <- read.csv( | |
| 61 file = df_phenodata, | |
| 62 header = TRUE, check.names = FALSE, sep = "\t" | |
| 63 ) | |
| 64 } | |
| 65 } | |
| 66 if (!is.null(exp_des)) { | |
| 67 exp_des <- load_experiment_definition(exp_des) | |
| 68 } | |
| 69 | |
| 70 feature_values <- ms1_featurevalues[-1] | |
| 71 feature_values <- t(feature_values) | |
| 72 colnames(feature_values) <- ms1_featurevalues[[1]] | |
| 73 | |
| 74 feature_definitions <- data.frame(ms1_featuredefinitions) | |
| 75 | |
| 76 ramclustr_obj <- RAMClustR::rc.get.df.data( | |
| 77 ms1_featureDefinitions = feature_definitions, | |
| 78 ms1_featureValues = feature_values, | |
| 79 phenoData = df_phenodata, | |
| 80 ExpDes = exp_des, | |
| 81 st = st, | |
| 82 ensure.no.na = ensure_no_na | |
| 83 ) | |
| 84 return(ramclustr_obj) | |
| 85 } | |
| 86 | |
| 87 apply_normalisation <- function(ramclustr_obj = NULL, | |
| 88 normalize_method, | |
| 89 metadata_file = NULL, | |
| 90 qc_inj_range, | |
| 91 p_cut, | |
| 92 rsq_cut, | |
| 93 p_adjust) { | |
| 59 batch <- NULL | 94 batch <- NULL |
| 60 order <- NULL | 95 order <- NULL |
| 61 qc <- NULL | 96 qc <- NULL |
| 62 | 97 |
| 63 if (!is.null(metadata_file)) { | 98 if (normalize_method == "TIC") { |
| 64 metadata <- read_metadata(metadata_file) | 99 ramclustr_obj <- RAMClustR::rc.feature.normalize.tic( |
| 65 batch <- metadata$batch | 100 ramclustObj = |
| 66 order <- metadata$order | 101 ramclustr_obj |
| 67 qc <- metadata$qc | 102 ) |
| 103 } else if (normalize_method == "quantile") { | |
| 104 ramclustr_obj <- RAMClustR::rc.feature.normalize.quantile(ramclustr_obj) | |
| 105 } else if (normalize_method == "batch.qc") { | |
| 106 if (!(is.null(metadata_file) || metadata_file == "None")) { | |
| 107 metadata <- read_metadata(metadata_file) | |
| 108 batch <- metadata$batch | |
| 109 order <- metadata$order | |
| 110 qc <- metadata$qc | |
| 111 } | |
| 112 | |
| 113 ramclustr_obj <- RAMClustR::rc.feature.normalize.batch.qc( | |
| 114 order = order, | |
| 115 batch = batch, | |
| 116 qc = qc, | |
| 117 ramclustObj = ramclustr_obj, | |
| 118 qc.inj.range = qc_inj_range | |
| 119 ) | |
| 120 } else { | |
| 121 if (!(is.null(metadata_file) || metadata_file == "None")) { | |
| 122 metadata <- read_metadata(metadata_file) | |
| 123 batch <- metadata$batch | |
| 124 order <- metadata$order | |
| 125 qc <- metadata$qc | |
| 126 } | |
| 127 | |
| 128 ramclustr_obj <- RAMClustR::rc.feature.normalize.qc( | |
| 129 order = order, | |
| 130 batch = batch, | |
| 131 qc = qc, | |
| 132 ramclustObj = ramclustr_obj, | |
| 133 p.cut = p_cut, | |
| 134 rsq.cut = rsq_cut, | |
| 135 p.adjust = p_adjust | |
| 136 ) | |
| 68 } | 137 } |
| 69 | 138 return(ramclustr_obj) |
| 70 experiment <- NULL | |
| 71 | |
| 72 if (!is.null(exp_design)) { | |
| 73 experiment <- load_experiment_definition(exp_design) | |
| 74 } | |
| 75 | |
| 76 x <- RAMClustR::ramclustR( | |
| 77 xcmsObj = xdata, | |
| 78 st = st, | |
| 79 maxt = maxt, | |
| 80 sr = sr, | |
| 81 deepSplit = deep_split, | |
| 82 blocksize = block_size, | |
| 83 mult = mult, | |
| 84 hmax = hmax, | |
| 85 usePheno = use_pheno, | |
| 86 mspout = FALSE, | |
| 87 qc.inj.range = qc_inj_range, | |
| 88 normalize = normalize, | |
| 89 minModuleSize = min_module_size, | |
| 90 linkage = linkage, | |
| 91 mzdec = mzdec, | |
| 92 cor.method = cor_method, | |
| 93 rt.only.low.n = rt_only_low_n, | |
| 94 fftempdir = NULL, | |
| 95 replace.zeros = replace_zeros, | |
| 96 batch = batch, | |
| 97 order = order, | |
| 98 qc = qc, | |
| 99 ExpDes = experiment | |
| 100 ) | |
| 101 return(x) | |
| 102 } | 139 } |
| 103 | |
| 104 ramclustr_csv <- function(ms, | |
| 105 idmsms, | |
| 106 sr, | |
| 107 st, | |
| 108 cor_method, | |
| 109 maxt, | |
| 110 linkage, | |
| 111 min_module_size, | |
| 112 hmax, | |
| 113 deep_split, | |
| 114 normalize, | |
| 115 metadata_file = NULL, | |
| 116 qc_inj_range, | |
| 117 block_size, | |
| 118 mult, | |
| 119 mzdec, | |
| 120 rt_only_low_n, | |
| 121 replace_zeros, | |
| 122 exp_design = NULL) { | |
| 123 if (!file.exists(idmsms)) { | |
| 124 idmsms <- NULL | |
| 125 } | |
| 126 | |
| 127 batch <- NULL | |
| 128 order <- NULL | |
| 129 qc <- NULL | |
| 130 | |
| 131 if (!is.null(metadata_file)) { | |
| 132 metadata <- read_metadata(metadata_file) | |
| 133 batch <- metadata$batch | |
| 134 order <- metadata$order | |
| 135 qc <- metadata$qc | |
| 136 } | |
| 137 | |
| 138 experiment <- NULL | |
| 139 | |
| 140 if (!is.null(exp_design)) { | |
| 141 experiment <- load_experiment_definition(exp_design) | |
| 142 } | |
| 143 | |
| 144 x <- RAMClustR::ramclustR( | |
| 145 ms = ms, | |
| 146 idmsms = idmsms, | |
| 147 st = st, | |
| 148 maxt = maxt, | |
| 149 sr = sr, | |
| 150 deepSplit = deep_split, | |
| 151 blocksize = block_size, | |
| 152 mult = mult, | |
| 153 hmax = hmax, | |
| 154 mspout = FALSE, | |
| 155 qc.inj.range = qc_inj_range, | |
| 156 normalize = normalize, | |
| 157 minModuleSize = min_module_size, | |
| 158 linkage = linkage, | |
| 159 mzdec = mzdec, | |
| 160 cor.method = cor_method, | |
| 161 rt.only.low.n = rt_only_low_n, | |
| 162 fftempdir = NULL, | |
| 163 replace.zeros = replace_zeros, | |
| 164 batch = batch, | |
| 165 order = order, | |
| 166 qc = qc, | |
| 167 ExpDes = experiment | |
| 168 ) | |
| 169 return(x) | |
| 170 } |
