changeset 7:09cabbc3d12d draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/ramclustr commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
author recetox
date Thu, 12 Oct 2023 13:30:54 +0000
parents 9b716db0a786
children c043e1fd79d1
files macros.xml ramclustr.xml ramclustr_wrapper.R
diffstat 3 files changed, 109 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/macros.xml	Tue Jun 27 14:29:37 2023 +0000
+++ b/macros.xml	Thu Oct 12 13:30:54 2023 +0000
@@ -39,10 +39,13 @@
         <edam_topics>
                <edam_topic>topic_3520</edam_topic>       
         </edam_topics>
+     </xml>
+    
+    <xml name="refs">
         <xrefs>
                <xref type="bio.tools">ramclustr</xref>
         </xrefs>
-     </xml>
+    </xml>
 
     <xml name="parameters_csv">
         <section name="ms_csv" title="Input MS Data as CSV" expanded="true">
--- a/ramclustr.xml	Tue Jun 27 14:29:37 2023 +0000
+++ b/ramclustr.xml	Thu Oct 12 13:30:54 2023 +0000
@@ -1,15 +1,16 @@
-<tool id="ramclustr" name="RAMClustR" version="@TOOL_VERSION@+galaxy1" profile="21.09">
+<tool id="ramclustr" name="RAMClustR" version="@TOOL_VERSION@+galaxy3" profile="21.09">
     <description>A feature clustering algorithm for non-targeted mass spectrometric metabolomics data.</description>
     <macros>
         <import>macros.xml</import>
     </macros>
+    <expand macro='annotation'/>
     <edam_operations>
         <edam_operation>operation_3557</edam_operation>
         <edam_operation>operation_3435</edam_operation>
         <edam_operation>operation_3432</edam_operation>
         <edam_operation>operation_3465</edam_operation>
     </edam_operations>
-    <expand macro='annotation'/>
+    <expand macro="refs"/>
     <expand macro="creator"/>
 
     <requirements>
@@ -157,7 +158,7 @@
     </outputs>
 
     <tests>
-        <test><!-- TEST 1 -->
+        <test expect_num_outputs="2"><!-- TEST 1 -->
             <section name="filetype">
                 <param name="type_choice" value="xcms"/>
                 <section name="xcms">
@@ -176,7 +177,7 @@
             <output name="mass_spectra_merged" file="test1_fill_xcms_1.msp" ftype="msp"/>
             <output name="spec_abundance" file="test1_spec_abundance_xcms_1.csv" ftype="csv" compare="sim_size" delta="100"/>
         </test>
-        <test><!-- TEST 2 -->
+        <test expect_num_outputs="2"><!-- TEST 2 -->
             <section name="filetype">
                 <param name="type_choice" value="xcms"/>
                 <section name="xcms">
@@ -197,7 +198,7 @@
             <output name="mass_spectra_merged" file="test2_fill_xcms_2.msp" ftype="msp" compare="sim_size" delta="100"/>
             <output name="spec_abundance" file="test2_spec_abundance_xcms_2.csv" ftype="csv" compare="sim_size" delta="100"/>
         </test>
-        <test><!-- TEST 3 -->
+        <test expect_num_outputs="2"><!-- TEST 3 -->
             <section name="filetype">
                 <param name="type_choice" value="csv"/>
                 <section name="ms_csv">
@@ -215,7 +216,7 @@
             <output name="mass_spectra_merged" file="test3_spectra_csv_1.msp" ftype="msp"/>
             <output name="spec_abundance" file="test3_spec_abundance_csv_1.csv" ftype="csv"/>
         </test>
-        <test><!-- TEST 4 -->
+        <test expect_num_outputs="2"><!-- TEST 4 -->
             <section name="filetype">
                 <param name="type_choice" value="csv"/>
                 <section name="ms_csv">
@@ -224,7 +225,7 @@
             </section>
             <output name="mass_spectra_merged" file="test4_spectra_csv_2.msp" ftype="msp" lines_diff="10"/>
         </test>
-        <test><!-- TEST 5 -->
+        <test expect_num_outputs="2"><!-- TEST 5 -->
             <section name="filetype">
                 <param name="type_choice" value="recetox-aplcms"/>
                 <section name="ms_dataframe">
--- a/ramclustr_wrapper.R	Tue Jun 27 14:29:37 2023 +0000
+++ b/ramclustr_wrapper.R	Thu Oct 12 13:30:54 2023 +0000
@@ -2,42 +2,42 @@
                          output_merge_msp,
                          output_spec_abundance,
                          msp_file) {
-    RAMClustR::write.msp(ramclustr_obj, one.file = output_merge_msp)
-    write.csv(ramclustr_obj$SpecAbund,
-        file = output_spec_abundance,
-        row.names = TRUE, quote = FALSE
-    )
+  RAMClustR::write.msp(ramclustr_obj, one.file = output_merge_msp)
+  write.csv(ramclustr_obj$SpecAbund,
+    file = output_spec_abundance,
+    row.names = TRUE, quote = FALSE
+  )
 
-    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,
@@ -47,41 +47,41 @@
                                   exp_des = NULL,
                                   st = NULL,
                                   ensure_no_na = TRUE) {
-    ms1_featuredefinitions <- arrow::read_parquet(ms1_featuredefinitions)
-    ms1_featurevalues <- arrow::read_parquet(ms1_featurevalues)
+  ms1_featuredefinitions <- arrow::read_parquet(ms1_featuredefinitions)
+  ms1_featurevalues <- arrow::read_parquet(ms1_featurevalues)
 
-    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(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)
-    }
+  }
+  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)
+  feature_values <- ms1_featurevalues[-1]
+  feature_values <- t(feature_values)
+  colnames(feature_values) <- ms1_featurevalues[[1]]
 
-    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_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,
@@ -91,49 +91,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
-        )
-    }
-    return(ramclustr_obj)
+    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)
 }