comparison frag4feature.R @ 0:b96fc0da0a32 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f9591483bef88aef71a9f0cc0ffc75cf6eab480c
author tomnl
date Mon, 05 Mar 2018 10:05:57 -0500
parents
children e2635fa802bd
comparison
equal deleted inserted replaced
-1:000000000000 0:b96fc0da0a32
1 library(msPurity)
2 library(optparse)
3
4 option_list <- list(
5 make_option(c("-o", "--out_dir"), type="character"),
6 make_option("--pa", type="character"),
7 make_option("--xset", type="character"),
8 make_option("--ppm", default=10),
9 make_option("--plim", default=0.0),
10 make_option("--convert2RawRT", action="store_true"),
11 make_option("--mostIntense", action="store_true"),
12 make_option("--cores", default=4),
13 make_option("--mzML_files", type="character"),
14 make_option("--galaxy_names", type="character"),
15 make_option("--grp_peaklist", type="character")
16 )
17
18 # store options
19 opt<- parse_args(OptionParser(option_list=option_list))
20
21 loadRData <- function(rdata_path, name){
22 #loads an RData file, and returns the named xset object if it is there
23 load(rdata_path)
24 return(get(ls()[ls() == name]))
25 }
26
27 # Requires
28 pa <- loadRData(opt$pa, 'pa')
29 xset <- loadRData(opt$xset, 'xset')
30
31 pa@cores <- opt$cores
32
33 if(is.null(opt$mostIntense)){
34 mostIntense = FALSE
35 }else{
36 mostIntense = TRUE
37 }
38
39 if(is.null(opt$convert2RawRT)){
40 convert2RawRT = FALSE
41 }else{
42 convert2RawRT= TRUE
43 }
44
45 # Makes sure the same files are being used
46 if(!all(basename(pa@fileList)==basename(xset@filepaths))){
47 if(!all(names(pa@fileList)==basename(xset@filepaths))){
48 quit(status = 1)
49 }else{
50 xset@filepaths <- unname(pa@fileList)
51 }
52 }
53
54 if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){
55 # NOTE: This only works if the pa file was generated IN Galaxy!! Relies on
56 # the pa@fileList having the names of files given as 'names' of the variables (done in frag4feature)
57 # Will update in the next version of msPurity
58 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]])
59 filepaths <- filepaths[filepaths != ""]
60 new_names <- basename(filepaths)
61
62 galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]])
63 galaxy_names <- galaxy_names[galaxy_names != ""]
64
65 nsave <- names(pa@fileList)
66 old_filenames <- basename(pa@fileList)
67 pa@fileList <- filepaths[match(names(pa@fileList), galaxy_names)]
68
69 pa@puritydf$filename <- basename(pa@fileList[match(pa@puritydf$filename, old_filenames)])
70 pa@grped_df$filename <- basename(pa@fileList[match(pa@grped_df$filename, old_filenames)])
71 }
72
73 if(!all(basename(pa@fileList)==basename(xset@filepaths))){
74 if(!all(names(pa@fileList)==basename(xset@filepaths))){
75 quit(status = 1)
76 }else{
77 xset@filepaths <- unname(pa@fileList)
78 }
79 }
80
81 if(is.null(opt$grp_peaklist)){
82 grp_peaklist = NA
83 }else{
84 grp_peaklist = opt$grp_peaklist
85 }
86
87 print(pa)
88 print(pa@fileList)
89 print(xset)
90 print(xset@filepaths)
91 print(opt$ppm)
92 print(opt$plim)
93 print(convert2RawRT)
94
95
96
97
98 pa <- msPurity::frag4feature(pa=pa, xset=xset, ppm=opt$ppm, plim=opt$plim,
99 intense=opt$mostIntense, convert2RawRT=convert2RawRT,
100 db_name='alldata.sqlite', out_dir=opt$out_dir, grp_peaklist=grp_peaklist)
101
102 save(pa, file=file.path(opt$out_dir, 'frag4feature.RData'))
103
104 print(head(pa@grped_df))
105 write.table(pa@grped_df, file.path(opt$out_dir, 'frag4feature.tsv'), row.names=FALSE, sep='\t')