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