Mercurial > repos > tomnl > mspurity_createdatabase
comparison spectralMatching.R @ 0:f075f67c7416 draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
| author | tomnl |
|---|---|
| date | Fri, 24 May 2019 08:59:45 -0400 |
| parents | |
| children | c34cdaca2fcb |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f075f67c7416 |
|---|---|
| 1 library(msPurity) | |
| 2 library(msPurityData) | |
| 3 library(optparse) | |
| 4 print(sessionInfo()) | |
| 5 | |
| 6 | |
| 7 option_list <- list( | |
| 8 make_option(c("-o", "--outDir"), type="character"), | |
| 9 make_option("--q_dbPth", type="character"), | |
| 10 make_option("--l_dbPth", type="character"), | |
| 11 | |
| 12 make_option("--q_msp", type="character", default=NA), | |
| 13 make_option("--l_msp", type="character", default=NA), | |
| 14 | |
| 15 make_option("--q_defaultDb", action="store_true"), | |
| 16 make_option("--l_defaultDb", action="store_true"), | |
| 17 | |
| 18 make_option("--q_ppmPrec", type="double"), | |
| 19 make_option("--l_ppmPrec", type="double"), | |
| 20 | |
| 21 make_option("--q_ppmProd", type="double"), | |
| 22 make_option("--l_ppmProd", type="double"), | |
| 23 | |
| 24 make_option("--q_raThres", type="double", default=NA), | |
| 25 make_option("--l_raThres", type="double", default=NA), | |
| 26 | |
| 27 make_option("--q_polarity", type="character", default=NA), | |
| 28 make_option("--l_polarity", type="character", default=NA), | |
| 29 | |
| 30 make_option("--q_purity", type="double", default=NA), | |
| 31 make_option("--l_purity", type="double", default=NA), | |
| 32 | |
| 33 make_option("--q_xcmsGroups", type="character", default=NA), | |
| 34 make_option("--l_xcmsGroups", type="character", default=NA), | |
| 35 | |
| 36 make_option("--q_pids", type="character", default=NA), | |
| 37 make_option("--l_pids", type="character", default=NA), | |
| 38 | |
| 39 make_option("--q_rtrangeMin", type="double", default=NA), | |
| 40 make_option("--l_rtrangeMin", type="double", default=NA), | |
| 41 | |
| 42 make_option("--q_rtrangeMax", type="double", default=NA), | |
| 43 make_option("--l_rtrangeMax", type="double", default=NA), | |
| 44 | |
| 45 make_option("--q_accessions", type="character", default=NA), | |
| 46 make_option("--l_accessions", type="character", default=NA), | |
| 47 | |
| 48 make_option("--q_sources", type="character", default=NA), | |
| 49 make_option("--l_sources", type="character", default=NA), | |
| 50 | |
| 51 make_option("--q_sourcesUser", type="character", default=NA), | |
| 52 make_option("--l_sourcesUser", type="character", default=NA), | |
| 53 | |
| 54 make_option("--q_instrumentTypes", type="character", default=NA), | |
| 55 make_option("--l_instrumentTypes", type="character", default=NA), | |
| 56 | |
| 57 make_option("--q_instrumentTypesUser", type="character", default=NA), | |
| 58 make_option("--l_instrumentTypesUser", type="character", default=NA), | |
| 59 | |
| 60 make_option("--q_instruments", type="character", default=NA), | |
| 61 make_option("--l_instruments", type="character", default=NA), | |
| 62 | |
| 63 make_option("--q_spectraTypes", type="character", default=NA), | |
| 64 make_option("--l_spectraTypes", type="character", default=NA), | |
| 65 | |
| 66 make_option("--q_spectraFilter", action="store_true"), | |
| 67 make_option("--l_spectraFilter", action="store_true"), | |
| 68 | |
| 69 make_option("--usePrecursors", action="store_true"), | |
| 70 | |
| 71 make_option("--mzW", type="double"), | |
| 72 make_option("--raW", type="double"), | |
| 73 | |
| 74 make_option("--rttol", type="double", default=NA), | |
| 75 | |
| 76 make_option("--updateDb", action="store_true"), | |
| 77 make_option("--copyDb", action="store_true"), | |
| 78 make_option("--cores", default=1) | |
| 79 | |
| 80 | |
| 81 ) | |
| 82 | |
| 83 # store options | |
| 84 opt<- parse_args(OptionParser(option_list=option_list)) | |
| 85 | |
| 86 print(opt) | |
| 87 | |
| 88 extractMultiple <- function(optParam){ | |
| 89 if (!is.na(optParam)){ | |
| 90 param <- trimws(strsplit(optParam, ',')[[1]]) | |
| 91 param <- param[param != ""] | |
| 92 }else{ | |
| 93 param <- NA | |
| 94 } | |
| 95 return(param) | |
| 96 | |
| 97 } | |
| 98 | |
| 99 if(!is.null(opt$q_defaultDb)){ | |
| 100 q_dbPth <- system.file("extdata", "library_spectra", "library_spectra.db", package="msPurityData") | |
| 101 }else if (!is.null(opt$q_dbPth)){ | |
| 102 q_dbPth <- opt$q_dbPth | |
| 103 }else{ | |
| 104 message('No query database available') | |
| 105 exit() | |
| 106 } | |
| 107 | |
| 108 if(!is.null(opt$l_defaultDb)){ | |
| 109 l_dbPth <- system.file("extdata", "library_spectra", "library_spectra.db", package="msPurityData") | |
| 110 }else if (!is.null(opt$l_dbPth)){ | |
| 111 l_dbPth <- opt$l_dbPth | |
| 112 }else{ | |
| 113 message('No library database available') | |
| 114 exit() | |
| 115 } | |
| 116 | |
| 117 | |
| 118 q_polarity <- extractMultiple(opt$q_polarity) | |
| 119 l_polarity <- extractMultiple(opt$l_polarity) | |
| 120 | |
| 121 q_xcmsGroups <- extractMultiple(opt$q_xcmsGroups) | |
| 122 l_xcmsGroups <- extractMultiple(opt$l_xcmsGroups) | |
| 123 | |
| 124 q_pids <- extractMultiple(opt$q_pids) | |
| 125 l_pids <- extractMultiple(opt$l_pids) | |
| 126 | |
| 127 q_sources <- extractMultiple(opt$q_sources) | |
| 128 l_sources <- extractMultiple(opt$l_sources) | |
| 129 | |
| 130 q_sourcesUser <- extractMultiple(opt$q_sourcesUser) | |
| 131 l_sourcesUser <- extractMultiple(opt$l_sourcesUser) | |
| 132 | |
| 133 q_sources <-c(q_sources, q_sourcesUser) | |
| 134 l_sources <-c(l_sources, l_sourcesUser) | |
| 135 | |
| 136 q_instrumentTypes <- extractMultiple(opt$q_instrumentTypes) | |
| 137 l_instrumentTypes <- extractMultiple(opt$l_instrumentTypes) | |
| 138 | |
| 139 q_instrumentTypes <-c(q_instrumentTypes, q_instrumentTypes) | |
| 140 l_instrumentTypes <-c(l_instrumentTypes, l_instrumentTypes) | |
| 141 | |
| 142 | |
| 143 if(!is.null(opt$l_spectraFilter)){ | |
| 144 l_spectraFilter <- TRUE | |
| 145 }else{ | |
| 146 l_spectraFilter <- FALSE | |
| 147 } | |
| 148 | |
| 149 if(!is.null(opt$q_spectraFilter)){ | |
| 150 q_spectraFilter <- TRUE | |
| 151 }else{ | |
| 152 q_spectraFilter <- FALSE | |
| 153 } | |
| 154 | |
| 155 if(!is.null(opt$updateDb)){ | |
| 156 updateDb <- TRUE | |
| 157 }else{ | |
| 158 updateDb <- FALSE | |
| 159 } | |
| 160 | |
| 161 if(!is.null(opt$copyDb)){ | |
| 162 copyDb <- TRUE | |
| 163 }else{ | |
| 164 copyDb <- FALSE | |
| 165 } | |
| 166 | |
| 167 if(!is.null(opt$l_rtrangeMax)){ | |
| 168 l_rtrangeMax <- opt$l_rtrangeMax | |
| 169 }else{ | |
| 170 l_rtrangeMax <- NA | |
| 171 } | |
| 172 | |
| 173 if(!is.null(opt$q_rtrangeMax)){ | |
| 174 q_rtrangeMax <- opt$q_rtrangeMax | |
| 175 }else{ | |
| 176 q_rtrangeMax <- NA | |
| 177 } | |
| 178 | |
| 179 if(!is.null(opt$l_rtrangeMin)){ | |
| 180 l_rtrangeMin <- opt$l_rtrangeMin | |
| 181 }else{ | |
| 182 l_rtrangeMin <- NA | |
| 183 } | |
| 184 | |
| 185 if(!is.null(opt$q_rtrangeMin)){ | |
| 186 q_rtrangeMin <- opt$q_rtrangeMin | |
| 187 }else{ | |
| 188 q_rtrangeMin <- NA | |
| 189 } | |
| 190 | |
| 191 | |
| 192 | |
| 193 sm <- msPurity::spectralMatching(q_dbPth = q_dbPth, | |
| 194 l_dbPth = l_dbPth, | |
| 195 | |
| 196 q_purity = opt$q_purity, | |
| 197 l_purity = opt$l_purity, | |
| 198 | |
| 199 q_ppmProd = opt$q_ppmProd, | |
| 200 l_ppmProd = opt$l_ppmProd, | |
| 201 | |
| 202 q_ppmPrec = opt$q_ppmPrec, | |
| 203 l_ppmPrec = opt$l_ppmPrec, | |
| 204 | |
| 205 q_raThres = opt$q_raThres, | |
| 206 l_raThres = opt$l_raThres, | |
| 207 | |
| 208 q_pol = q_polarity, | |
| 209 l_pol = l_polarity, | |
| 210 | |
| 211 q_xcmsGroups = q_xcmsGroups, | |
| 212 l_xcmsGroups = l_xcmsGroups, | |
| 213 | |
| 214 q_pids = q_pids, | |
| 215 l_pids = l_pids, | |
| 216 | |
| 217 q_sources = q_sources, | |
| 218 l_sources = l_sources, | |
| 219 | |
| 220 q_instrumentTypes = q_instrumentTypes, | |
| 221 l_instrumentTypes = l_instrumentTypes, | |
| 222 | |
| 223 q_spectraFilter= q_spectraFilter, | |
| 224 l_spectraFilter= l_spectraFilter, | |
| 225 | |
| 226 l_rtrange=c(l_rtrangeMin, l_rtrangeMax), | |
| 227 q_rtrange=c(q_rtrangeMin, q_rtrangeMax), | |
| 228 | |
| 229 q_accessions = opt$q_accessions, | |
| 230 l_accessions= opt$l_accessions, | |
| 231 | |
| 232 raW = opt$raW, | |
| 233 mzW = opt$mzW, | |
| 234 rttol=opt$rttol, | |
| 235 cores=opt$cores, | |
| 236 | |
| 237 copyDb=copyDb, | |
| 238 updateDb=updateDb, | |
| 239 outPth = "db_with_spectral_matching.sqlite" | |
| 240 ) | |
| 241 | |
| 242 | |
| 243 | |
| 244 write.table(sm$matchedResults, 'matched_results.tsv', sep = '\t', row.names = FALSE, col.names = TRUE) | |
| 245 write.table(sm$xcmsMatchedResults, 'xcms_matched_results.tsv', sep = '\t', row.names = FALSE, col.names = TRUE) |
