# HG changeset patch # User recetox # Date 1634828631 0 # Node ID 27853894eeac83ee0a0f05d52062b7909cdd7f5a # Parent d62f052efae61d143c8fb2d90bcfdd352f91e8d7 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 46f606d8d234807e603b55eb2791f76663b551ee" diff -r d62f052efae6 -r 27853894eeac main.R --- a/main.R Tue Oct 05 13:13:20 2021 +0000 +++ b/main.R Thu Oct 21 15:03:51 2021 +0000 @@ -1,4 +1,5 @@ library(recetox.aplcms) +library(dplyr) save_extracted_features <- function(df, filename) { df <- as.data.frame(df) @@ -6,11 +7,37 @@ arrow::write_parquet(df[columns], filename) } -save_feature_sample_table <- function(df, filename) { +save_aligned_feature_table <- function(df, filename) { columns <- c("feature", "mz", "rt", "sample", "sample_rt", "sample_intensity") arrow::write_parquet(df[columns], filename) } +save_recovered_feature_table <- function(df, filename, out_format) { + columns <- c("feature", "mz", "rt", "sample", "sample_rt", "sample_intensity") + if (out_format == "recetox") { + peak_table <- df[columns] + recetox_peak_table <- rcx_aplcms_to_rcx_xmsannotator(peak_table) + arrow::write_parquet(recetox_peak_table, filename) + } else { + arrow::write_parquet(df[columns], filename) + } +} + +rcx_aplcms_to_rcx_xmsannotator <- function(peak_table) { + col_base <- c("feature", "mz", "rt") + output_table <- peak_table %>% distinct(across(any_of(col_base))) + + for (level in levels(peak_table$sample)) { + subdata <- peak_table %>% + filter(sample == level) %>% + select(any_of(c(col_base, "sample_intensity"))) %>% + rename(!!level := "sample_intensity") + output_table <- inner_join(output_table, subdata, by = col_base) + } + output_table <- output_table %>% rename(peak = feature) + return(output_table) +} + known_table_columns <- function() { c("chemical_formula", "HMDB_ID", "KEGG_compound_ID", "mass", "ion.type", "m.z", "Number_profiles_processed", "Percent_found", "mz_min", "mz_max", @@ -47,7 +74,7 @@ mapply(save_extracted_features, dfs, filenames) } -unsupervised_main <- function(sample_files, aligned_file, recovered_file, ...) { +unsupervised_main <- function(sample_files, aligned_file, recovered_file, out_format, ...) { sample_files <- sort_samples_by_acquisition_number(sample_files) res <- unsupervised(filenames = sample_files, ...) @@ -55,11 +82,11 @@ save_all_extracted_features(res$extracted_features, sample_files) save_all_corrected_features(res$corrected_features, sample_files) - save_feature_sample_table(res$aligned_feature_sample_table, aligned_file) - save_feature_sample_table(res$recovered_feature_sample_table, recovered_file) + save_aligned_feature_table(res$aligned_feature_sample_table, aligned_file) + save_recovered_feature_table(res$recovered_feature_sample_table, recovered_file, out_format) } -hybrid_main <- function(sample_files, known_table_file, updated_known_table_file, pairing_file, aligned_file, recovered_file, ...) { +hybrid_main <- function(sample_files, known_table_file, updated_known_table_file, pairing_file, aligned_file, recovered_file, out_format, ...) { sample_files <- sort_samples_by_acquisition_number(sample_files) known <- read_known_table(known_table_file) @@ -71,6 +98,6 @@ save_all_extracted_features(res$extracted_features, sample_files) save_all_corrected_features(res$corrected_features, sample_files) - save_feature_sample_table(res$aligned_feature_sample_table, aligned_file) - save_feature_sample_table(res$recovered_feature_sample_table, recovered_file) + save_aligned_feature_table(res$aligned_feature_sample_table, aligned_file) + save_recovered_feature_table(res$recovered_feature_sample_table, recovered_file, out_format) } diff -r d62f052efae6 -r 27853894eeac recetox_aplcms_hybrid.xml --- a/recetox_aplcms_hybrid.xml Tue Oct 05 13:13:20 2021 +0000 +++ b/recetox_aplcms_hybrid.xml Thu Oct 21 15:03:51 2021 +0000 @@ -1,4 +1,4 @@ - + generate a feature table from LC/MS spectra recetox_aplcms_macros.xml @@ -25,6 +25,7 @@ pairing_file = '${feature_known_table_pairing}', aligned_file = '${aligned_feature_sample_table}', recovered_file = '${recovered_feature_sample_table}', + out_format = '$output_format.out_format', min_exp = $noise_filtering.min_exp, min_pres = $noise_filtering.min_pres, min_run = $noise_filtering.min_run, @@ -61,6 +62,7 @@ + @@ -75,6 +77,14 @@ + + + +
+ +
+ +
diff -r d62f052efae6 -r 27853894eeac recetox_aplcms_macros.xml --- a/recetox_aplcms_macros.xml Tue Oct 05 13:13:20 2021 +0000 +++ b/recetox_aplcms_macros.xml Thu Oct 21 15:03:51 2021 +0000 @@ -5,6 +5,7 @@ r-base r-arrow r-recetox-aplcms + r-dplyr @@ -19,7 +20,7 @@ - + @@ -132,6 +133,11 @@ help="The minimum number of raw data points to be considered as a true feature." /> + +
+ +
+
diff -r d62f052efae6 -r 27853894eeac test-data/hybrid.recetox.parquet Binary file test-data/hybrid.recetox.parquet has changed diff -r d62f052efae6 -r 27853894eeac test-data/unsupervised.recetox.parquet Binary file test-data/unsupervised.recetox.parquet has changed