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