Mercurial > repos > recetox > recetox_xmsannotator_advanced
comparison utils.R @ 5:a393c4383436 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:44 +0000 |
| parents | |
| children | d8766a6c08a4 |
comparison
equal
deleted
inserted
replaced
| 4:464c1e80a01f | 5:a393c4383436 |
|---|---|
| 1 library(recetox.xmsannotator) | |
| 2 library(dplyr) | |
| 3 | |
| 4 load_table <- function(filename, filetype) { | |
| 5 if (filename == "None") { | |
| 6 return(NULL) | |
| 7 } | |
| 8 if (filetype == "csv") { | |
| 9 return(as.data.frame(read.csv(filename))) | |
| 10 } else { | |
| 11 return(as.data.frame(arrow::read_parquet(filename))) | |
| 12 } | |
| 13 } | |
| 14 | |
| 15 save_table <- function(table, filename, filetype) { | |
| 16 if (filetype == "csv") { | |
| 17 write.csv(table, filename, row.names = FALSE) | |
| 18 } else { | |
| 19 arrow::write_parquet(table, filename) | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 create_filter_by_adducts <- function(comma_separated_values) { | |
| 24 if (comma_separated_values == "None") { | |
| 25 return(NA) | |
| 26 } | |
| 27 filter_by <- strsplit(trimws(comma_separated_values), ",")[[1]] | |
| 28 return(filter_by) | |
| 29 } | |
| 30 | |
| 31 create_peak_table <- function(metadata_table, intensity_table) { | |
| 32 metadata_table <- select(metadata_table, id, mz, rt) | |
| 33 peak_table <- inner_join(metadata_table, intensity_table, by = "id") | |
| 34 peak_table <- rename(peak_table, peak = id) | |
| 35 peak_table$peak <- as.integer(peak_table$peak) | |
| 36 return(peak_table) | |
| 37 } |
