Mercurial > repos > computational-metabolomics > mspurity_purityx
comparison combineAnnotations.R @ 0:a141be614e76 draft
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
author | computational-metabolomics |
---|---|
date | Wed, 27 Nov 2019 12:41:53 -0500 |
parents | |
children | d7c5fa406ea8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a141be614e76 |
---|---|
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("--create_new_database", action="store_true"), | |
25 make_option("--outdir", type="character", default="."), | |
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) | |
30 ) | |
31 opt <- parse_args(OptionParser(option_list=option_list)) | |
32 | |
33 print(opt) | |
34 | |
35 if (!is.null(opt$create_new_database)){ | |
36 sm_resultPth <- file.path(opt$outdir, 'combined_annotations.sqlite') | |
37 file.copy(opt$sm_resultPth, sm_resultPth) | |
38 }else{ | |
39 sm_resultPth <- opt$sm_resultPth | |
40 } | |
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 } | |
50 | |
51 weights <-list('sm'=opt$sm_weight, | |
52 'metfrag'=opt$metfrag_weight, | |
53 'sirius_csifingerid'= opt$sirius_csi_weight, | |
54 'probmetab'=opt$probmetab_weight, | |
55 'ms1_lookup'=opt$ms1_lookup_weight, | |
56 'biosim'=opt$biosim_weight | |
57 ) | |
58 print(weights) | |
59 if (round(!sum(unlist(weights),0)==1)){ | |
60 | |
61 stop(paste0('The weights should sum to 1 not ', sum(unlist(weights)))) | |
62 } | |
63 | |
64 if (opt$compoundDbType=='local_config'){ | |
65 # load in compound config | |
66 # Soure local function taken from workflow4metabolomics | |
67 source_local <- function(fname){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } | |
68 source_local("dbconfig.R") | |
69 }else{ | |
70 compoundDbPth = opt$compoundDbPth | |
71 compoundDbType = opt$compoundDbType | |
72 compoundDbName = NA | |
73 compoundDbHost = NA | |
74 compoundDbPort = NA | |
75 compoundDbUser = NA | |
76 compoundDbPass = NA | |
77 } | |
78 | |
79 | |
80 | |
81 summary_output <- msPurity::combineAnnotations( | |
82 sm_resultPth = sm_resultPth, | |
83 compoundDbPth = compoundDbPth, | |
84 metfrag_resultPth = opt$metfrag_resultPth, | |
85 sirius_csi_resultPth = opt$sirius_csi_resultPth, | |
86 probmetab_resultPth = opt$probmetab_resultPth, | |
87 ms1_lookup_resultPth = opt$ms1_lookup_resultPth, | |
88 ms1_lookup_keepAdducts = ms1_lookup_keepAdducts, | |
89 ms1_lookup_checkAdducts = opt$ms1_lookup_checkAdducts, | |
90 | |
91 compoundDbType = compoundDbType, | |
92 compoundDbName = compoundDbName, | |
93 compoundDbHost = compoundDbHost, | |
94 compoundDbPort = compoundDbPort, | |
95 compoundDbUser = compoundDbUser, | |
96 compoundDbPass = compoundDbPass, | |
97 weights = weights) | |
98 | |
99 write.table(summary_output, file.path(opt$outdir, 'combined_annotations.tsv'), sep = '\t', row.names = FALSE) | |
100 | |
101 | |
102 closeAllConnections() | |
103 |