Mercurial > repos > computational-metabolomics > mspurity_spectralmatching
comparison purityA.R @ 0:a8ab07c27338 draft default tip
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
| author | computational-metabolomics |
|---|---|
| date | Thu, 04 Mar 2021 12:20:23 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a8ab07c27338 |
|---|---|
| 1 library(msPurity) | |
| 2 library(optparse) | |
| 3 print(sessionInfo()) | |
| 4 | |
| 5 option_list <- list( | |
| 6 make_option(c("-o", "--out_dir"), type = "character"), | |
| 7 make_option("--mzML_files", type = "character"), | |
| 8 make_option("--galaxy_names", type = "character"), | |
| 9 make_option("--minOffset", type = "numeric"), | |
| 10 make_option("--maxOffset", type = "numeric"), | |
| 11 make_option("--ilim", type = "numeric"), | |
| 12 make_option("--iwNorm", default = "none", type = "character"), | |
| 13 make_option("--exclude_isotopes", action = "store_true"), | |
| 14 make_option("--isotope_matrix", type = "character"), | |
| 15 make_option("--mostIntense", action = "store_true"), | |
| 16 make_option("--plotP", action = "store_true"), | |
| 17 make_option("--nearest", action = "store_true"), | |
| 18 make_option("--cores", default = 4), | |
| 19 make_option("--ppmInterp", default = 7) | |
| 20 ) | |
| 21 | |
| 22 opt <- parse_args(OptionParser(option_list = option_list)) | |
| 23 print(opt) | |
| 24 | |
| 25 if (opt$iwNorm == "none") { | |
| 26 iwNorm <- FALSE | |
| 27 iwNormFun <- NULL | |
| 28 }else if (opt$iwNorm == "gauss") { | |
| 29 iwNorm <- TRUE | |
| 30 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { | |
| 31 print("User has to define offsets if using Gaussian normalisation") | |
| 32 }else{ | |
| 33 iwNormFun <- msPurity::iwNormGauss(minOff = -as.numeric(opt$minOffset), | |
| 34 maxOff = as.numeric(opt$maxOffset)) | |
| 35 } | |
| 36 }else if (opt$iwNorm == "rcosine") { | |
| 37 iwNorm <- TRUE | |
| 38 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { | |
| 39 print("User has to define offsets if using R-cosine normalisation") | |
| 40 }else{ | |
| 41 iwNormFun <- msPurity::iwNormRcosine(minOff = -as.numeric(opt$minOffset), | |
| 42 maxOff = as.numeric(opt$maxOffset)) | |
| 43 } | |
| 44 }else if (opt$iwNorm == "QE5") { | |
| 45 iwNorm <- TRUE | |
| 46 iwNormFun <- msPurity::iwNormQE.5() | |
| 47 } | |
| 48 | |
| 49 filepaths <- trimws(strsplit(opt$mzML_files, ",")[[1]]) | |
| 50 filepaths <- filepaths[filepaths != ""] | |
| 51 | |
| 52 | |
| 53 | |
| 54 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { | |
| 55 offsets <- NA | |
| 56 }else{ | |
| 57 offsets <- as.numeric(c(opt$minOffset, opt$maxOffset)) | |
| 58 } | |
| 59 | |
| 60 | |
| 61 if (is.null(opt$mostIntense)) { | |
| 62 mostIntense <- FALSE | |
| 63 }else{ | |
| 64 mostIntense <- TRUE | |
| 65 } | |
| 66 | |
| 67 if (is.null(opt$nearest)) { | |
| 68 nearest <- FALSE | |
| 69 }else{ | |
| 70 nearest <- TRUE | |
| 71 } | |
| 72 | |
| 73 if (is.null(opt$plotP)) { | |
| 74 plotP <- FALSE | |
| 75 plotdir <- NULL | |
| 76 }else{ | |
| 77 plotP <- TRUE | |
| 78 plotdir <- opt$out_dir | |
| 79 } | |
| 80 | |
| 81 | |
| 82 if (is.null(opt$isotope_matrix)) { | |
| 83 im <- NULL | |
| 84 }else{ | |
| 85 im <- read.table(opt$isotope_matrix, | |
| 86 header = TRUE, sep = "\t", stringsAsFactors = FALSE) | |
| 87 } | |
| 88 | |
| 89 if (is.null(opt$exclude_isotopes)) { | |
| 90 isotopes <- FALSE | |
| 91 }else{ | |
| 92 isotopes <- TRUE | |
| 93 } | |
| 94 | |
| 95 pa <- msPurity::purityA(filepaths, | |
| 96 cores = opt$cores, | |
| 97 mostIntense = mostIntense, | |
| 98 nearest = nearest, | |
| 99 offsets = offsets, | |
| 100 plotP = plotP, | |
| 101 plotdir = plotdir, | |
| 102 interpol = "linear", | |
| 103 iwNorm = iwNorm, | |
| 104 iwNormFun = iwNormFun, | |
| 105 ilim = opt$ilim, | |
| 106 mzRback = "pwiz", | |
| 107 isotopes = isotopes, | |
| 108 im = im, | |
| 109 ppmInterp = opt$ppmInterp) | |
| 110 | |
| 111 | |
| 112 if (!is.null(opt$galaxy_names)) { | |
| 113 galaxy_names <- trimws(strsplit(opt$galaxy_names, ",")[[1]]) | |
| 114 galaxy_names <- galaxy_names[galaxy_names != ""] | |
| 115 names(pa@fileList) <- galaxy_names | |
| 116 } | |
| 117 | |
| 118 print(pa) | |
| 119 save(pa, file = file.path(opt$out_dir, "purityA_output.RData")) | |
| 120 | |
| 121 pa@puritydf$filename <- sapply(pa@puritydf$fileid, function(x) names(pa@fileList)[as.integer(x)]) | |
| 122 | |
| 123 print(head(pa@puritydf)) | |
| 124 write.table(pa@puritydf, file.path(opt$out_dir, "purityA_output.tsv"), row.names = FALSE, sep = "\t") |
