annotate utils.R @ 6:d8766a6c08a4 draft default tip

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
author recetox
date Thu, 20 Jul 2023 06:28:49 +0000
parents a393c4383436
children
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) {
6
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
5 if (filename == "None") {
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
6 return(NULL)
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
7 }
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
8 if (filetype == "csv") {
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
9 return(as.data.frame(read.csv(filename)))
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
10 } else {
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
11 return(as.data.frame(arrow::read_parquet(filename)))
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
12 }
5
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) {
6
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
16 if (filetype == "csv") {
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
17 write.csv(table, filename, row.names = FALSE)
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
18 } else {
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
19 arrow::write_parquet(table, filename)
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
20 }
5
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) {
6
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
24 if (comma_separated_values == "None") {
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
25 return(NA)
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
26 }
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
27 filter_by <- strsplit(trimws(comma_separated_values), ",")[[1]]
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
28 return(filter_by)
5
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) {
6
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
32 metadata_table <- select(metadata_table, id, mz, rt)
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
33 peak_table <- inner_join(metadata_table, intensity_table, by = "id")
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
34 peak_table <- rename(peak_table, peak = id)
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
35 peak_table$peak <- as.integer(peak_table$peak)
d8766a6c08a4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 8547c5323747595eabbeed29039a1b2363491243
recetox
parents: 5
diff changeset
36 return(peak_table)
5
a393c4383436 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit 1ab1a1dabfcebe11720de1411927a7438c1b64c1
recetox
parents:
diff changeset
37 }