Mercurial > repos > computational-metabolomics > mspurity_flagremove
comparison createMSP.R @ 0:353d48ece635 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:17:52 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:353d48ece635 |
|---|---|
| 1 library(optparse) | |
| 2 library(msPurity) | |
| 3 print(sessionInfo()) | |
| 4 | |
| 5 # Get the parameter | |
| 6 option_list <- list( | |
| 7 make_option("--rdata_input", type = "character"), | |
| 8 make_option("--method", type = "character"), | |
| 9 make_option("--metadata", type = "character"), | |
| 10 make_option("--metadata_cols", type = "character"), | |
| 11 make_option("--metadata_cols_filter", type = "character"), | |
| 12 make_option("--adduct_split", action = "store_true"), | |
| 13 make_option("--xcms_groupids", type = "character"), | |
| 14 make_option("--filter", action = "store_true"), | |
| 15 make_option("--intensity_ra", type = "character"), | |
| 16 make_option("--include_adducts", type = "character"), | |
| 17 make_option("--msp_schema", type = "character"), | |
| 18 make_option("--include_adducts_custom", type = "character", default = ""), | |
| 19 make_option("--out_dir", type = "character", default = ".") | |
| 20 ) | |
| 21 opt <- parse_args(OptionParser(option_list = option_list)) | |
| 22 | |
| 23 print(opt) | |
| 24 | |
| 25 load(opt$rdata_input) | |
| 26 | |
| 27 if (is.null(opt$metadata)) { | |
| 28 metadata <- NULL | |
| 29 }else{ | |
| 30 metadata <- read.table(opt$metadata, header = TRUE, sep = "\t", | |
| 31 stringsAsFactors = FALSE, check.names = FALSE) | |
| 32 | |
| 33 if (!opt$metadata_cols_filter == "") { | |
| 34 metadata_cols_filter <- strsplit(opt$metadata_cols_filter, ",")[[1]] | |
| 35 | |
| 36 metadata <- metadata[, metadata_cols_filter, drop = FALSE] | |
| 37 print(metadata) | |
| 38 | |
| 39 if (!"grpid" %in% colnames(metadata)) { | |
| 40 metadata$grpid <- seq_len(nrow(metadata)) | |
| 41 } | |
| 42 | |
| 43 print(metadata) | |
| 44 | |
| 45 } | |
| 46 | |
| 47 } | |
| 48 | |
| 49 | |
| 50 | |
| 51 if (is.null(opt$metadata_cols) || opt$metadata_cols == "") { | |
| 52 metadata_cols <- NULL | |
| 53 }else{ | |
| 54 metadata_cols <- opt$metadata_cols | |
| 55 | |
| 56 } | |
| 57 | |
| 58 | |
| 59 if (is.null(opt$adduct_split)) { | |
| 60 adduct_split <- FALSE | |
| 61 }else{ | |
| 62 adduct_split <- TRUE | |
| 63 } | |
| 64 | |
| 65 if (is.null(opt$xcms_groupids)) { | |
| 66 xcms_groupids <- NULL | |
| 67 }else{ | |
| 68 xcms_groupids <- trimws(strsplit(opt$xcms_groupids, ",")[[1]]) | |
| 69 } | |
| 70 | |
| 71 | |
| 72 if (is.null(opt$include_adducts_custom)) { | |
| 73 include_adducts_custom <- "" | |
| 74 }else{ | |
| 75 include_adducts_custom <- opt$include_adducts_custom | |
| 76 } | |
| 77 | |
| 78 | |
| 79 if (opt$include_adducts == "None") { | |
| 80 include_adducts <- "" | |
| 81 }else{ | |
| 82 include_adducts <- opt$include_adducts | |
| 83 } | |
| 84 | |
| 85 include_adducts_all <- paste(include_adducts_custom, ",", include_adducts, sep = "") | |
| 86 | |
| 87 include_adducts_all <- gsub("^,", "", include_adducts_all) | |
| 88 include_adducts_all <- gsub(",$", "", include_adducts_all) | |
| 89 | |
| 90 include_adducts_all <- gsub("__ob__", "[", include_adducts_all) | |
| 91 include_adducts_all <- gsub("__cb__", "]", include_adducts_all) | |
| 92 include_adducts_all <- trimws(include_adducts_all) | |
| 93 include_adducts_all <- gsub(",", " ", include_adducts_all) | |
| 94 | |
| 95 | |
| 96 | |
| 97 if (is.null(opt$filter)) { | |
| 98 filter <- FALSE | |
| 99 }else{ | |
| 100 filter <- TRUE | |
| 101 } | |
| 102 | |
| 103 | |
| 104 | |
| 105 msPurity::createMSP(pa, | |
| 106 msp_file_pth = file.path(opt$out_dir, "lcmsms_spectra.msp"), | |
| 107 metadata = metadata, | |
| 108 metadata_cols = metadata_cols, | |
| 109 method = opt$method, | |
| 110 adduct_split = adduct_split, | |
| 111 xcms_groupids = xcms_groupids, | |
| 112 filter = filter, | |
| 113 intensity_ra = opt$intensity_ra, | |
| 114 include_adducts = include_adducts_all, | |
| 115 msp_schema = opt$msp_schema) | |
| 116 | |
| 117 print("msp created") |
