annotate utils.R @ 14:ec196e27a61a draft default tip

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 5da5b5e8b95d93a24424155e5aebfbd337d2c4b6
author recetox
date Thu, 31 Oct 2024 11:23:30 +0000
parents d5c638b72ce4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
1 library(recetox.aplcms)
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
2
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
3 get_env_sample_name <- function() {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
4 sample_name <- Sys.getenv("SAMPLE_NAME", unset = NA)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
5 if (nchar(sample_name) == 0) {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
6 sample_name <- NA
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
7 }
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
8 if (is.na(sample_name)) {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
9 message("The mzML file does not contain run ID.")
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
10 }
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
11 return(sample_name)
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
12 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
13
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
14 save_sample_name <- function(df, sample_name) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
15 attr(df, "sample_name") <- sample_name
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
16 return(df)
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
17 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
18
9
7b42ee54d757 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 0873c036d734782d2647b0eea84cd1a0658f5e58
recetox
parents: 7
diff changeset
19 restore_sample_name <- function(df) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
20 return(df$sample_id[1])
9
7b42ee54d757 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 0873c036d734782d2647b0eea84cd1a0658f5e58
recetox
parents: 7
diff changeset
21 }
7b42ee54d757 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 0873c036d734782d2647b0eea84cd1a0658f5e58
recetox
parents: 7
diff changeset
22
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
23 load_sample_name <- function(df) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
24 sample_name <- attr(df, "sample_name")
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
25 if (is.null(sample_name)) {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
26 return(NA)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
27 } else {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
28 return(sample_name)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
29 }
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
30 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
31
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
32 save_data_as_parquet_file <- function(data, filename) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
33 arrow::write_parquet(data, filename)
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
34 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
35
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
36 load_data_from_parquet_file <- function(filename) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
37 return(arrow::read_parquet(filename))
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
38 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
39
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
40 load_parquet_collection <- function(files) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
41 features <- lapply(files, arrow::read_parquet)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
42 features <- lapply(features, tibble::as_tibble)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
43 return(features)
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
44 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
45
5
c44c73efd6e5 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 724ecb1b81ebd8a67488b8a9397177b2ff0357db
recetox
parents: 3
diff changeset
46 save_parquet_collection <- function(feature_tables, sample_names, subdir) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
47 dir.create(subdir)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
48 for (i in seq_len(length(feature_tables))) {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
49 filename <- file.path(subdir, paste0(sample_names[i], ".parquet"))
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
50 feature_table <- as.data.frame(feature_tables[[i]])
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
51 feature_table <- save_sample_name(feature_table, sample_names[i])
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
52 arrow::write_parquet(feature_table, filename)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
53 }
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
54 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
55
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
56 sort_by_sample_name <- function(tables, sample_names) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
57 return(tables[order(sample_names)])
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
58 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
59
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
60 save_tolerances <- function(table, tol_file) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
61 mz_tolerance <- c(table$mz_tol_relative)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
62 rt_tolerance <- c(table$rt_tol_relative)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
63 arrow::write_parquet(data.frame(mz_tolerance, rt_tolerance), tol_file)
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
64 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
65
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
66 save_aligned_features <- function(aligned_features, metadata_file, rt_file, intensity_file) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
67 save_data_as_parquet_file(aligned_features$metadata, metadata_file)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
68 save_data_as_parquet_file(aligned_features$rt, rt_file)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
69 save_data_as_parquet_file(aligned_features$intensity, intensity_file)
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
70 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
71
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
72 select_table_with_sample_name <- function(tables, sample_name) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
73 sample_names <- lapply(tables, load_sample_name)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
74 index <- which(sample_names == sample_name)
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
75 if (length(index) > 0) {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
76 return(tables[[index]])
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
77 } else {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
78 stop(sprintf(
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
79 "Mismatch - sample name '%s' not present in %s",
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
80 sample_name, paste(sample_names, collapse = ", ")
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
81 ))
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
82 }
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
83 }
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
84
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
85 select_adjusted <- function(recovered_features) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
86 return(recovered_features$adjusted_features)
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
87 }
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
88
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
89 known_table_columns <- function() {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
90 c(
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
91 "chemical_formula", "HMDB_ID", "KEGG_compound_ID", "mass", "ion.type",
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
92 "m.z", "Number_profiles_processed", "Percent_found", "mz_min", "mz_max",
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
93 "RT_mean", "RT_sd", "RT_min", "RT_max", "int_mean(log)", "int_sd(log)",
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
94 "int_min(log)", "int_max(log)"
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
95 )
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
96 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
97
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
98 save_known_table <- function(table, filename) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
99 columns <- known_table_columns()
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
100 arrow::write_parquet(table$known_table[columns], filename)
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
101 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
102
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
103 read_known_table <- function(filename) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
104 arrow::read_parquet(filename, col_select = known_table_columns())
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
105 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
106
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
107 save_pairing <- function(table, filename) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
108 df <- table$pairing %>%
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
109 as_tibble() %>%
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
110 setNames(c("new", "old"))
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
111 arrow::write_parquet(df, filename)
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
112 }
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
113
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
114 join_tables_to_list <- function(metadata, rt_table, intensity_table) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
115 features <- new("list")
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
116 features$metadata <- metadata
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
117 features$intensity <- intensity_table
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
118 features$rt <- rt_table
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
119 return(features)
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
120 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
121
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
122 validate_sample_names <- function(sample_names) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
123 if ((any(is.na(sample_names))) || (length(unique(sample_names)) != length(sample_names))) {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
124 stop(sprintf(
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
125 "Sample names absent or not unique - provided sample names: %s",
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
126 paste(sample_names, collapse = ", ")
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
127 ))
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
128 }
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
129 }
3
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
130
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
131 determine_sigma_ratios <- function(sigma_ratio_lim_min = NA, sigma_ratio_lim_max = NA) {
11
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
132 if (is.na(sigma_ratio_lim_min)) {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
133 sigma_ratio_lim_min <- 0
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
134 }
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
135 if (is.na(sigma_ratio_lim_max)) {
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
136 sigma_ratio_lim_max <- Inf
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
137 }
d5c638b72ce4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit bc3445f7c41271b0062c7674108f57708d08dd28
recetox
parents: 10
diff changeset
138 return(c(sigma_ratio_lim_min, sigma_ratio_lim_max))
3
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
139 }