Mercurial > repos > recetox > ramclustr
changeset 11:da7722f665f4 draft default tip
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/ramclustr commit bc3445f7c41271b0062c7674108f57708d08dd28
author | recetox |
---|---|
date | Thu, 30 May 2024 14:52:11 +0000 |
parents | 2d94da58904b |
children | |
files | macros.xml ramclustr.xml ramclustr_wrapper.R |
diffstat | 3 files changed, 112 insertions(+), 109 deletions(-) [+] |
line wrap: on
line diff
--- a/macros.xml Wed May 22 08:04:21 2024 +0000 +++ b/macros.xml Thu May 30 14:52:11 2024 +0000 @@ -66,7 +66,7 @@ </xml> <xml name="parameters_recetox_aplcms"> - <section name="ms_dataframe" title="Input MS Data as parquet (output from recetox-aplcms)" expanded="true"> + <section name="ms_dataframe" title="Input MS Data as parquet/tabular (output from recetox-aplcms)" expanded="true"> <param label="Input MS1 featureDefinitions" name="ms1_featureDefinitions" type="data" format="parquet,tabular" help="Metadata with columns: mz, rt, feature names containing MS data."/> <param label="Input MS1 featureValues" name="ms1_featureValues" type="data" format="parquet,tabular"
--- a/ramclustr.xml Wed May 22 08:04:21 2024 +0000 +++ b/ramclustr.xml Thu May 30 14:52:11 2024 +0000 @@ -1,4 +1,4 @@ -<tool id="ramclustr" name="RAMClustR" version="@TOOL_VERSION@+galaxy6" profile="21.09"> +<tool id="ramclustr" name="RAMClustR" version="@TOOL_VERSION@+galaxy7" profile="21.09"> <description>A feature clustering algorithm for non-targeted mass spectrometric metabolomics data.</description> <macros> <import>macros.xml</import>
--- a/ramclustr_wrapper.R Wed May 22 08:04:21 2024 +0000 +++ b/ramclustr_wrapper.R Thu May 30 14:52:11 2024 +0000 @@ -2,42 +2,42 @@ output_merge_msp, output_spec_abundance, msp_file) { - RAMClustR::write.msp(ramclustr_obj, one.file = output_merge_msp) - write.table(ramclustr_obj$SpecAbund, - file = output_spec_abundance, - row.names = TRUE, quote = FALSE, col.names = NA, sep = "\t" - ) + RAMClustR::write.msp(ramclustr_obj, one.file = output_merge_msp) + write.table(ramclustr_obj$SpecAbund, + file = output_spec_abundance, + row.names = TRUE, quote = FALSE, col.names = NA, sep = "\t" + ) - if (!is.null(msp_file)) { - exp_name <- ramclustr_obj$ExpDes[[1]][which( - row.names(ramclustr_obj$ExpDes[[1]]) == "Experiment" - ), 1] - filename <- paste("spectra/", exp_name, ".msp", sep = "") - file.copy(from = filename, to = msp_file, overwrite = TRUE) - } + if (!is.null(msp_file)) { + exp_name <- ramclustr_obj$ExpDes[[1]][which( + row.names(ramclustr_obj$ExpDes[[1]]) == "Experiment" + ), 1] + filename <- paste("spectra/", exp_name, ".msp", sep = "") + file.copy(from = filename, to = msp_file, overwrite = TRUE) + } } load_experiment_definition <- function(filename) { - experiment <- RAMClustR::defineExperiment(csv = filename) - return(experiment) + experiment <- RAMClustR::defineExperiment(csv = filename) + return(experiment) } read_metadata <- function(filename) { - data <- read.csv(filename, header = TRUE, stringsAsFactors = FALSE) + data <- read.csv(filename, header = TRUE, stringsAsFactors = FALSE) - if (!"qc" %in% colnames(data)) { - if ("sampleType" %in% colnames(data)) { - data$qc <- ifelse(data$sampleType == "qc", TRUE, FALSE) + if (!"qc" %in% colnames(data)) { + if ("sampleType" %in% colnames(data)) { + data$qc <- ifelse(data$sampleType == "qc", TRUE, FALSE) + } } - } - if (!"order" %in% colnames(data)) { - if ("injectionOrder" %in% colnames(data)) { - names(data)[names(data) == "injectionOrder"] <- "order" + if (!"order" %in% colnames(data)) { + if ("injectionOrder" %in% colnames(data)) { + names(data)[names(data) == "injectionOrder"] <- "order" + } } - } - return(data) + return(data) } read_ramclustr_aplcms <- function(ms1_featuredefinitions = NULL, @@ -49,52 +49,55 @@ ensure_no_na = TRUE, ms1_featuredefinitions_ext = "parquet", ms1_featurevalues_ext = "parquet") { - if (ms1_featuredefinitions_ext == "parquet") { - ms1_featuredefinitions <- arrow::read_parquet(ms1_featuredefinitions) - } else { - ms1_featuredefinitions <- read.csv(ms1_featuredefinitions, - header = TRUE, sep = "\t" - ) - } + if (ms1_featuredefinitions_ext == "parquet") { + ms1_featuredefinitions <- arrow::read_parquet(ms1_featuredefinitions) + } else { + ms1_featuredefinitions <- read.csv(ms1_featuredefinitions, + header = TRUE, sep = "\t", check.names = FALSE + ) + } - if (ms1_featurevalues_ext == "parquet") { - ms1_featurevalues <- arrow::read_parquet(ms1_featurevalues) - } else { - ms1_featurevalues <- read.csv(ms1_featurevalues, header = TRUE, sep = "\t") - } - - if (!is.null(df_phenodata)) { - if (phenodata_ext == "csv") { - df_phenodata <- read.csv( - file = df_phenodata, - header = TRUE, check.names = FALSE - ) + if (ms1_featurevalues_ext == "parquet") { + ms1_featurevalues <- arrow::read_parquet(ms1_featurevalues) } else { - df_phenodata <- read.csv( - file = df_phenodata, - header = TRUE, check.names = FALSE, sep = "\t" - ) + ms1_featurevalues <- read.csv(ms1_featurevalues, + header = TRUE, + sep = "\t", check.names = FALSE + ) } - } - if (!is.null(exp_des)) { - exp_des <- load_experiment_definition(exp_des) - } - feature_values <- ms1_featurevalues[-1] - feature_values <- t(feature_values) - colnames(feature_values) <- ms1_featurevalues[[1]] - - feature_definitions <- data.frame(ms1_featuredefinitions) + if (!is.null(df_phenodata)) { + if (phenodata_ext == "csv") { + df_phenodata <- read.csv( + file = df_phenodata, + header = TRUE, check.names = FALSE + ) + } else { + df_phenodata <- read.csv( + file = df_phenodata, + header = TRUE, check.names = FALSE, sep = "\t" + ) + } + } + if (!is.null(exp_des)) { + exp_des <- load_experiment_definition(exp_des) + } - ramclustr_obj <- RAMClustR::rc.get.df.data( - ms1_featureDefinitions = feature_definitions, - ms1_featureValues = feature_values, - phenoData = df_phenodata, - ExpDes = exp_des, - st = st, - ensure.no.na = ensure_no_na - ) - return(ramclustr_obj) + feature_values <- ms1_featurevalues[-1] + feature_values <- t(feature_values) + colnames(feature_values) <- ms1_featurevalues[[1]] + + feature_definitions <- data.frame(ms1_featuredefinitions) + + ramclustr_obj <- RAMClustR::rc.get.df.data( + ms1_featureDefinitions = feature_definitions, + ms1_featureValues = feature_values, + phenoData = df_phenodata, + ExpDes = exp_des, + st = st, + ensure.no.na = ensure_no_na + ) + return(ramclustr_obj) } apply_normalisation <- function(ramclustr_obj = NULL, @@ -104,49 +107,49 @@ p_cut, rsq_cut, p_adjust) { - batch <- NULL - order <- NULL - qc <- NULL + batch <- NULL + order <- NULL + qc <- NULL - if (normalize_method == "TIC") { - ramclustr_obj <- RAMClustR::rc.feature.normalize.tic( - ramclustObj = - ramclustr_obj - ) - } else if (normalize_method == "quantile") { - ramclustr_obj <- RAMClustR::rc.feature.normalize.quantile(ramclustr_obj) - } else if (normalize_method == "batch.qc") { - if (!(is.null(metadata_file) || metadata_file == "None")) { - metadata <- read_metadata(metadata_file) - batch <- metadata$batch - order <- metadata$order - qc <- metadata$qc - } + if (normalize_method == "TIC") { + ramclustr_obj <- RAMClustR::rc.feature.normalize.tic( + ramclustObj = + ramclustr_obj + ) + } else if (normalize_method == "quantile") { + ramclustr_obj <- RAMClustR::rc.feature.normalize.quantile(ramclustr_obj) + } else if (normalize_method == "batch.qc") { + if (!(is.null(metadata_file) || metadata_file == "None")) { + metadata <- read_metadata(metadata_file) + batch <- metadata$batch + order <- metadata$order + qc <- metadata$qc + } - ramclustr_obj <- RAMClustR::rc.feature.normalize.batch.qc( - order = order, - batch = batch, - qc = qc, - ramclustObj = ramclustr_obj, - qc.inj.range = qc_inj_range - ) - } else { - if (!(is.null(metadata_file) || metadata_file == "None")) { - metadata <- read_metadata(metadata_file) - batch <- metadata$batch - order <- metadata$order - qc <- metadata$qc + ramclustr_obj <- RAMClustR::rc.feature.normalize.batch.qc( + order = order, + batch = batch, + qc = qc, + ramclustObj = ramclustr_obj, + qc.inj.range = qc_inj_range + ) + } else { + if (!(is.null(metadata_file) || metadata_file == "None")) { + metadata <- read_metadata(metadata_file) + batch <- metadata$batch + order <- metadata$order + qc <- metadata$qc + } + + ramclustr_obj <- RAMClustR::rc.feature.normalize.qc( + order = order, + batch = batch, + qc = qc, + ramclustObj = ramclustr_obj, + p.cut = p_cut, + rsq.cut = rsq_cut, + p.adjust = p_adjust + ) } - - ramclustr_obj <- RAMClustR::rc.feature.normalize.qc( - order = order, - batch = batch, - qc = qc, - ramclustObj = ramclustr_obj, - p.cut = p_cut, - rsq.cut = rsq_cut, - p.adjust = p_adjust - ) - } - return(ramclustr_obj) + return(ramclustr_obj) }