Mercurial > repos > recetox > recetox_xmsannotator_advanced
annotate 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 |
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) { |
3
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
5 if (filename == "None") { |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
6 return(NULL) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
7 } |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
8 if (filetype == "csv") { |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
9 return(as.data.frame(read.csv(filename))) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
10 } else { |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
11 return(as.data.frame(arrow::read_parquet(filename))) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
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) { |
3
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
16 if (filetype == "csv") { |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
17 write.csv(table, filename, row.names = FALSE) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
18 } else { |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
19 arrow::write_parquet(table, filename) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
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) { |
3
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
24 if (comma_separated_values == "None") { |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
25 return(NA) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
26 } |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
27 filter_by <- strsplit(trimws(comma_separated_values), ",")[[1]] |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
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) { |
3
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
32 metadata_table <- select(metadata_table, id, mz, rt) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
33 peak_table <- inner_join(metadata_table, intensity_table, by = "id") |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
34 peak_table <- rename(peak_table, peak = id) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
diff
changeset
|
35 peak_table$peak <- as.integer(peak_table$peak) |
6b5dec818827
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox-xmsannotator commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents:
1
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 } |