Mercurial > repos > tomnl > mspurity_flagremove
comparison combineAnnotations.R @ 12:2c8b5a640a04 draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit bbbcc75d51c020446fd00d76f908a6250266cfea
| author | tomnl |
|---|---|
| date | Fri, 13 Sep 2019 11:49:43 -0400 |
| parents | 1a77ed3c94b7 |
| children | 2445754177bb |
comparison
equal
deleted
inserted
replaced
| 11:7e4a5ce0877d | 12:2c8b5a640a04 |
|---|---|
| 6 option_list <- list( | 6 option_list <- list( |
| 7 make_option(c("-s","--sm_resultPth"),type="character"), | 7 make_option(c("-s","--sm_resultPth"),type="character"), |
| 8 make_option(c("-m","--metfrag_resultPth"),type="character"), | 8 make_option(c("-m","--metfrag_resultPth"),type="character"), |
| 9 make_option(c("-c","--sirius_csi_resultPth"),type="character"), | 9 make_option(c("-c","--sirius_csi_resultPth"),type="character"), |
| 10 make_option(c("-p","--probmetab_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 | |
| 11 make_option(c("-sw","--sm_weight"),type="numeric"), | 17 make_option(c("-sw","--sm_weight"),type="numeric"), |
| 12 make_option(c("-mw","--metfrag_weight"),type="numeric"), | 18 make_option(c("-mw","--metfrag_weight"),type="numeric"), |
| 13 make_option(c("-cw","--sirius_csi_weight"),type="numeric"), | 19 make_option(c("-cw","--sirius_csi_weight"),type="numeric"), |
| 14 make_option(c("-pw","--probmetab_weight"),type="numeric"), | 20 make_option(c("-pw","--probmetab_weight"),type="numeric"), |
| 21 make_option(c("-lw","--ms1_lookup_weight"),type="numeric"), | |
| 22 make_option(c("-bw","--biosim_weight"),type="numeric"), | |
| 23 | |
| 15 make_option("--create_new_database", action="store_true"), | 24 make_option("--create_new_database", action="store_true"), |
| 16 make_option(c("-o","--outdir"),type="character", default="."), | 25 make_option(c("-o","--outdir"),type="character", default="."), |
| 17 make_option("--eic", action="store_true") | 26 |
| 27 make_option("--compoundDbType", type="character", default="sqlite"), | |
| 28 make_option("--compoundDbPth", type="character", default=NA), | |
| 29 make_option("--compoundDbHost", type="character", default=NA) | |
| 18 ) | 30 ) |
| 19 opt <- parse_args(OptionParser(option_list=option_list)) | 31 opt <- parse_args(OptionParser(option_list=option_list)) |
| 20 | 32 |
| 21 print(opt) | 33 print(opt) |
| 22 | 34 |
| 25 file.copy(opt$sm_resultPth, sm_resultPth) | 37 file.copy(opt$sm_resultPth, sm_resultPth) |
| 26 }else{ | 38 }else{ |
| 27 sm_resultPth <- opt$sm_resultPth | 39 sm_resultPth <- opt$sm_resultPth |
| 28 } | 40 } |
| 29 | 41 |
| 42 if (is.null(opt$ms1_lookup_checkAdducts)){ | |
| 43 opt$ms1_lookup_checkAdducts <- FALSE | |
| 44 } | |
| 45 if (!is.null(opt$ms1_lookup_keepAdducts)){ | |
| 46 opt$ms1_lookup_keepAdducts <- gsub("__ob__", "[", opt$ms1_lookup_keepAdducts) | |
| 47 opt$ms1_lookup_keepAdducts <- gsub("__cb__", "]", opt$ms1_lookup_keepAdducts) | |
| 48 ms1_lookup_keepAdducts <- strsplit(opt$ms1_lookup_keepAdducts, ",")[[1]] | |
| 49 } | |
| 30 | 50 |
| 31 weights <-list('sm'=opt$sm_weight, | 51 weights <-list('sm'=opt$sm_weight, |
| 32 'metfrag'=opt$metfrag_weight, | 52 'metfrag'=opt$metfrag_weight, |
| 33 'sirius_csifingerid'= opt$sirius_csi_weight, | 53 'sirius_csifingerid'= opt$sirius_csi_weight, |
| 34 'probmetab'=opt$probmetab_weight | 54 'probmetab'=opt$probmetab_weight, |
| 55 'ms1_lookup'=opt$ms1_lookup_weight, | |
| 56 'biosim'=opt$biosim_weight | |
| 35 ) | 57 ) |
| 36 | 58 print(weights) |
| 37 if (round(!sum(unlist(weights),0)==1)){ | 59 if (round(!sum(unlist(weights),0)==1)){ |
| 38 | 60 |
| 39 stop(paste0('The weights should sum to 1 not ', sum(unlist(weights)))) | 61 stop(paste0('The weights should sum to 1 not ', sum(unlist(weights)))) |
| 40 } | 62 } |
| 41 | 63 |
| 42 summary_output <- msPurity::combineAnnotations(sm_resultPth, | 64 if (opt$compoundDbType=='local_config'){ |
| 43 opt$metfrag_resultPth, | 65 # load in compound config |
| 44 opt$sirius_csi_resultPth, | 66 # Soure local function taken from workflow4metabolomics |
| 45 opt$probmetab_resultPth, | 67 source_local <- function(fname){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } |
| 46 weights = weights) | 68 source_local("dbconfig.R") |
| 69 }else{ | |
| 70 compoundDbType = opt$compoundDbType | |
| 71 compoundDbName = NA | |
| 72 compoundDbHost = NA | |
| 73 compoundDbPort = NA | |
| 74 compoundDbUser = NA | |
| 75 compoundDbPass = NA | |
| 76 } | |
| 77 | |
| 78 | |
| 79 | |
| 80 summary_output <- msPurity::combineAnnotations( | |
| 81 sm_resultPth = sm_resultPth, | |
| 82 compoundDbPth = opt$compoundDbPth, | |
| 83 metfrag_resultPth = opt$metfrag_resultPth, | |
| 84 sirius_csi_resultPth = opt$sirius_csi_resultPth, | |
| 85 probmetab_resultPth = opt$probmetab_resultPth, | |
| 86 ms1_lookup_resultPth = opt$ms1_lookup_resultPth, | |
| 87 ms1_lookup_keepAdducts = ms1_lookup_keepAdducts, | |
| 88 ms1_lookup_checkAdducts = opt$ms1_lookup_checkAdducts, | |
| 89 | |
| 90 compoundDbType = compoundDbType, | |
| 91 compoundDbName = compoundDbName, | |
| 92 compoundDbHost = compoundDbHost, | |
| 93 compoundDbPort = compoundDbPort, | |
| 94 compoundDbUser = compoundDbUser, | |
| 95 compoundDbPass = compoundDbPass, | |
| 96 weights = weights) | |
| 47 | 97 |
| 48 write.table(summary_output, file.path(opt$outdir, 'combined_annotations.tsv'), sep = '\t', row.names = FALSE) | 98 write.table(summary_output, file.path(opt$outdir, 'combined_annotations.tsv'), sep = '\t', row.names = FALSE) |
| 49 | 99 |
| 50 | 100 |
| 51 closeAllConnections() | 101 closeAllConnections() |
