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