comparison createDatabase.R @ 3:0a3e6c28f1ab draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit e05cb49ba56d359fec34f132d1c9ace582e5b483-dirty
author tomnl
date Tue, 18 Jun 2019 10:02:43 -0400
parents b1d4689e8a26
children e96c518a3f06
comparison
equal deleted inserted replaced
2:b1d4689e8a26 3:0a3e6c28f1ab
8 8
9 9
10 xset_pa_filename_fix <- function(opt, pa, xset){ 10 xset_pa_filename_fix <- function(opt, pa, xset){
11 11
12 if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){ 12 if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){
13 # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables 13 # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables
14 # needs to be done due to Galaxy moving the files around and screwing up any links to files 14 # needs to be done due to Galaxy moving the files around and screwing up any links to files
15 15
16 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]]) 16 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]])
17 filepaths <- filepaths[filepaths != ""] 17 filepaths <- filepaths[filepaths != ""]
18 new_names <- basename(filepaths) 18 new_names <- basename(filepaths)
56 make_option("--xcms_camera_option", type="character"), 56 make_option("--xcms_camera_option", type="character"),
57 make_option("--eic", action="store_true"), 57 make_option("--eic", action="store_true"),
58 make_option("--cores", default=4), 58 make_option("--cores", default=4),
59 make_option("--mzML_files", type="character"), 59 make_option("--mzML_files", type="character"),
60 make_option("--galaxy_names", type="character"), 60 make_option("--galaxy_names", type="character"),
61 make_option("--grpPeaklist", type="character"), 61 make_option("--grpPeaklist", type="character")
62 make_option("--raw_rt_columns", action="store_true")
63 ) 62 )
64 63
65 64
66 # store options 65 # store options
67 opt<- parse_args(OptionParser(option_list=option_list)) 66 opt<- parse_args(OptionParser(option_list=option_list))
98 print(pa@fileList) 97 print(pa@fileList)
99 98
100 99
101 100
102 if (opt$xcms_camera_option=='xcms'){ 101 if (opt$xcms_camera_option=='xcms'){
103 102
104 xset <- loadRData(opt$xset, c('xset','xdata')) 103 xset <- loadRData(opt$xset, c('xset','xdata'))
105 xset <- getxcmsSetObject(xset) 104 xset <- getxcmsSetObject(xset)
106 fix <- xset_pa_filename_fix(opt, pa, xset) 105 fix <- xset_pa_filename_fix(opt, pa, xset)
107 pa <- fix[[1]] 106 pa <- fix[[1]]
108 xset <- fix[[2]] 107 xset <- fix[[2]]
109 xa <- NULL 108 xa <- NULL
110 }else{ 109 }else{
111 110
112 xa <- loadRData(opt$xset, 'xa') 111 xa <- loadRData(opt$xset, 'xa')
113 fix <- xset_pa_filename_fix(opt, pa, xa@xcmsSet) 112 fix <- xset_pa_filename_fix(opt, pa, xa@xcmsSet)
114 pa <- fix[[1]] 113 pa <- fix[[1]]
115 xa@xcmsSet <- fix[[2]] 114 xa@xcmsSet <- fix[[2]]
116 xset <- NULL 115 xset <- NULL
117 } 116 }
118 117
126 125
127 126
128 127
129 dbPth <- msPurity::createDatabase(pa, 128 dbPth <- msPurity::createDatabase(pa,
130 xset=xset, 129 xset=xset,
131 xsa=xa, 130 xsa=xa,
132 outDir=opt$outDir, 131 outDir=opt$outDir,
133 grpPeaklist=grpPeaklist, 132 grpPeaklist=grpPeaklist,
134 dbName='createDatabase_output.sqlite' 133 dbName='createDatabase_output.sqlite'
135 ) 134 )
136 135
137 136
138 137
138
139
139 if (!is.null(opt$eic)){ 140 if (!is.null(opt$eic)){
140 if (is.null(opt$raw_rt_columns)){ 141
141 rtrawColumns <- FALSE
142 }else{
143 rtrawColumns <- TRUE
144 }
145 if (is.null(xset)){ 142 if (is.null(xset)){
146 xset <- xa@xcmsSet 143 xset <- xa@xcmsSet
147 } 144 }
148 # previous check should have matched filelists together 145 # previous check should have matched filelists together
149 xset@filepaths <- unname(pa@fileList) 146 xset@filepaths <- unname(pa@fileList)
150 147
148 convert2Raw <- function(x, xset){
149 sid <- unique(x$sample)
150 # for each file get list of peaks
151 x$rt_raw <- xset@rt$raw[[sid]][match(x$rt, xset@rt$corrected[[sid]])]
152 x$rtmin_raw <- xset@rt$raw[[sid]][match(x$rtmin, xset@rt$corrected[[sid]])]
153 x$rtmax_raw <- xset@rt$raw[[sid]][match(x$rtmax, xset@rt$corrected[[sid]])]
154 return(x)
155
156 }
157
158 xset@peaks <- as.matrix(plyr::ddply(data.frame(xset@peaks), ~ sample, convert2Raw, xset=xset))
159
151 # Saves the EICS into the previously created database 160 # Saves the EICS into the previously created database
152 px <- msPurity::purityX(xset, saveEIC = TRUE, 161 px <- msPurity::purityX(xset, saveEIC = TRUE,
153 cores=1, sqlitePth=db_pth, 162 cores=1, sqlitePth=db_pth,
154 rtrawColumns = rtrawColumns) 163 rtrawColumns = TRUE)
164
155 } 165 }
156 166
157 con <- DBI::dbConnect(RSQLite::SQLite(), dbPth) 167 closeAllConnections()