Mercurial > repos > tomnl > flag_remove_peaks
comparison frag4feature.R @ 13:ac2e4562b70a draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit a598583947118bd50cfe5ae12d955c20d6e502a6
| author | tomnl |
|---|---|
| date | Tue, 17 Jul 2018 12:20:30 -0400 |
| parents | cb8dce9812ff |
| children |
comparison
equal
deleted
inserted
replaced
| 12:cb8dce9812ff | 13:ac2e4562b70a |
|---|---|
| 1 library(optparse) | 1 library(optparse) |
| 2 library(msPurity) | 2 library(msPurity) |
| 3 library(xcms) | 3 library(xcms) |
| 4 print(sessionInfo()) | 4 print(sessionInfo()) |
| 5 | 5 |
| 6 xset_pa_filename_fix <- function(opt, pa, xset){ | 6 xset_pa_filename_fix <- function(opt, pa, xset=NULL){ |
| 7 | 7 |
| 8 | 8 |
| 9 if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){ | 9 if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){ |
| 10 # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables | 10 # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables |
| 11 # needs to be done due to Galaxy moving the files around and screwing up any links to files | 11 # needs to be done due to Galaxy moving the files around and screwing up any links to files |
| 24 names(pa@fileList) <- nsave | 24 names(pa@fileList) <- nsave |
| 25 | 25 |
| 26 pa@puritydf$filename <- basename(pa@fileList[match(pa@puritydf$filename, old_filenames)]) | 26 pa@puritydf$filename <- basename(pa@fileList[match(pa@puritydf$filename, old_filenames)]) |
| 27 pa@grped_df$filename <- basename(pa@fileList[match(pa@grped_df$filename, old_filenames)]) | 27 pa@grped_df$filename <- basename(pa@fileList[match(pa@grped_df$filename, old_filenames)]) |
| 28 } | 28 } |
| 29 print(pa@fileList) | 29 print(pa@fileList) |
| 30 print(xset@filepaths) | |
| 31 | 30 |
| 32 if(!all(basename(pa@fileList)==basename(xset@filepaths))){ | 31 if(!is.null(xset)){ |
| 33 if(!all(names(pa@fileList)==basename(xset@filepaths))){ | |
| 34 print('FILELISTS DO NOT MATCH') | |
| 35 message('FILELISTS DO NOT MATCH') | |
| 36 quit(status = 1) | |
| 37 }else{ | |
| 38 xset@filepaths <- unname(pa@fileList) | |
| 39 } | |
| 40 } | |
| 41 | 32 |
| 33 print(xset@filepaths) | |
| 34 | |
| 35 if(!all(basename(pa@fileList)==basename(xset@filepaths))){ | |
| 36 if(!all(names(pa@fileList)==basename(xset@filepaths))){ | |
| 37 print('FILELISTS DO NOT MATCH') | |
| 38 message('FILELISTS DO NOT MATCH') | |
| 39 quit(status = 1) | |
| 40 }else{ | |
| 41 xset@filepaths <- unname(pa@fileList) | |
| 42 } | |
| 43 } | |
| 44 } | |
| 42 | 45 |
| 43 return(list(pa, xset)) | 46 return(list(pa, xset)) |
| 44 } | 47 } |
| 45 | 48 |
| 46 | 49 |
| 54 make_option("--mostIntense", action="store_true"), | 57 make_option("--mostIntense", action="store_true"), |
| 55 make_option("--createDB", action="store_true"), | 58 make_option("--createDB", action="store_true"), |
| 56 make_option("--cores", default=4), | 59 make_option("--cores", default=4), |
| 57 make_option("--mzML_files", type="character"), | 60 make_option("--mzML_files", type="character"), |
| 58 make_option("--galaxy_names", type="character"), | 61 make_option("--galaxy_names", type="character"), |
| 59 make_option("--grp_peaklist", type="character") | 62 make_option("--grp_peaklist", type="character"), |
| 63 make_option("--use_group", action="store_true") | |
| 60 ) | 64 ) |
| 61 | 65 |
| 62 # store options | 66 # store options |
| 63 opt<- parse_args(OptionParser(option_list=option_list)) | 67 opt<- parse_args(OptionParser(option_list=option_list)) |
| 68 | |
| 69 print(opt) | |
| 64 | 70 |
| 65 loadRData <- function(rdata_path, name){ | 71 loadRData <- function(rdata_path, name){ |
| 66 #loads an RData file, and returns the named xset object if it is there | 72 #loads an RData file, and returns the named xset object if it is there |
| 67 load(rdata_path) | 73 load(rdata_path) |
| 68 return(get(ls()[ls() %in% name])) | 74 return(get(ls()[ls() %in% name])) |
| 109 createDB = FALSE | 115 createDB = FALSE |
| 110 }else{ | 116 }else{ |
| 111 createDB = TRUE | 117 createDB = TRUE |
| 112 } | 118 } |
| 113 | 119 |
| 120 if(is.null(opt$use_group)){ | |
| 121 fix <- xset_pa_filename_fix(opt, pa, xset) | |
| 122 pa <- fix[[1]] | |
| 123 xset <- fix[[2]] | |
| 124 use_group=FALSE | |
| 125 }else{ | |
| 126 # if are only aligning to the group not eah file we do not need to align the files between the xset and pa object | |
| 127 print('use_group') | |
| 128 fix <- xset_pa_filename_fix(opt, pa) | |
| 129 pa <- fix[[1]] | |
| 130 use_group=TRUE | |
| 131 } | |
| 114 | 132 |
| 115 fix <- xset_pa_filename_fix(opt, pa, xset) | |
| 116 pa <- fix[[1]] | |
| 117 xset <- fix[[2]] | |
| 118 | 133 |
| 119 if(is.null(opt$grp_peaklist)){ | 134 if(is.null(opt$grp_peaklist)){ |
| 120 grp_peaklist = NA | 135 grp_peaklist = NA |
| 121 }else{ | 136 }else{ |
| 122 grp_peaklist = opt$grp_peaklist | 137 grp_peaklist = opt$grp_peaklist |
| 128 saveRDS(pa, 'test_pa.rds') | 143 saveRDS(pa, 'test_pa.rds') |
| 129 | 144 |
| 130 pa <- msPurity::frag4feature(pa=pa, xset=xset, ppm=opt$ppm, plim=opt$plim, | 145 pa <- msPurity::frag4feature(pa=pa, xset=xset, ppm=opt$ppm, plim=opt$plim, |
| 131 intense=opt$mostIntense, convert2RawRT=convert2RawRT, | 146 intense=opt$mostIntense, convert2RawRT=convert2RawRT, |
| 132 db_name='alldata.sqlite', out_dir=opt$out_dir, grp_peaklist=grp_peaklist, | 147 db_name='alldata.sqlite', out_dir=opt$out_dir, grp_peaklist=grp_peaklist, |
| 133 create_db=createDB) | 148 create_db=createDB, use_group=use_group) |
| 134 | 149 |
| 135 save(pa, file=file.path(opt$out_dir, 'frag4feature.RData')) | 150 save(pa, file=file.path(opt$out_dir, 'frag4feature.RData')) |
| 136 | 151 |
| 137 print(head(pa@grped_df)) | 152 print(head(pa@grped_df)) |
| 138 write.table(pa@grped_df, file.path(opt$out_dir, 'frag4feature.tsv'), row.names=FALSE, sep='\t') | 153 write.table(pa@grped_df, file.path(opt$out_dir, 'frag4feature.tsv'), row.names=FALSE, sep='\t') |
