comparison createDatabase.R @ 0:ca0ac330f1a4 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2948ce35fa7fffe5a64711cb30be971031e79019-dirty
author tomnl
date Fri, 24 May 2019 09:13:42 -0400
parents
children 054189c06bb1
comparison
equal deleted inserted replaced
-1:000000000000 0:ca0ac330f1a4
1 library(msPurity)
2 library(optparse)
3 library(xcms)
4 library(CAMERA)
5 print(sessionInfo())
6 print('CREATING DATABASE')
7
8
9
10 xset_pa_filename_fix <- function(opt, pa, xset){
11
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
14 # needs to be done due to Galaxy moving the files around and screwing up any links to files
15
16 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]])
17 filepaths <- filepaths[filepaths != ""]
18 new_names <- basename(filepaths)
19
20 galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]])
21 galaxy_names <- galaxy_names[galaxy_names != ""]
22
23 nsave <- names(pa@fileList)
24 old_filenames <- basename(pa@fileList)
25 pa@fileList <- filepaths[match(names(pa@fileList), galaxy_names)]
26 names(pa@fileList) <- nsave
27
28 pa@puritydf$filename <- basename(pa@fileList[match(pa@puritydf$filename, old_filenames)])
29 pa@grped_df$filename <- basename(pa@fileList[match(pa@grped_df$filename, old_filenames)])
30 }
31
32
33 if(!all(basename(pa@fileList)==basename(xset@filepaths))){
34 if(!all(names(pa@fileList)==basename(xset@filepaths))){
35 print('FILELISTS DO NOT MATCH')
36 message('FILELISTS DO NOT MATCH')
37 quit(status = 1)
38 }else{
39 xset@filepaths <- unname(pa@fileList)
40 }
41 }
42
43 print(xset@phenoData)
44 print(xset@filepaths)
45
46 return(list(pa, xset))
47 }
48
49
50
51
52 option_list <- list(
53 make_option(c("-o", "--outDir"), type="character"),
54 make_option("--pa", type="character"),
55 make_option("--xset_xa", type="character"),
56 make_option("--xcms_camera_option", type="character"),
57 make_option("--eic", action="store_true"),
58 make_option("--cores", default=4),
59 make_option("--mzML_files", type="character"),
60 make_option("--galaxy_names", type="character"),
61 make_option("--grpPeaklist", type="character"),
62 make_option("--raw_rt_columns", action="store_true")
63 )
64
65
66 # store options
67 opt<- parse_args(OptionParser(option_list=option_list))
68 print(opt)
69
70 loadRData <- function(rdata_path, name){
71 #loads an RData file, and returns the named xset object if it is there
72 load(rdata_path)
73 return(get(ls()[ls() == name]))
74 }
75
76 print(paste('pa', opt$pa))
77 print(opt$xset)
78
79 print(opt$xcms_camera_option)
80 # Requires
81 pa <- loadRData(opt$pa, 'pa')
82
83
84 print(pa@fileList)
85
86
87 if (opt$xcms_camera_option=='xcms'){
88 xset <- loadRData(opt$xset, 'xset')
89 fix <- xset_pa_filename_fix(opt, pa, xset)
90 pa <- fix[[1]]
91 xset <- fix[[2]]
92 xa <- NULL
93 }else{
94
95 xa <- loadRData(opt$xset, 'xa')
96 fix <- xset_pa_filename_fix(opt, pa, xa@xcmsSet)
97 pa <- fix[[1]]
98 xa@xcmsSet <- fix[[2]]
99 xset <- NULL
100 }
101
102
103
104 if(is.null(opt$grp_peaklist)){
105 grpPeaklist = NA
106 }else{
107 grpPeaklist = opt$grp_peaklist
108 }
109
110
111
112 dbPth <- msPurity::createDatabase(pa,
113 xset=xset,
114 # xsa=xa,
115 outDir=opt$outDir,
116 # grpPeaklist=grpPeaklist,
117 dbName='createDatabase_output.sqlite'
118 )
119
120
121
122 if (!is.null(opt$eic)){
123 if (is.null(opt$raw_rt_columns)){
124 rtrawColumns <- FALSE
125 }else{
126 rtrawColumns <- TRUE
127 }
128 if (is.null(xset)){
129 xset <- xa@xcmsSet
130 }
131 # previous check should have matched filelists together
132 xset@filepaths <- unname(pa@fileList)
133
134 # Saves the EICS into the previously created database
135 px <- msPurity::purityX(xset, saveEIC = TRUE,
136 cores=1, sqlitePth=db_pth,
137 rtrawColumns = rtrawColumns)
138 }
139
140 con <- DBI::dbConnect(RSQLite::SQLite(), dbPth)