# HG changeset patch # User recetox # Date 1717080731 0 # Node ID da7722f665f4405e2b68677020439c4f253b0eef # Parent 2d94da58904bb676e540f59326830ac2d473c49d planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/ramclustr commit bc3445f7c41271b0062c7674108f57708d08dd28 diff -r 2d94da58904b -r da7722f665f4 macros.xml --- 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 @@ -
+
+ A feature clustering algorithm for non-targeted mass spectrometric metabolomics data. macros.xml diff -r 2d94da58904b -r da7722f665f4 ramclustr_wrapper.R --- 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) }