Mercurial > repos > tomnl > track_rt_raw
comparison frag4feature.R @ 1:e2635fa802bd draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2e847122cf605951c334858455fc1d3ebdb189e9-dirty
| author | tomnl |
|---|---|
| date | Tue, 27 Mar 2018 05:36:22 -0400 |
| parents | b96fc0da0a32 |
| children | 26fd52ed6d21 |
comparison
equal
deleted
inserted
replaced
| 0:b96fc0da0a32 | 1:e2635fa802bd |
|---|---|
| 1 library(optparse) | |
| 1 library(msPurity) | 2 library(msPurity) |
| 2 library(optparse) | 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 | |
| 3 | 43 |
| 4 option_list <- list( | 44 option_list <- list( |
| 5 make_option(c("-o", "--out_dir"), type="character"), | 45 make_option(c("-o", "--out_dir"), type="character"), |
| 6 make_option("--pa", type="character"), | 46 make_option("--pa", type="character"), |
| 7 make_option("--xset", type="character"), | 47 make_option("--xset", type="character"), |
| 8 make_option("--ppm", default=10), | 48 make_option("--ppm", default=10), |
| 9 make_option("--plim", default=0.0), | 49 make_option("--plim", default=0.0), |
| 10 make_option("--convert2RawRT", action="store_true"), | 50 make_option("--convert2RawRT", action="store_true"), |
| 11 make_option("--mostIntense", action="store_true"), | 51 make_option("--mostIntense", action="store_true"), |
| 52 make_option("--createDB", action="store_true"), | |
| 12 make_option("--cores", default=4), | 53 make_option("--cores", default=4), |
| 13 make_option("--mzML_files", type="character"), | 54 make_option("--mzML_files", type="character"), |
| 14 make_option("--galaxy_names", type="character"), | 55 make_option("--galaxy_names", type="character"), |
| 15 make_option("--grp_peaklist", type="character") | 56 make_option("--grp_peaklist", type="character") |
| 16 ) | 57 ) |
| 28 pa <- loadRData(opt$pa, 'pa') | 69 pa <- loadRData(opt$pa, 'pa') |
| 29 xset <- loadRData(opt$xset, 'xset') | 70 xset <- loadRData(opt$xset, 'xset') |
| 30 | 71 |
| 31 pa@cores <- opt$cores | 72 pa@cores <- opt$cores |
| 32 | 73 |
| 74 print(pa@fileList) | |
| 75 print(xset@filepaths) | |
| 76 | |
| 33 if(is.null(opt$mostIntense)){ | 77 if(is.null(opt$mostIntense)){ |
| 34 mostIntense = FALSE | 78 mostIntense = FALSE |
| 35 }else{ | 79 }else{ |
| 36 mostIntense = TRUE | 80 mostIntense = TRUE |
| 37 } | 81 } |
| 40 convert2RawRT = FALSE | 84 convert2RawRT = FALSE |
| 41 }else{ | 85 }else{ |
| 42 convert2RawRT= TRUE | 86 convert2RawRT= TRUE |
| 43 } | 87 } |
| 44 | 88 |
| 45 # Makes sure the same files are being used | 89 if(is.null(opt$createDB)){ |
| 46 if(!all(basename(pa@fileList)==basename(xset@filepaths))){ | 90 createDB = FALSE |
| 47 if(!all(names(pa@fileList)==basename(xset@filepaths))){ | 91 }else{ |
| 48 quit(status = 1) | 92 createDB = TRUE |
| 49 }else{ | |
| 50 xset@filepaths <- unname(pa@fileList) | |
| 51 } | |
| 52 } | 93 } |
| 53 | 94 |
| 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 | 95 |
| 62 galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]]) | 96 fix <- xset_pa_filename_fix(opt, pa, xset) |
| 63 galaxy_names <- galaxy_names[galaxy_names != ""] | 97 pa <- fix[[1]] |
| 64 | 98 xset <- fix[[2]] |
| 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 | 99 |
| 81 if(is.null(opt$grp_peaklist)){ | 100 if(is.null(opt$grp_peaklist)){ |
| 82 grp_peaklist = NA | 101 grp_peaklist = NA |
| 102 | |
| 103 | |
| 83 }else{ | 104 }else{ |
| 84 grp_peaklist = opt$grp_peaklist | 105 grp_peaklist = opt$grp_peaklist |
| 85 } | 106 } |
| 86 | 107 |
| 87 print(pa) | 108 print('heck') |
| 88 print(pa@fileList) | 109 print(pa@fileList) |
| 89 print(xset) | 110 print(names(pa@fileList)) |
| 90 print(xset@filepaths) | 111 print(xset@filepaths) |
| 91 print(opt$ppm) | 112 saveRDS(pa, 'test_pa.rds') |
| 92 print(opt$plim) | |
| 93 print(convert2RawRT) | |
| 94 | |
| 95 | |
| 96 | |
| 97 | 113 |
| 98 pa <- msPurity::frag4feature(pa=pa, xset=xset, ppm=opt$ppm, plim=opt$plim, | 114 pa <- msPurity::frag4feature(pa=pa, xset=xset, ppm=opt$ppm, plim=opt$plim, |
| 99 intense=opt$mostIntense, convert2RawRT=convert2RawRT, | 115 intense=opt$mostIntense, convert2RawRT=convert2RawRT, |
| 100 db_name='alldata.sqlite', out_dir=opt$out_dir, grp_peaklist=grp_peaklist) | 116 db_name='alldata.sqlite', out_dir=opt$out_dir, grp_peaklist=grp_peaklist, |
| 117 create_db=createDB) | |
| 101 | 118 |
| 102 save(pa, file=file.path(opt$out_dir, 'frag4feature.RData')) | 119 save(pa, file=file.path(opt$out_dir, 'frag4feature.RData')) |
| 103 | 120 |
| 104 print(head(pa@grped_df)) | 121 print(head(pa@grped_df)) |
| 105 write.table(pa@grped_df, file.path(opt$out_dir, 'frag4feature.tsv'), row.names=FALSE, sep='\t') | 122 write.table(pa@grped_df, file.path(opt$out_dir, 'frag4feature.tsv'), row.names=FALSE, sep='\t') |
