comparison combineAnnotations.R @ 8:94a2b6571758 draft

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