Mercurial > repos > recetox > recetox_aplcms_adjust_time
annotate utils.R @ 1:d52c3e7c37b9 draft default tip
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 699355cdf45b2157e9eea3962a01950d469fb0ba
| author | recetox | 
|---|---|
| date | Thu, 16 Jun 2022 10:21:39 +0000 | 
| parents | 5c7f041a5cf9 | 
| children | 
| rev | line source | 
|---|---|
| 0 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 1 library(recetox.aplcms) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 2 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 3 align_features <- function(sample_names, ...) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 4 aligned <- feature.align(...) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 5 feature_names <- seq_len(nrow(aligned$pk.times)) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 6 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 7 list( | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 8 mz_tolerance = as.numeric(aligned$mz.tol), | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 9 rt_tolerance = as.numeric(aligned$chr.tol), | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 10 rt_crosstab = as_feature_crosstab(feature_names, sample_names, aligned$pk.times), | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 11 int_crosstab = as_feature_crosstab(feature_names, sample_names, aligned$aligned.ftrs) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 12 ) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 13 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 14 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 15 get_sample_name <- function(filename) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 16 tools::file_path_sans_ext(basename(filename)) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 17 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 18 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 19 as_feature_crosstab <- function(feature_names, sample_names, data) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 20 colnames(data) <- c("mz", "rt", "mz_min", "mz_max", sample_names) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 21 rownames(data) <- feature_names | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 22 as.data.frame(data) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 23 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 24 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 25 as_feature_sample_table <- function(rt_crosstab, int_crosstab) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 26 feature_names <- rownames(rt_crosstab) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 27 sample_names <- colnames(rt_crosstab)[- (1:4)] | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 28 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 29 feature_table <- data.frame( | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 30 feature = feature_names, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 31 mz = rt_crosstab[, 1], | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 32 rt = rt_crosstab[, 2] | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 33 ) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 34 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 35 # series of conversions to produce a table type from data.frame | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 36 rt_crosstab <- as.table(as.matrix(rt_crosstab[, - (1:4)])) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 37 int_crosstab <- as.table(as.matrix(int_crosstab[, - (1:4)])) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 38 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 39 crosstab_axes <- list(feature = feature_names, sample = sample_names) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 40 dimnames(rt_crosstab) <- dimnames(int_crosstab) <- crosstab_axes | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 41 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 42 x <- as.data.frame(rt_crosstab, responseName = "sample_rt") | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 43 y <- as.data.frame(int_crosstab, responseName = "sample_intensity") | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 44 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 45 data <- merge(x, y, by = c("feature", "sample")) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 46 data <- merge(feature_table, data, by = "feature") | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 47 data | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 48 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 49 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 50 load_features <- function(files) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 51 files_list <- sort_samples_by_acquisition_number(files) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 52 features <- lapply(files_list, arrow::read_parquet) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 53 features <- lapply(features, as.matrix) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 54 return(features) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 55 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 56 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 57 save_data_as_parquet_files <- function(data, subdir) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 58 dir.create(subdir) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 59 for (i in 0:(length(data) - 1)) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 60 filename <- file.path(subdir, paste0(subdir, "_features_", i, ".parquet")) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 61 arrow::write_parquet(as.data.frame(data[i + 1]), filename) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 62 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 63 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 64 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 65 save_aligned_features <- function(aligned, rt_file, int_file, tol_file) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 66 arrow::write_parquet(as.data.frame(aligned$rt_crosstab), rt_file) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 67 arrow::write_parquet(as.data.frame(aligned$int_crosstab), int_file) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 68 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 69 mz_tolerance <- c(aligned$mz_tolerance) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 70 rt_tolerance <- c(aligned$rt_tolerance) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 71 arrow::write_parquet(data.frame(mz_tolerance, rt_tolerance), tol_file) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 72 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 73 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 74 load_aligned_features <- function(rt_file, int_file, tol_file) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 75 rt_cross_table <- arrow::read_parquet(rt_file) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 76 int_cross_table <- arrow::read_parquet(int_file) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 77 tolerances_table <- arrow::read_parquet(tol_file) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 78 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 79 result <- list() | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 80 result$mz_tolerance <- tolerances_table$mz_tolerance | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 81 result$rt_tolerance <- tolerances_table$rt_tolerance | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 82 result$rt_crosstab <- rt_cross_table | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 83 result$int_crosstab <- int_cross_table | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 84 return(result) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 85 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 86 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 87 recover_signals <- function(cluster, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 88 filenames, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 89 extracted, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 90 corrected, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 91 aligned, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 92 mz_tol = 1e-05, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 93 mz_range = NA, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 94 rt_range = NA, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 95 use_observed_range = TRUE, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 96 min_bandwidth = NA, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 97 max_bandwidth = NA, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 98 recover_min_count = 3) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 99 if (!is(cluster, "cluster")) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 100 cluster <- parallel::makeCluster(cluster) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 101 on.exit(parallel::stopCluster(cluster)) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 102 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 103 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 104 clusterExport(cluster, c("extracted", "corrected", "aligned", "recover.weaker")) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 105 clusterEvalQ(cluster, library("splines")) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 106 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 107 recovered <- parLapply(cluster, seq_along(filenames), function(i) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 108 recover.weaker( | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 109 loc = i, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 110 filename = filenames[[i]], | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 111 this.f1 = extracted[[i]], | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 112 this.f2 = corrected[[i]], | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 113 pk.times = aligned$rt_crosstab, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 114 aligned.ftrs = aligned$int_crosstab, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 115 orig.tol = mz_tol, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 116 align.mz.tol = aligned$mz_tolerance, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 117 align.chr.tol = aligned$rt_tolerance, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 118 mz.range = mz_range, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 119 chr.range = rt_range, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 120 use.observed.range = use_observed_range, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 121 bandwidth = 0.5, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 122 min.bw = min_bandwidth, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 123 max.bw = max_bandwidth, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 124 recover.min.count = recover_min_count | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 125 ) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 126 }) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 127 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 128 feature_table <- aligned$rt_crosstab[, 1:4] | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 129 rt_crosstab <- cbind(feature_table, sapply(recovered, function(x) x$this.times)) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 130 int_crosstab <- cbind(feature_table, sapply(recovered, function(x) x$this.ftrs)) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 131 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 132 feature_names <- rownames(feature_table) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 133 sample_names <- colnames(aligned$rt_crosstab[, - (1:4)]) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 134 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 135 list( | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 136 extracted_features = lapply(recovered, function(x) x$this.f1), | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 137 corrected_features = lapply(recovered, function(x) x$this.f2), | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 138 rt_crosstab = as_feature_crosstab(feature_names, sample_names, rt_crosstab), | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 139 int_crosstab = as_feature_crosstab(feature_names, sample_names, int_crosstab) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 140 ) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 141 } | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 142 | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 143 create_feature_sample_table <- function(features) { | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 144 table <- as_feature_sample_table( | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 145 rt_crosstab = features$rt_crosstab, | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 146 int_crosstab = features$int_crosstab | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 147 ) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 148 return(table) | 
| 
5c7f041a5cf9
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/recetox_aplcms commit 19de0924a65bc65cbbf7c1fc17e9b5348305f95c
 recetox parents: diff
changeset | 149 } | 
