annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
1 library(recetox.xmsannotator)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
2 library(dplyr)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
3
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
4 load_table <- function(filename, filetype) {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
5 if (filename == "None") {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
6 return(NULL)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
7 }
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
8 if (filetype == "csv") {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
9 return(as.data.frame(read.csv(filename)))
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
10 } else {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
11 return(as.data.frame(arrow::read_parquet(filename)))
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
12 }
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
13 }
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
14
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
15 save_table <- function(table, filename, filetype) {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
16 if (filetype == "csv") {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
17 write.csv(table, filename, row.names = FALSE)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
18 } else {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
19 arrow::write_parquet(table, filename)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
20 }
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
21 }
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
22
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
23 create_filter_by_adducts <- function(comma_separated_values) {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
24 if (comma_separated_values == "None") {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
25 return(NA)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
26 }
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
27 filter_by <- strsplit(trimws(comma_separated_values), ",")[[1]]
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
28 return(filter_by)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
29 }
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
30
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
31 create_peak_table <- function(metadata_table, intensity_table) {
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
32 metadata_table <- select(metadata_table, id, mz, rt)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
33 peak_table <- inner_join(metadata_table, intensity_table, by = "id")
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
34 peak_table <- rename(peak_table, peak = id)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
35 peak_table$peak <- as.integer(peak_table$peak)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
36 return(peak_table)
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
37 }