annotate utils.R @ 8:2d13fcae8b84 draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 199dd33897bacaeb194ce9f5239cc4752c92e4df
author recetox
date Thu, 22 Jun 2023 11:45:30 +0000
parents 1a01ffa85adc
children 7b42ee54d757
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() {
abe783e0daca 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)
abe783e0daca 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) {
abe783e0daca 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
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
7 }
abe783e0daca 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)) {
abe783e0daca 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.")
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
10 }
abe783e0daca 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
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) {
abe783e0daca 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
abe783e0daca 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
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
2
abe783e0daca 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) {
abe783e0daca 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")
abe783e0daca 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)) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
22 return(NA)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
23 } else {
abe783e0daca 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)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
25 }
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
26 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
27
2
abe783e0daca 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) {
abe783e0daca 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)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
30 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
31
abe783e0daca 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) {
abe783e0daca 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))
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_parquet_collection <- function(files) {
abe783e0daca 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)
abe783e0daca 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
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
39 return(features)
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
40 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
41
5
c44c73efd6e5 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 724ecb1b81ebd8a67488b8a9397177b2ff0357db
recetox
parents: 3
diff changeset
42 save_parquet_collection <- function(feature_tables, sample_names, subdir) {
2
abe783e0daca 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)
7
1a01ffa85adc planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 775afc79d12e680bb26496a2626d1855db9cddc7
recetox
parents: 6
diff changeset
44 for (i in seq_len(length(feature_tables))) {
6
c464931ca425 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 505c3374a3e1e9aa450fcb752f2b8f87558fedbb
recetox
parents: 5
diff changeset
45 filename <- file.path(subdir, paste0(sample_names[i], ".parquet"))
7
1a01ffa85adc planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 775afc79d12e680bb26496a2626d1855db9cddc7
recetox
parents: 6
diff changeset
46 feature_table <- as.data.frame(feature_tables[[i]])
2
abe783e0daca 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])
abe783e0daca 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)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
49 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
50 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
51
abe783e0daca 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) {
abe783e0daca 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
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
54 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
55
2
abe783e0daca 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) {
abe783e0daca 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)
abe783e0daca 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)
abe783e0daca 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
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
60 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
61
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
62 save_aligned_features <- function(aligned_features, metadata_file, rt_file, intensity_file) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
63 save_data_as_parquet_file(aligned_features$metadata, metadata_file)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
64 save_data_as_parquet_file(aligned_features$rt, rt_file)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
65 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
66 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
67
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
68 select_table_with_sample_name <- function(tables, sample_name) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
69 sample_names <- lapply(tables, load_sample_name)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
70 index <- which(sample_names == sample_name)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
71 if (length(index) > 0) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
72 return(tables[[index]])
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
73 } else {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
74 stop(sprintf("Mismatch - sample name '%s' not present in %s",
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
75 sample_name, paste(sample_names, collapse = ", ")))
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
76 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
77 }
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
78
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
79 select_adjusted <- function(recovered_features) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
80 return(recovered_features$adjusted_features)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
81 }
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
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 known_table_columns <- function() {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
84 c("chemical_formula", "HMDB_ID", "KEGG_compound_ID", "mass", "ion.type",
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
85 "m.z", "Number_profiles_processed", "Percent_found", "mz_min", "mz_max",
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
86 "RT_mean", "RT_sd", "RT_min", "RT_max", "int_mean(log)", "int_sd(log)",
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
87 "int_min(log)", "int_max(log)")
0
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
88 }
57c644d3f24c planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
recetox
parents:
diff changeset
89
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
90 save_known_table <- function(table, filename) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
91 columns <- known_table_columns()
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
92 arrow::write_parquet(table$known_table[columns], filename)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
93 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
94
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
95 read_known_table <- function(filename) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
96 arrow::read_parquet(filename, col_select = known_table_columns())
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
97 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
98
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
99 save_pairing <- function(table, filename) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
100 df <- table$pairing %>% as_tibble() %>% setNames(c("new", "old"))
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
101 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
102 }
2
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
103
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
104 join_tables_to_list <- function(metadata, rt_table, intensity_table) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
105 features <- new("list")
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
106 features$metadata <- metadata
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
107 features$intensity <- intensity_table
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
108 features$rt <- rt_table
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
109 return(features)
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
110 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
111
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
112 validate_sample_names <- function(sample_names) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
113 if ((any(is.na(sample_names))) || (length(unique(sample_names)) != length(sample_names))) {
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
114 stop(sprintf("Sample names absent or not unique - provided sample names: %s",
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
115 paste(sample_names, collapse = ", ")))
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
116 }
abe783e0daca planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 506df2aef355b3791567283e1a175914f06b405a
recetox
parents: 0
diff changeset
117 }
3
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
118
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
119 determine_sigma_ratios <- function(sigma_ratio_lim_min = NA, sigma_ratio_lim_max = NA) {
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
120 if (is.na(sigma_ratio_lim_min)) {
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
121 sigma_ratio_lim_min <- 0
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
122 }
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
123 if (is.na(sigma_ratio_lim_max)) {
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
124 sigma_ratio_lim_max <- Inf
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
125 }
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
126 return(c(sigma_ratio_lim_min, sigma_ratio_lim_max))
1e2a13bcb5a7 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 4254c6f6f05915ceab5af5d7040ac2c44a8364b4
recetox
parents: 2
diff changeset
127 }