Mercurial > repos > computational-metabolomics > mspurity_flagremove
comparison combineAnnotations.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(c("-s", "--sm_resultPth"), type = "character"), | |
| 8 make_option(c("-m", "--metfrag_resultPth"), type = "character"), | |
| 9 make_option(c("-c", "--sirius_csi_resultPth"), type = "character"), | |
| 10 make_option(c("-p", "--probmetab_resultPth"), type = "character"), | |
| 11 make_option(c("-l", "--ms1_lookup_resultPth"), type = "character"), | |
| 12 | |
| 13 make_option("--ms1_lookup_checkAdducts", action = "store_true"), | |
| 14 make_option("--ms1_lookup_keepAdducts", type = "character", default = NA), | |
| 15 make_option("--ms1_lookup_dbSource", type = "character", default = "hmdb"), | |
| 16 | |
| 17 make_option("--sm_weight", type = "numeric"), | |
| 18 make_option("--metfrag_weight", type = "numeric"), | |
| 19 make_option("--sirius_csi_weight", type = "numeric"), | |
| 20 make_option("--probmetab_weight", type = "numeric"), | |
| 21 make_option("--ms1_lookup_weight", type = "numeric"), | |
| 22 make_option("--biosim_weight", type = "numeric"), | |
| 23 | |
| 24 make_option("--summaryOutput", action = "store_true"), | |
| 25 | |
| 26 make_option("--create_new_database", action = "store_true"), | |
| 27 make_option("--outdir", type = "character", default = "."), | |
| 28 | |
| 29 make_option("--compoundDbType", type = "character", default = "sqlite"), | |
| 30 make_option("--compoundDbPth", type = "character", default = NA), | |
| 31 make_option("--compoundDbHost", type = "character", default = NA) | |
| 32 ) | |
| 33 opt <- parse_args(OptionParser(option_list = option_list)) | |
| 34 | |
| 35 print(opt) | |
| 36 | |
| 37 if (!is.null(opt$create_new_database)) { | |
| 38 sm_resultPth <- file.path(opt$outdir, "combined_annotations.sqlite") | |
| 39 file.copy(opt$sm_resultPth, sm_resultPth) | |
| 40 }else{ | |
| 41 sm_resultPth <- opt$sm_resultPth | |
| 42 } | |
| 43 | |
| 44 if (is.null(opt$ms1_lookup_checkAdducts)) { | |
| 45 opt$ms1_lookup_checkAdducts <- FALSE | |
| 46 } | |
| 47 if (!is.null(opt$ms1_lookup_keepAdducts)) { | |
| 48 opt$ms1_lookup_keepAdducts <- gsub("__ob__", "[", opt$ms1_lookup_keepAdducts) | |
| 49 opt$ms1_lookup_keepAdducts <- gsub("__cb__", "]", opt$ms1_lookup_keepAdducts) | |
| 50 ms1_lookup_keepAdducts <- strsplit(opt$ms1_lookup_keepAdducts, ",")[[1]] | |
| 51 } | |
| 52 | |
| 53 weights <- list("sm" = opt$sm_weight, | |
| 54 "metfrag" = opt$metfrag_weight, | |
| 55 "sirius_csifingerid" = opt$sirius_csi_weight, | |
| 56 "probmetab" = opt$probmetab_weight, | |
| 57 "ms1_lookup" = opt$ms1_lookup_weight, | |
| 58 "biosim" = opt$biosim_weight | |
| 59 ) | |
| 60 print(weights) | |
| 61 | |
| 62 if (is.null(opt$probmetab_resultPth)) { | |
| 63 opt$probmetab_resultPth <- NA | |
| 64 } | |
| 65 | |
| 66 if (round(!sum(unlist(weights), 0) == 1)) { | |
| 67 stop(paste0("The weights should sum to 1 not ", sum(unlist(weights)))) | |
| 68 } | |
| 69 | |
| 70 if (is.null(opt$summaryOutput)) { | |
| 71 summaryOutput <- FALSE | |
| 72 }else{ | |
| 73 summaryOutput <- TRUE | |
| 74 } | |
| 75 | |
| 76 if (opt$compoundDbType == "local_config") { | |
| 77 # load in compound config | |
| 78 # Soure local function taken from workflow4metabolomics | |
| 79 source_local <- function(fname) { | |
| 80 argv <- commandArgs(trailingOnly = FALSE) | |
| 81 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | |
| 82 source(paste(base_dir, fname, sep = "/")) | |
| 83 } | |
| 84 source_local("dbconfig.R") | |
| 85 }else{ | |
| 86 compoundDbPth <- opt$compoundDbPth | |
| 87 compoundDbType <- opt$compoundDbType | |
| 88 compoundDbName <- NA | |
| 89 compoundDbHost <- NA | |
| 90 compoundDbPort <- NA | |
| 91 compoundDbUser <- NA | |
| 92 compoundDbPass <- NA | |
| 93 } | |
| 94 | |
| 95 summary_output <- msPurity::combineAnnotations( | |
| 96 sm_resultPth = sm_resultPth, | |
| 97 compoundDbPth = compoundDbPth, | |
| 98 metfrag_resultPth = opt$metfrag_resultPth, | |
| 99 sirius_csi_resultPth = opt$sirius_csi_resultPth, | |
| 100 probmetab_resultPth = opt$probmetab_resultPth, | |
| 101 ms1_lookup_resultPth = opt$ms1_lookup_resultPth, | |
| 102 ms1_lookup_keepAdducts = ms1_lookup_keepAdducts, | |
| 103 ms1_lookup_checkAdducts = opt$ms1_lookup_checkAdducts, | |
| 104 | |
| 105 compoundDbType = compoundDbType, | |
| 106 compoundDbName = compoundDbName, | |
| 107 compoundDbHost = compoundDbHost, | |
| 108 compoundDbPort = compoundDbPort, | |
| 109 compoundDbUser = compoundDbUser, | |
| 110 compoundDbPass = compoundDbPass, | |
| 111 weights = weights, | |
| 112 summaryOutput = summaryOutput) | |
| 113 if (summaryOutput) { | |
| 114 write.table(summary_output, | |
| 115 file.path(opt$outdir, "combined_annotations.tsv"), | |
| 116 sep = "\t", row.names = FALSE) | |
| 117 } | |
| 118 | |
| 119 write.table(summary_output, | |
| 120 file.path(opt$outdir, "combined_annotations.tsv"), | |
| 121 sep = "\t", row.names = FALSE) | |
| 122 | |
| 123 closeAllConnections() | 
