Mercurial > repos > tomnl > mspurity_createmsp
comparison createMSP.R @ 12:5dd61e94d70d draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit bbbcc75d51c020446fd00d76f908a6250266cfea
| author | tomnl |
|---|---|
| date | Fri, 13 Sep 2019 11:53:46 -0400 |
| parents | df2efceff4cd |
| children |
comparison
equal
deleted
inserted
replaced
| 11:4b3b0f5a55d9 | 12:5dd61e94d70d |
|---|---|
| 2 library(msPurity) | 2 library(msPurity) |
| 3 print(sessionInfo()) | 3 print(sessionInfo()) |
| 4 | 4 |
| 5 # Get the parameter | 5 # Get the parameter |
| 6 option_list <- list( | 6 option_list <- list( |
| 7 make_option(c("-i","--rdata_input"),type="character"), | 7 make_option("--rdata_input",type="character"), |
| 8 make_option(c("-m","--method"),type="character"), | 8 make_option("--method",type="character"), |
| 9 make_option(c("-meta","--metadata"),type="character"), | 9 make_option("--metadata",type="character"), |
| 10 make_option(c("-metac","--metadata_cols"),type="character"), | 10 make_option("--metadata_cols",type="character"), |
| 11 make_option(c("-a","--adduct_split"),type="character"), | 11 make_option("--metadata_cols_filter",type="character"), |
| 12 make_option(c("-x","--xcms_groupids"),type="character"), | 12 make_option("--adduct_split", action="store_true"), |
| 13 make_option(c("-f","--filter"),action="store_true"), | 13 make_option("--xcms_groupids",type="character"), |
| 14 make_option("--filter",action="store_true"), | |
| 14 make_option("--intensity_ra",type="character"), | 15 make_option("--intensity_ra",type="character"), |
| 16 make_option("--include_adducts",type="character"), | |
| 15 make_option("--msp_schema",type="character"), | 17 make_option("--msp_schema",type="character"), |
| 16 make_option(c("-o","--out_dir"),type="character", default=".") | 18 make_option("--out_dir",type="character", default=".") |
| 17 ) | 19 ) |
| 18 opt <- parse_args(OptionParser(option_list=option_list)) | 20 opt <- parse_args(OptionParser(option_list=option_list)) |
| 19 | 21 |
| 20 print(opt) | 22 print(opt) |
| 21 | 23 |
| 23 | 25 |
| 24 if (is.null(opt$metadata)){ | 26 if (is.null(opt$metadata)){ |
| 25 metadata <- NULL | 27 metadata <- NULL |
| 26 }else{ | 28 }else{ |
| 27 metadata <- read.table(opt$metadata, header = TRUE, sep='\t', stringsAsFactors = FALSE, check.names = FALSE) | 29 metadata <- read.table(opt$metadata, header = TRUE, sep='\t', stringsAsFactors = FALSE, check.names = FALSE) |
| 28 print(head(metadata)) | 30 |
| 31 if(!opt$metadata_cols_filter==''){ | |
| 32 metadata_cols_filter <- strsplit(opt$metadata_cols_filter, ',')[[1]] | |
| 33 | |
| 34 metadata <- metadata[,metadata_cols_filter, drop=FALSE] | |
| 35 print(metadata) | |
| 36 | |
| 37 if (!"grpid" %in% colnames(metadata)){ | |
| 38 metadata$grpid <- 1:nrow(metadata) | |
| 39 } | |
| 40 | |
| 41 print(metadata) | |
| 42 | |
| 43 } | |
| 44 | |
| 29 } | 45 } |
| 46 | |
| 47 | |
| 48 | |
| 49 if (is.null(opt$metadata_cols) || opt$metadata_cols==''){ | |
| 50 metadata_cols <- NULL | |
| 51 }else{ | |
| 52 metadata_cols <- opt$metadata_cols | |
| 53 | |
| 54 } | |
| 55 | |
| 30 | 56 |
| 31 if(is.null(opt$adduct_split)){ | 57 if(is.null(opt$adduct_split)){ |
| 32 adduct_split <- FALSE | 58 adduct_split <- FALSE |
| 33 }else{ | 59 }else{ |
| 34 adduct_split <- TRUE | 60 adduct_split <- TRUE |
| 38 xcms_groupids <- NULL | 64 xcms_groupids <- NULL |
| 39 }else{ | 65 }else{ |
| 40 xcms_groupids <- trimws(strsplit(opt$xcms_groupids, ',')[[1]]) | 66 xcms_groupids <- trimws(strsplit(opt$xcms_groupids, ',')[[1]]) |
| 41 } | 67 } |
| 42 | 68 |
| 69 if (opt$include_adducts=='None'){ | |
| 70 include_adducts <- '' | |
| 71 }else{ | |
| 72 include_adducts <- opt$include_adducts | |
| 73 include_adducts <- gsub("__ob__", "[", include_adducts) | |
| 74 include_adducts <- gsub("__cb__", "]", include_adducts) | |
| 75 include_adducts <- trimws(include_adducts) | |
| 76 | |
| 77 include_adducts <- gsub(",", " ", include_adducts) | |
| 78 | |
| 79 } | |
| 80 | |
| 81 | |
| 43 if(is.null(opt$filter)){ | 82 if(is.null(opt$filter)){ |
| 44 filter <- FALSE | 83 filter <- FALSE |
| 45 }else{ | 84 }else{ |
| 46 filter <- TRUE | 85 filter <- TRUE |
| 47 } | 86 } |
| 48 | 87 |
| 88 | |
| 89 | |
| 49 msPurity::createMSP(pa, | 90 msPurity::createMSP(pa, |
| 50 msp_file_pth = file.path(opt$out_dir, 'lcmsms_spectra.msp'), | 91 msp_file_pth = file.path(opt$out_dir, 'lcmsms_spectra.msp'), |
| 51 metadata = metadata, | 92 metadata = metadata, |
| 52 metadata_cols = opt$metadata_cols, | 93 metadata_cols = metadata_cols, |
| 53 method = opt$method, | 94 method = opt$method, |
| 54 adduct_split = adduct_split, | 95 adduct_split = adduct_split, |
| 55 xcms_groupids = xcms_groupids, | 96 xcms_groupids = xcms_groupids, |
| 56 filter = filter, | 97 filter = filter, |
| 57 intensity_ra=opt$intensity_ra, | 98 intensity_ra=opt$intensity_ra, |
| 99 include_adducts=include_adducts, | |
| 58 msp_schema=opt$msp_schema) | 100 msp_schema=opt$msp_schema) |
| 59 | 101 |
| 60 print('msp created') | 102 print('msp created') |
