comparison combineAnnotations.R @ 6:6b9a83e08467 draft

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