Mercurial > repos > workflow4metabolomics > ms2snoop
changeset 3:c68c94865667 draft
planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
| author | workflow4metabolomics |
|---|---|
| date | Wed, 22 Jun 2022 13:07:01 +0000 |
| parents | a35fde23940e |
| children | 856001213966 |
| files | MS2snoop.R MS2snoop.xml README.md macros.xml test-data/compounds_pos.csv test-data/peaklist_precursors.csv |
| diffstat | 6 files changed, 3045 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/MS2snoop.R Wed Jun 08 12:37:53 2022 +0000 +++ b/MS2snoop.R Wed Jun 22 13:07:01 2022 +0000 @@ -15,7 +15,7 @@ #' -assign("MS2SNOOP_VERSION", "1.0.1") +assign("MS2SNOOP_VERSION", "1.1.0") lockBinding("MS2SNOOP_VERSION", globalenv()) assign("MISSING_PARAMETER_ERROR", 1) @@ -202,10 +202,10 @@ c_name, min_number_scan, mzdecimal, - r_threshold=DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD, - seuil_ra=DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA, - tolmz=DEFAULT_EXTRACT_FRAGMENTS_TOLMZ, - tolrt=DEFAULT_EXTRACT_FRAGMENTS_TOLRT + r_threshold = DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD, + seuil_ra = DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA, + tolmz = DEFAULT_EXTRACT_FRAGMENTS_TOLMZ, + tolrt = DEFAULT_EXTRACT_FRAGMENTS_TOLRT ) { ## filter precursor in the precursors file based on mz and rt in the ## compound list @@ -252,6 +252,7 @@ if (global_verbose) { cat(" fragments :", vmz) + cat("\n") } ## mz of precursor in data precursor to check correlation with @@ -372,9 +373,6 @@ if (!is.null(res_comp_by_file)) { res_comp <- rbind(res_comp, res_comp_by_file) } - if (global_verbose) { - cat("\n") - } dev.off() } } else { @@ -625,6 +623,43 @@ } } +get_csv_or_tsv <- function( + path, + sep_stack = c("\t", ",", ";"), + header = TRUE, + quote = "\"" +) { + sep <- sep_stack[1] + result <- tryCatch({ + read.table( + file = path, + sep = sep, + header = header, + quote = quote + ) + }, error = function(e) { + return(data.frame()) + }) + if (length(sep_stack) == 1) { + return(result) + } + # if ( + # ncol(result) == 0 || ## failed + # ncol(result) == 1 ## only one row, suspicious, possible fail # nolint + # ) { + new_result <- get_csv_or_tsv( + path, + sep_stack = sep_stack[-1], + header = header, + quote = quote + ) + if (ncol(new_result) > ncol(result)) { + return(new_result) + } + # } + return(result) +} + main <- function(args) { if (args$version) { cat(sprintf("%s\n", MS2SNOOP_VERSION)) @@ -639,26 +674,11 @@ set_verbose() } ## MSpurity precursors file - precursors <- read.table( - file = args$precursors, - header = TRUE, - sep = "\t", - quote = "\"" - ) + precursors <- get_csv_or_tsv(args$precursors) ## MSpurity fragments file - fragments <- read.table( - file = args$fragments, - header = TRUE, - sep = "\t", - quote = "\"" - ) + fragments <- get_csv_or_tsv(args$fragments) ## list of compounds : col1=Name of molecule, col2=m/z, col3=retention time - compounds <- read.table( - file = args$compounds, - sep = "\t", - quote = "\"", - header = TRUE - ) + compounds <- get_csv_or_tsv(args$compounds) res_all <- NULL for (i in seq_len(nrow(compounds))) {
--- a/MS2snoop.xml Wed Jun 08 12:37:53 2022 +0000 +++ b/MS2snoop.xml Wed Jun 22 13:07:01 2022 +0000 @@ -3,8 +3,9 @@ MS1/MS2 spectra and associated adducts extraction and cleaning </description> <macros> - <token name="@TOOL_VERSION@">1.0.1</token> - <token name="@VERSION_SUFFIX@">1</token> + <import>macros.xml</import> + <token name="@TOOL_VERSION@">1.1.0</token> + <token name="@VERSION_SUFFIX@">0</token> </macros> <edam_topics> <edam_topic>topic_0091</edam_topic> @@ -50,20 +51,20 @@ <param argument="--compound_txt" type="data" - format="tabular,csv" + format="tabular,csv,tsv" label="list of compounds" help="The table must fit the format: col1=Name of molecule, col2=m/z, col3=retention time" /> <param argument="--peaklist_frag_tsv" type="data" - format="tabular,csv" + format="tabular,csv,tsv" label="MSpurity fragments file" /> <param argument="--peaklist_preco_tsv" type="data" - format="tabular,csv" + format="tabular,csv,tsv" label="MSpurity precursors file" /> <param @@ -150,6 +151,96 @@ <param name="peaklist_frag_tsv" value="peaklist_fragments.tsv" /> <param name="peaklist_preco_tsv" value="peaklist_precursors.tsv" /> <output name="frag_result_txt" file="compound_fragments_result.txt" /> + <assert_stdout> + <expand macro="has_regular_stdout"/> + <expand macro="has_not_verbose_stdout"/> + <expand macro="has_not_debug_stdout"/> + </assert_stdout> + </test> + <test> + <param name="compound_txt" value="compounds_pos.txt" /> + <param name="peaklist_frag_tsv" value="peaklist_fragments.tsv" /> + <param name="peaklist_preco_tsv" value="peaklist_precursors.tsv" /> + <param name="verbose" value="--verbose" /> + <output name="frag_result_txt" file="compound_fragments_result.txt" /> + <assert_stdout> + <expand macro="has_regular_stdout"/> + <expand macro="has_verbose_stdout"/> + <expand macro="has_not_debug_stdout"/> + </assert_stdout> + </test> + <test> + <param name="compound_txt" value="compounds_pos.txt" /> + <param name="peaklist_frag_tsv" value="peaklist_fragments.tsv" /> + <param name="peaklist_preco_tsv" value="peaklist_precursors.tsv" /> + <param name="debug" value="--debug" /> + <output name="frag_result_txt" file="compound_fragments_result.txt" /> + <assert_stdout> + <expand macro="has_smol_stdout"/> + <expand macro="has_debug_stdout"/> + <expand macro="has_not_verbose_stdout"/> + </assert_stdout> + </test> + <test> + <param name="compound_txt" value="compounds_pos.txt" /> + <param name="peaklist_frag_tsv" value="peaklist_fragments.tsv" /> + <param name="peaklist_preco_tsv" value="peaklist_precursors.tsv" /> + <param name="debug" value="--debug" /> + <param name="verbose" value="--verbose" /> + <output name="frag_result_txt" file="compound_fragments_result.txt" /> + <assert_stdout> + <expand macro="has_smol_stdout"/> + <expand macro="has_debug_stdout"/> + <expand macro="has_smol_verbose_stdout"/> + </assert_stdout> + </test> + <test> + <param name="compound_txt" value="compounds_pos.csv" /> + <param name="peaklist_frag_tsv" value="peaklist_fragments.tsv" /> + <param name="peaklist_preco_tsv" value="peaklist_precursors.csv" /> + <output name="frag_result_txt" file="compound_fragments_result.txt" /> + <assert_stdout> + <expand macro="has_regular_stdout"/> + <expand macro="has_not_verbose_stdout"/> + <expand macro="has_not_debug_stdout"/> + </assert_stdout> + </test> + <test> + <param name="compound_txt" value="compounds_pos.csv" /> + <param name="peaklist_frag_tsv" value="peaklist_fragments.tsv" /> + <param name="peaklist_preco_tsv" value="peaklist_precursors.csv" /> + <param name="verbose" value="--verbose" /> + <output name="frag_result_txt" file="compound_fragments_result.txt" /> + <assert_stdout> + <expand macro="has_regular_stdout"/> + <expand macro="has_verbose_stdout"/> + <expand macro="has_not_debug_stdout"/> + </assert_stdout> + </test> + <test> + <param name="compound_txt" value="compounds_pos.csv" /> + <param name="peaklist_frag_tsv" value="peaklist_fragments.tsv" /> + <param name="peaklist_preco_tsv" value="peaklist_precursors.csv" /> + <param name="debug" value="--debug" /> + <output name="frag_result_txt" file="compound_fragments_result.txt" /> + <assert_stdout> + <expand macro="has_smol_stdout"/> + <expand macro="has_debug_stdout"/> + <expand macro="has_not_verbose_stdout"/> + </assert_stdout> + </test> + <test> + <param name="compound_txt" value="compounds_pos.csv" /> + <param name="peaklist_frag_tsv" value="peaklist_fragments.tsv" /> + <param name="peaklist_preco_tsv" value="peaklist_precursors.csv" /> + <param name="debug" value="--debug" /> + <param name="verbose" value="--verbose" /> + <output name="frag_result_txt" file="compound_fragments_result.txt" /> + <assert_stdout> + <expand macro="has_smol_stdout"/> + <expand macro="has_debug_stdout"/> + <expand macro="has_smol_verbose_stdout"/> + </assert_stdout> </test> </tests> <help><