Mercurial > repos > recetox > recetox_xmsannotator_advanced
diff utils.R @ 0:cfd2e19f00a9 draft
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
author | recetox |
---|---|
date | Mon, 26 Jun 2023 13:55:56 +0000 |
parents | |
children | 2c6fa447f6a0 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils.R Mon Jun 26 13:55:56 2023 +0000 @@ -0,0 +1,37 @@ +library(recetox.xmsannotator) +library(dplyr) + +load_table <- function(filename, filetype) { + if (filename == "None") { + return(NULL) + } + if (filetype == "csv") { + return(as.data.frame(read.csv(filename))) + } else { + return(as.data.frame(arrow::read_parquet(filename))) + } +} + +save_table <- function(table, filename, filetype) { + if (filetype == "csv") { + write.csv(table, filename, row.names = FALSE) + } else { + arrow::write_parquet(table, filename) + } +} + +create_filter_by_adducts <- function(comma_separated_values) { + if (comma_separated_values == "None") { + return(NA) + } + filter_by <- strsplit(trimws(comma_separated_values), ",")[[1]] + return(filter_by) +} + +create_peak_table <- function(metadata_table, intensity_table) { + metadata_table <- select(metadata_table, id, mz, rt) + peak_table <- inner_join(metadata_table, intensity_table, by = "id") + peak_table <- rename(peak_table, peak = id) + peak_table$peak <- as.integer(peak_table$peak) + return(peak_table) +}