# HG changeset patch
# User recetox
# Date 1634828598 0
# Node ID 6057540f65a91339a6c4decc915f9ac93153a35e
# Parent b18c2d014b2886fbeaabdb2e98374276674a9389
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 46f606d8d234807e603b55eb2791f76663b551ee"
diff -r b18c2d014b28 -r 6057540f65a9 main.R
--- a/main.R Tue Oct 05 13:12:50 2021 +0000
+++ b/main.R Thu Oct 21 15:03:18 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 b18c2d014b28 -r 6057540f65a9 recetox_aplcms_macros.xml
--- a/recetox_aplcms_macros.xml Tue Oct 05 13:12:50 2021 +0000
+++ b/recetox_aplcms_macros.xml Thu Oct 21 15:03:18 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 b18c2d014b28 -r 6057540f65a9 recetox_aplcms_unsupervised.xml
--- a/recetox_aplcms_unsupervised.xml Tue Oct 05 13:12:50 2021 +0000
+++ b/recetox_aplcms_unsupervised.xml Thu Oct 21 15:03:18 2021 +0000
@@ -1,4 +1,4 @@
-
+
generate a feature table from LC/MS spectra
recetox_aplcms_macros.xml
@@ -22,6 +22,7 @@
sample_files = c('$filenames_str'),
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,
@@ -55,6 +56,7 @@
+
@@ -66,6 +68,13 @@
+
+
+
+
+
diff -r b18c2d014b28 -r 6057540f65a9 test-data/hybrid.recetox.parquet
Binary file test-data/hybrid.recetox.parquet has changed
diff -r b18c2d014b28 -r 6057540f65a9 test-data/unsupervised.recetox.parquet
Binary file test-data/unsupervised.recetox.parquet has changed