comparison createMSP.R @ 0:50eedf5ad217 draft

"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
author computational-metabolomics
date Wed, 27 Nov 2019 13:35:22 -0500
parents
children ccda730c6cf7
comparison
equal deleted inserted replaced
-1:000000000000 0:50eedf5ad217
1 library(optparse)
2 library(msPurity)
3 print(sessionInfo())
4
5 # Get the parameter
6 option_list <- list(
7 make_option("--rdata_input",type="character"),
8 make_option("--method",type="character"),
9 make_option("--metadata",type="character"),
10 make_option("--metadata_cols",type="character"),
11 make_option("--metadata_cols_filter",type="character"),
12 make_option("--adduct_split", action="store_true"),
13 make_option("--xcms_groupids",type="character"),
14 make_option("--filter",action="store_true"),
15 make_option("--intensity_ra",type="character"),
16 make_option("--include_adducts",type="character"),
17 make_option("--msp_schema",type="character"),
18 make_option("--out_dir",type="character", default=".")
19 )
20 opt <- parse_args(OptionParser(option_list=option_list))
21
22 print(opt)
23
24 load(opt$rdata_input)
25
26 if (is.null(opt$metadata)){
27 metadata <- NULL
28 }else{
29 metadata <- read.table(opt$metadata, header = TRUE, sep='\t', stringsAsFactors = FALSE, check.names = FALSE)
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
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
56
57 if(is.null(opt$adduct_split)){
58 adduct_split <- FALSE
59 }else{
60 adduct_split <- TRUE
61 }
62
63 if (is.null(opt$xcms_groupids)){
64 xcms_groupids <- NULL
65 }else{
66 xcms_groupids <- trimws(strsplit(opt$xcms_groupids, ',')[[1]])
67 }
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
82 if(is.null(opt$filter)){
83 filter <- FALSE
84 }else{
85 filter <- TRUE
86 }
87
88
89
90 msPurity::createMSP(pa,
91 msp_file_pth = file.path(opt$out_dir, 'lcmsms_spectra.msp'),
92 metadata = metadata,
93 metadata_cols = metadata_cols,
94 method = opt$method,
95 adduct_split = adduct_split,
96 xcms_groupids = xcms_groupids,
97 filter = filter,
98 intensity_ra=opt$intensity_ra,
99 include_adducts=include_adducts,
100 msp_schema=opt$msp_schema)
101
102 print('msp created')