Mercurial > repos > computational-metabolomics > mspurity_createdatabase
annotate dimsPredictPuritySingle.R @ 7:0cc6b67dccb8 draft
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit e3b17490a958d80ebe78ef1bebebef48948e1240"
author | computational-metabolomics |
---|---|
date | Tue, 08 Feb 2022 13:55:12 +0000 |
parents | 2f71b3495221 |
children | efd14b326007 |
rev | line source |
---|---|
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
1 library(msPurity) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
2 library(optparse) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
3 print(sessionInfo()) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
4 |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
5 option_list <- list( |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
6 make_option(c("--mzML_file"), type = "character"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
7 make_option(c("--mzML_files"), type = "character"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
8 make_option(c("--mzML_filename"), type = "character", default = ""), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
9 make_option(c("--mzML_galaxy_names"), type = "character", default = ""), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
10 make_option(c("--peaks_file"), type = "character"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
11 make_option(c("-o", "--out_dir"), type = "character"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
12 make_option("--minoffset", default = 0.5), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
13 make_option("--maxoffset", default = 0.5), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
14 make_option("--ilim", default = 0.05), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
15 make_option("--ppm", default = 4), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
16 make_option("--dimspy", action = "store_true"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
17 make_option("--sim", action = "store_true"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
18 make_option("--remove_nas", action = "store_true"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
19 make_option("--iwNorm", default = "none", type = "character"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
20 make_option("--file_num_dimspy", default = 1), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
21 make_option("--exclude_isotopes", action = "store_true"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
22 make_option("--isotope_matrix", type = "character") |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
23 ) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
24 |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
25 # store options |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
26 opt <- parse_args(OptionParser(option_list = option_list)) |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
27 |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
28 print(sessionInfo()) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
29 print(opt) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
30 |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
31 print(opt$mzML_files) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
32 print(opt$mzML_galaxy_names) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
33 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
34 str_to_vec <- function(x) { |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
35 print(x) |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
36 x <- trimws(strsplit(x, ",")[[1]]) |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
37 return(x[x != ""]) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
38 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
39 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
40 find_mzml_file <- function(mzML_files, galaxy_names, mzML_filename) { |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
41 mzML_filename <- trimws(mzML_filename) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
42 mzML_files <- str_to_vec(mzML_files) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
43 galaxy_names <- str_to_vec(galaxy_names) |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
44 if (mzML_filename %in% galaxy_names) { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
45 return(mzML_files[galaxy_names == mzML_filename]) |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
46 }else{ |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
47 stop(paste("mzML file not found - ", mzML_filename)) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
48 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
49 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
50 |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
51 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
52 if (is.null(opt$dimspy)) { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
53 df <- read.table(opt$peaks_file, header = TRUE, sep = "\t") |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
54 if (file.exists(opt$mzML_file)) { |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
55 mzML_file <- opt$mzML_file |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
56 }else if (!is.null(opt$mzML_files)) { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
57 mzML_file <- find_mzml_file(opt$mzML_files, opt$mzML_galaxy_names, |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
58 opt$mzML_filename) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
59 }else{ |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
60 mzML_file <- file.path(opt$mzML_file, filename) |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
61 } |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
62 }else{ |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
63 indf <- read.table(opt$peaks_file, |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
64 header = TRUE, sep = "\t", stringsAsFactors = FALSE) |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
65 |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
66 filename <- colnames(indf)[8:ncol(indf)][opt$file_num_dimspy] |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
67 print(filename) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
68 # check if the data file is mzML or RAW (can only use mzML currently) so |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
69 # we expect an mzML file of the same name in the same folder |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
70 indf$i <- indf[, colnames(indf) == filename] |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
71 indf[, colnames(indf) == filename] <- as.numeric(indf[, colnames(indf) == filename]) |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
72 |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
73 filename <- sub("raw", "mzML", filename, ignore.case = TRUE) |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
74 print(filename) |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
75 |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
76 if (file.exists(opt$mzML_file)) { |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
77 mzML_file <- opt$mzML_file |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
78 }else if (!is.null(opt$mzML_files)) { |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
79 mzML_file <- find_mzml_file(opt$mzML_files, opt$mzML_galaxy_names, filename) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
80 }else{ |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
81 mzML_file <- file.path(opt$mzML_file, filename) |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
82 } |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
83 |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
84 # Update the dimspy output with the correct information |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
85 df <- indf[4:nrow(indf), ] |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
86 if ("blank_flag" %in% colnames(df)) { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
87 df <- df[df$blank_flag == 1, ] |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
88 } |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
89 colnames(df)[colnames(df) == "m.z"] <- "mz" |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
90 |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
91 if ("nan" %in% df$mz) { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
92 df[df$mz == "nan", ]$mz <- NA |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
93 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
94 df$mz <- as.numeric(df$mz) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
95 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
96 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
97 if (!is.null(opt$remove_nas)) { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
98 df <- df[!is.na(df$mz), ] |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
99 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
100 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
101 if (is.null(opt$isotope_matrix)) { |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
102 im <- NULL |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
103 }else{ |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
104 im <- read.table(opt$isotope_matrix, |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
105 header = TRUE, sep = "\t", stringsAsFactors = FALSE) |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
106 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
107 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
108 if (is.null(opt$exclude_isotopes)) { |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
109 isotopes <- FALSE |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
110 }else{ |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
111 isotopes <- TRUE |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
112 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
113 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
114 if (is.null(opt$sim)) { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
115 sim <- FALSE |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
116 }else{ |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
117 sim <- TRUE |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
118 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
119 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
120 minOffset <- as.numeric(opt$minoffset) |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
121 maxOffset <- as.numeric(opt$maxoffset) |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
122 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
123 if (opt$iwNorm == "none") { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
124 iwNorm <- FALSE |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
125 iwNormFun <- NULL |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
126 }else if (opt$iwNorm == "gauss") { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
127 iwNorm <- TRUE |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
128 iwNormFun <- msPurity::iwNormGauss(minOff = -minOffset, maxOff = maxOffset) |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
129 }else if (opt$iwNorm == "rcosine") { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
130 iwNorm <- TRUE |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
131 iwNormFun <- msPurity::iwNormRcosine(minOff = -minOffset, maxOff = maxOffset) |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
132 }else if (opt$iwNorm == "QE5") { |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
133 iwNorm <- TRUE |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
134 iwNormFun <- msPurity::iwNormQE.5() |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
135 } |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
136 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
137 print("FIRST ROWS OF PEAK FILE") |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
138 print(head(df)) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
139 print(mzML_file) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
140 predicted <- msPurity::dimsPredictPuritySingle(df$mz, |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
141 filepth = mzML_file, |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
142 minOffset = minOffset, |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
143 maxOffset = maxOffset, |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
144 ppm = opt$ppm, |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
145 mzML = TRUE, |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
146 sim = sim, |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
147 ilim = opt$ilim, |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
148 isotopes = isotopes, |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
149 im = im, |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
150 iwNorm = iwNorm, |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
151 iwNormFun = iwNormFun |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
152 ) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
153 predicted <- cbind(df, predicted) |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
154 |
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
155 print(head(predicted)) |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
156 print(file.path(opt$out_dir, "dimsPredictPuritySingle_output.tsv")) |
0
f52287a06c02
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff
changeset
|
157 |
6
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
158 write.table(predicted, |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
159 file.path(opt$out_dir, "dimsPredictPuritySingle_output.tsv"), |
2f71b3495221
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
computational-metabolomics
parents:
0
diff
changeset
|
160 row.names = FALSE, sep = "\t") |