Mercurial > repos > tomnl > mspurity_dimspredictpuritysingle
comparison purityA.R @ 0:fc9bb7e49a3a draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
| author | tomnl |
|---|---|
| date | Fri, 24 May 2019 09:02:25 -0400 |
| parents | |
| children | a90832e6acb2 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:fc9bb7e49a3a |
|---|---|
| 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", default=0.5), | |
| 10 make_option("--maxOffset", default=0.5), | |
| 11 make_option("--ilim", default=0.05), | |
| 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 ) | |
| 20 | |
| 21 opt <- parse_args(OptionParser(option_list=option_list)) | |
| 22 print(opt) | |
| 23 | |
| 24 minOffset = as.numeric(opt$minOffset) | |
| 25 maxOffset = as.numeric(opt$maxOffset) | |
| 26 | |
| 27 if (opt$iwNorm=='none'){ | |
| 28 iwNorm = FALSE | |
| 29 iwNormFun = NULL | |
| 30 }else if (opt$iwNorm=='gauss'){ | |
| 31 iwNorm = TRUE | |
| 32 iwNormFun = msPurity::iwNormGauss(minOff=-minOffset, maxOff=maxOffset) | |
| 33 }else if (opt$iwNorm=='rcosine'){ | |
| 34 iwNorm = TRUE | |
| 35 iwNormFun = msPurity::iwNormRcosine(minOff=-minOffset, maxOff=maxOffset) | |
| 36 }else if (opt$iwNorm=='QE5'){ | |
| 37 iwNorm = TRUE | |
| 38 iwNormFun = msPurity::iwNormQE.5() | |
| 39 } | |
| 40 | |
| 41 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]]) | |
| 42 filepaths <- filepaths[filepaths != ""] | |
| 43 | |
| 44 | |
| 45 | |
| 46 if(is.null(opt$minOffset) || is.null(opt$maxOffset)){ | |
| 47 offsets = NA | |
| 48 }else{ | |
| 49 offsets = as.numeric(c(opt$minOffset, opt$maxOffset)) | |
| 50 } | |
| 51 | |
| 52 | |
| 53 if(is.null(opt$mostIntense)){ | |
| 54 mostIntense = FALSE | |
| 55 }else{ | |
| 56 mostIntense = TRUE | |
| 57 } | |
| 58 | |
| 59 if(is.null(opt$nearest)){ | |
| 60 nearest = FALSE | |
| 61 }else{ | |
| 62 nearest = TRUE | |
| 63 } | |
| 64 | |
| 65 if(is.null(opt$plotP)){ | |
| 66 plotP = FALSE | |
| 67 plotdir = NULL | |
| 68 }else{ | |
| 69 plotP = TRUE | |
| 70 plotdir = opt$out_dir | |
| 71 } | |
| 72 | |
| 73 | |
| 74 if (is.null(opt$isotope_matrix)){ | |
| 75 im <- NULL | |
| 76 }else{ | |
| 77 im <- read.table(opt$isotope_matrix, | |
| 78 header = TRUE, sep='\t', stringsAsFactors = FALSE) | |
| 79 } | |
| 80 | |
| 81 if (is.null(opt$exclude_isotopes)){ | |
| 82 isotopes <- FALSE | |
| 83 }else{ | |
| 84 isotopes <- TRUE | |
| 85 } | |
| 86 | |
| 87 pa <- msPurity::purityA(filepaths, | |
| 88 cores = opt$cores, | |
| 89 mostIntense = mostIntense, | |
| 90 nearest = nearest, | |
| 91 offsets = offsets, | |
| 92 plotP = plotP, | |
| 93 plotdir = plotdir, | |
| 94 interpol = "linear", | |
| 95 iwNorm = iwNorm, | |
| 96 iwNormFun = iwNormFun, | |
| 97 ilim = opt$ilim, | |
| 98 mzRback = "pwiz", | |
| 99 isotopes = isotopes, | |
| 100 im = im) | |
| 101 | |
| 102 | |
| 103 if (!is.null(opt$galaxy_names)){ | |
| 104 galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]]) | |
| 105 galaxy_names <- galaxy_names[galaxy_names != ""] | |
| 106 names(pa@fileList) <- galaxy_names | |
| 107 } | |
| 108 | |
| 109 print(pa) | |
| 110 save(pa, file=file.path(opt$out_dir, 'purityA_output.RData')) | |
| 111 | |
| 112 pa@puritydf$filename <- sapply(pa@puritydf$fileid, function(x) names(pa@fileList)[as.integer(x)]) | |
| 113 | |
| 114 print(head(pa@puritydf)) | |
| 115 write.table(pa@puritydf, file.path(opt$out_dir, 'purityA_output.tsv'), row.names=FALSE, sep='\t') | |
| 116 | |
| 117 # removed_peaks <- data.frame(removed_peaks) | |
| 118 # write.table(data.frame('ID'=rownames(removed_peaks),removed_peaks), | |
| 119 # file.path(opt$out_dir, 'removed_peaks.txt'), row.names=FALSE, sep='\t') |
