annotate createDatabase.R @ 4:c635d8b0b929 draft

"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cbbd708ea1e93b1b1643f6bf6da72af65ffd9950"
author computational-metabolomics
date Mon, 10 Aug 2020 08:31:19 -0400
parents e570f604b357
children a67b129cd78e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
1 library(msPurity)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
2 library(optparse)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
3 library(xcms)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
4 library(CAMERA)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
5 print(sessionInfo())
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
6 print('CREATING DATABASE')
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
7
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
8 xset_pa_filename_fix <- function(opt, pa, xset){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
9
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
10 if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
11 # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
12 # needs to be done due to Galaxy moving the files around and screwing up any links to files
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
13
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
14 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]])
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
15 filepaths <- filepaths[filepaths != ""]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
16 new_names <- basename(filepaths)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
17
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
18 galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]])
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
19 galaxy_names <- galaxy_names[galaxy_names != ""]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
20
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
21 nsave <- names(pa@fileList)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
22 old_filenames <- basename(pa@fileList)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
23 pa@fileList <- filepaths[match(names(pa@fileList), galaxy_names)]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
24 names(pa@fileList) <- nsave
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
25
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
26 pa@puritydf$filename <- basename(pa@fileList[match(pa@puritydf$filename, old_filenames)])
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
27 pa@grped_df$filename <- basename(pa@fileList[match(pa@grped_df$filename, old_filenames)])
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
28 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
29
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
30
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
31 if(!all(basename(pa@fileList)==basename(xset@filepaths))){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
32 if(!all(names(pa@fileList)==basename(xset@filepaths))){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
33 print('FILELISTS DO NOT MATCH')
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
34 message('FILELISTS DO NOT MATCH')
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
35 quit(status = 1)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
36 }else{
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
37 xset@filepaths <- unname(pa@fileList)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
38 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
39 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
40
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
41 print(xset@phenoData)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
42 print(xset@filepaths)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
43
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
44 return(list(pa, xset))
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
45 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
46
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
47
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
48
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
49
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
50 option_list <- list(
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
51 make_option(c("-o", "--outDir"), type="character"),
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
52 make_option("--pa", type="character"),
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
53 make_option("--xset_xa", type="character"),
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
54 make_option("--xcms_camera_option", type="character"),
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
55 make_option("--eic", action="store_true"),
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
56 make_option("--cores", default=4),
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
57 make_option("--mzML_files", type="character"),
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
58 make_option("--galaxy_names", type="character"),
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
59 make_option("--grpPeaklist", type="character")
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
60 )
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
61
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
62
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
63 # store options
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
64 opt<- parse_args(OptionParser(option_list=option_list))
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
65 print(opt)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
66
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
67 loadRData <- function(rdata_path, name){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
68 #loads an RData file, and returns the named xset object if it is there
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
69 load(rdata_path)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
70 return(get(ls()[ls() %in% name]))
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
71 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
72
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
73 getxcmsSetObject <- function(xobject) {
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
74 # XCMS 1.x
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
75 if (class(xobject) == "xcmsSet")
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
76 return (xobject)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
77 # XCMS 3.x
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
78 if (class(xobject) == "XCMSnExp") {
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
79 # Get the legacy xcmsSet object
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
80 suppressWarnings(xset <- as(xobject, 'xcmsSet'))
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
81 sampclass(xset) <- xset@phenoData$sample_group
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
82 return (xset)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
83 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
84 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
85
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
86
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
87 print(paste('pa', opt$pa))
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
88 print(opt$xset)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
89
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
90 print(opt$xcms_camera_option)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
91 # Requires
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
92 pa <- loadRData(opt$pa, 'pa')
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
93
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
94
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
95 print(pa@fileList)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
96
4
c635d8b0b929 "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cbbd708ea1e93b1b1643f6bf6da72af65ffd9950"
computational-metabolomics
parents: 2
diff changeset
97 # Missing list element causes failures (should be updated
c635d8b0b929 "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cbbd708ea1e93b1b1643f6bf6da72af65ffd9950"
computational-metabolomics
parents: 2
diff changeset
98 # in msPurity R package for future releases)
c635d8b0b929 "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cbbd708ea1e93b1b1643f6bf6da72af65ffd9950"
computational-metabolomics
parents: 2
diff changeset
99 if (!exists('allfrag', where=pa@filter_frag_params)){
c635d8b0b929 "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cbbd708ea1e93b1b1643f6bf6da72af65ffd9950"
computational-metabolomics
parents: 2
diff changeset
100 pa@filter_frag_params$allfrag <- FALSE
c635d8b0b929 "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cbbd708ea1e93b1b1643f6bf6da72af65ffd9950"
computational-metabolomics
parents: 2
diff changeset
101 }
0
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
102
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
103 if (opt$xcms_camera_option=='xcms'){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
104
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
105 xset <- loadRData(opt$xset, c('xset','xdata'))
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
106 xset <- getxcmsSetObject(xset)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
107 fix <- xset_pa_filename_fix(opt, pa, xset)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
108 pa <- fix[[1]]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
109 xset <- fix[[2]]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
110 xa <- NULL
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
111 }else{
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
112
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
113 xa <- loadRData(opt$xset, 'xa')
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
114 fix <- xset_pa_filename_fix(opt, pa, xa@xcmsSet)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
115 pa <- fix[[1]]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
116 xa@xcmsSet <- fix[[2]]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
117 xset <- NULL
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
118 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
119
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
120
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
121
2
e570f604b357 "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 242de155f13acd6cb88946e89b5196ac55578aa8"
computational-metabolomics
parents: 0
diff changeset
122 if(is.null(opt$grpPeaklist)){
0
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
123 grpPeaklist = NA
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
124 }else{
2
e570f604b357 "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 242de155f13acd6cb88946e89b5196ac55578aa8"
computational-metabolomics
parents: 0
diff changeset
125 grpPeaklist = opt$grpPeaklist
0
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
126 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
127
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
128
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
129
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
130 dbPth <- msPurity::createDatabase(pa,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
131 xset=xset,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
132 xsa=xa,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
133 outDir=opt$outDir,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
134 grpPeaklist=grpPeaklist,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
135 dbName='createDatabase_output.sqlite'
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
136 )
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
137
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
138
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
139
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
140
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
141
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
142 if (!is.null(opt$eic)){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
143
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
144 if (is.null(xset)){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
145 xset <- xa@xcmsSet
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
146 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
147 # previous check should have matched filelists together
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
148 xset@filepaths <- unname(pa@fileList)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
149
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
150 convert2Raw <- function(x, xset){
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
151 sid <- unique(x$sample)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
152 # for each file get list of peaks
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
153 x$rt_raw <- xset@rt$raw[[sid]][match(x$rt, xset@rt$corrected[[sid]])]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
154 x$rtmin_raw <- xset@rt$raw[[sid]][match(x$rtmin, xset@rt$corrected[[sid]])]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
155 x$rtmax_raw <- xset@rt$raw[[sid]][match(x$rtmax, xset@rt$corrected[[sid]])]
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
156 return(x)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
157
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
158 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
159
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
160 xset@peaks <- as.matrix(plyr::ddply(data.frame(xset@peaks), ~ sample, convert2Raw, xset=xset))
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
161
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
162 # Saves the EICS into the previously created database
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
163 px <- msPurity::purityX(xset,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
164 saveEIC = TRUE,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
165 cores=1,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
166 sqlitePth=dbPth,
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
167 rtrawColumns = TRUE)
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
168
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
169 }
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
170
5d0461edc7fd "planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
computational-metabolomics
parents:
diff changeset
171 closeAllConnections()