Mercurial > repos > recetox > recetox_xmsannotator_advanced
comparison utils.R @ 3:6b5dec818827 draft default tip
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
author | recetox |
---|---|
date | Thu, 30 May 2024 14:53:48 +0000 |
parents | 2c6fa447f6a0 |
children |
comparison
equal
deleted
inserted
replaced
2:50ac7359ffe7 | 3:6b5dec818827 |
---|---|
1 library(recetox.xmsannotator) | 1 library(recetox.xmsannotator) |
2 library(dplyr) | 2 library(dplyr) |
3 | 3 |
4 load_table <- function(filename, filetype) { | 4 load_table <- function(filename, filetype) { |
5 if (filename == "None") { | 5 if (filename == "None") { |
6 return(NULL) | 6 return(NULL) |
7 } | 7 } |
8 if (filetype == "csv") { | 8 if (filetype == "csv") { |
9 return(as.data.frame(read.csv(filename))) | 9 return(as.data.frame(read.csv(filename))) |
10 } else { | 10 } else { |
11 return(as.data.frame(arrow::read_parquet(filename))) | 11 return(as.data.frame(arrow::read_parquet(filename))) |
12 } | 12 } |
13 } | 13 } |
14 | 14 |
15 save_table <- function(table, filename, filetype) { | 15 save_table <- function(table, filename, filetype) { |
16 if (filetype == "csv") { | 16 if (filetype == "csv") { |
17 write.csv(table, filename, row.names = FALSE) | 17 write.csv(table, filename, row.names = FALSE) |
18 } else { | 18 } else { |
19 arrow::write_parquet(table, filename) | 19 arrow::write_parquet(table, filename) |
20 } | 20 } |
21 } | 21 } |
22 | 22 |
23 create_filter_by_adducts <- function(comma_separated_values) { | 23 create_filter_by_adducts <- function(comma_separated_values) { |
24 if (comma_separated_values == "None") { | 24 if (comma_separated_values == "None") { |
25 return(NA) | 25 return(NA) |
26 } | 26 } |
27 filter_by <- strsplit(trimws(comma_separated_values), ",")[[1]] | 27 filter_by <- strsplit(trimws(comma_separated_values), ",")[[1]] |
28 return(filter_by) | 28 return(filter_by) |
29 } | 29 } |
30 | 30 |
31 create_peak_table <- function(metadata_table, intensity_table) { | 31 create_peak_table <- function(metadata_table, intensity_table) { |
32 metadata_table <- select(metadata_table, id, mz, rt) | 32 metadata_table <- select(metadata_table, id, mz, rt) |
33 peak_table <- inner_join(metadata_table, intensity_table, by = "id") | 33 peak_table <- inner_join(metadata_table, intensity_table, by = "id") |
34 peak_table <- rename(peak_table, peak = id) | 34 peak_table <- rename(peak_table, peak = id) |
35 peak_table$peak <- as.integer(peak_table$peak) | 35 peak_table$peak <- as.integer(peak_table$peak) |
36 return(peak_table) | 36 return(peak_table) |
37 } | 37 } |