Mercurial > repos > tomnl > create_sqlite_db
comparison frag4feature.R @ 0:fe7d7cc95ca5 draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2e847122cf605951c334858455fc1d3ebdb189e9-dirty
author | tomnl |
---|---|
date | Tue, 27 Mar 2018 06:03:50 -0400 |
parents | |
children | 1a88758357ed |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fe7d7cc95ca5 |
---|---|
1 library(optparse) | |
2 library(msPurity) | |
3 library(xcms) | |
4 | |
5 xset_pa_filename_fix <- function(opt, pa, xset){ | |
6 | |
7 | |
8 if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){ | |
9 # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables | |
10 # needs to be done due to Galaxy moving the files around and screwing up any links to files | |
11 | |
12 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]]) | |
13 filepaths <- filepaths[filepaths != ""] | |
14 new_names <- basename(filepaths) | |
15 | |
16 galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]]) | |
17 galaxy_names <- galaxy_names[galaxy_names != ""] | |
18 | |
19 nsave <- names(pa@fileList) | |
20 old_filenames <- basename(pa@fileList) | |
21 pa@fileList <- filepaths[match(names(pa@fileList), galaxy_names)] | |
22 names(pa@fileList) <- nsave | |
23 | |
24 pa@puritydf$filename <- basename(pa@fileList[match(pa@puritydf$filename, old_filenames)]) | |
25 pa@grped_df$filename <- basename(pa@fileList[match(pa@grped_df$filename, old_filenames)]) | |
26 } | |
27 | |
28 | |
29 if(!all(basename(pa@fileList)==basename(xset@filepaths))){ | |
30 if(!all(names(pa@fileList)==basename(xset@filepaths))){ | |
31 print('FILELISTS DO NOT MATCH') | |
32 message('FILELISTS DO NOT MATCH') | |
33 quit(status = 1) | |
34 }else{ | |
35 xset@filepaths <- unname(pa@fileList) | |
36 } | |
37 } | |
38 | |
39 | |
40 return(list(pa, xset)) | |
41 } | |
42 | |
43 | |
44 option_list <- list( | |
45 make_option(c("-o", "--out_dir"), type="character"), | |
46 make_option("--pa", type="character"), | |
47 make_option("--xset", type="character"), | |
48 make_option("--ppm", default=10), | |
49 make_option("--plim", default=0.0), | |
50 make_option("--convert2RawRT", action="store_true"), | |
51 make_option("--mostIntense", action="store_true"), | |
52 make_option("--createDB", action="store_true"), | |
53 make_option("--cores", default=4), | |
54 make_option("--mzML_files", type="character"), | |
55 make_option("--galaxy_names", type="character"), | |
56 make_option("--grp_peaklist", type="character") | |
57 ) | |
58 | |
59 # store options | |
60 opt<- parse_args(OptionParser(option_list=option_list)) | |
61 | |
62 loadRData <- function(rdata_path, name){ | |
63 #loads an RData file, and returns the named xset object if it is there | |
64 load(rdata_path) | |
65 return(get(ls()[ls() == name])) | |
66 } | |
67 | |
68 # Requires | |
69 pa <- loadRData(opt$pa, 'pa') | |
70 xset <- loadRData(opt$xset, 'xset') | |
71 | |
72 pa@cores <- opt$cores | |
73 | |
74 print(pa@fileList) | |
75 print(xset@filepaths) | |
76 | |
77 if(is.null(opt$mostIntense)){ | |
78 mostIntense = FALSE | |
79 }else{ | |
80 mostIntense = TRUE | |
81 } | |
82 | |
83 if(is.null(opt$convert2RawRT)){ | |
84 convert2RawRT = FALSE | |
85 }else{ | |
86 convert2RawRT= TRUE | |
87 } | |
88 | |
89 if(is.null(opt$createDB)){ | |
90 createDB = FALSE | |
91 }else{ | |
92 createDB = TRUE | |
93 } | |
94 | |
95 | |
96 fix <- xset_pa_filename_fix(opt, pa, xset) | |
97 pa <- fix[[1]] | |
98 xset <- fix[[2]] | |
99 | |
100 if(is.null(opt$grp_peaklist)){ | |
101 grp_peaklist = NA | |
102 | |
103 | |
104 }else{ | |
105 grp_peaklist = opt$grp_peaklist | |
106 } | |
107 | |
108 print('heck') | |
109 print(pa@fileList) | |
110 print(names(pa@fileList)) | |
111 print(xset@filepaths) | |
112 saveRDS(pa, 'test_pa.rds') | |
113 | |
114 pa <- msPurity::frag4feature(pa=pa, xset=xset, ppm=opt$ppm, plim=opt$plim, | |
115 intense=opt$mostIntense, convert2RawRT=convert2RawRT, | |
116 db_name='alldata.sqlite', out_dir=opt$out_dir, grp_peaklist=grp_peaklist, | |
117 create_db=createDB) | |
118 | |
119 save(pa, file=file.path(opt$out_dir, 'frag4feature.RData')) | |
120 | |
121 print(head(pa@grped_df)) | |
122 write.table(pa@grped_df, file.path(opt$out_dir, 'frag4feature.tsv'), row.names=FALSE, sep='\t') |