comparison createMSP.R @ 6:a67b129cd78e draft

"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
author computational-metabolomics
date Thu, 04 Mar 2021 12:30:15 +0000
parents d2373ced0ded
children a0ee43397d1e
comparison
equal deleted inserted replaced
5:4b627470dea2 6:a67b129cd78e
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("--rdata_input",type="character"), 7 make_option("--rdata_input", type = "character"),
8 make_option("--method",type="character"), 8 make_option("--method", type = "character"),
9 make_option("--metadata",type="character"), 9 make_option("--metadata", type = "character"),
10 make_option("--metadata_cols",type="character"), 10 make_option("--metadata_cols", type = "character"),
11 make_option("--metadata_cols_filter",type="character"), 11 make_option("--metadata_cols_filter", type = "character"),
12 make_option("--adduct_split", action="store_true"), 12 make_option("--adduct_split", action = "store_true"),
13 make_option("--xcms_groupids",type="character"), 13 make_option("--xcms_groupids", type = "character"),
14 make_option("--filter",action="store_true"), 14 make_option("--filter", action = "store_true"),
15 make_option("--intensity_ra",type="character"), 15 make_option("--intensity_ra", type = "character"),
16 make_option("--include_adducts",type="character"), 16 make_option("--include_adducts", type = "character"),
17 make_option("--msp_schema",type="character"), 17 make_option("--msp_schema", type = "character"),
18 make_option("--include_adducts_custom",type="character", default=""), 18 make_option("--include_adducts_custom", type = "character", default = ""),
19 make_option("--out_dir",type="character", default=".") 19 make_option("--out_dir", type = "character", default = ".")
20 ) 20 )
21 opt <- parse_args(OptionParser(option_list=option_list)) 21 opt <- parse_args(OptionParser(option_list = option_list))
22 22
23 print(opt) 23 print(opt)
24 24
25 load(opt$rdata_input) 25 load(opt$rdata_input)
26 26
27 if (is.null(opt$metadata)){ 27 if (is.null(opt$metadata)) {
28 metadata <- NULL 28 metadata <- NULL
29 }else{ 29 }else{
30 metadata <- read.table(opt$metadata, header = TRUE, sep='\t', stringsAsFactors = FALSE, check.names = FALSE) 30 metadata <- read.table(opt$metadata, header = TRUE, sep = "\t",
31 stringsAsFactors = FALSE, check.names = FALSE)
31 32
32 if(!opt$metadata_cols_filter==''){ 33 if (!opt$metadata_cols_filter == "") {
33 metadata_cols_filter <- strsplit(opt$metadata_cols_filter, ',')[[1]] 34 metadata_cols_filter <- strsplit(opt$metadata_cols_filter, ",")[[1]]
34 35
35 metadata <- metadata[,metadata_cols_filter, drop=FALSE] 36 metadata <- metadata[, metadata_cols_filter, drop = FALSE]
36 print(metadata) 37 print(metadata)
37 38
38 if (!"grpid" %in% colnames(metadata)){ 39 if (!"grpid" %in% colnames(metadata)) {
39 metadata$grpid <- 1:nrow(metadata) 40 metadata$grpid <- seq_len(nrow(metadata))
40 } 41 }
41 42
42 print(metadata) 43 print(metadata)
43 44
44 } 45 }
45 46
46 } 47 }
47 48
48 49
49 50
50 if (is.null(opt$metadata_cols) || opt$metadata_cols==''){ 51 if (is.null(opt$metadata_cols) || opt$metadata_cols == "") {
51 metadata_cols <- NULL 52 metadata_cols <- NULL
52 }else{ 53 }else{
53 metadata_cols <- opt$metadata_cols 54 metadata_cols <- opt$metadata_cols
54 55
55 } 56 }
56 57
57 58
58 if(is.null(opt$adduct_split)){ 59 if (is.null(opt$adduct_split)) {
59 adduct_split <- FALSE 60 adduct_split <- FALSE
60 }else{ 61 }else{
61 adduct_split <- TRUE 62 adduct_split <- TRUE
62 } 63 }
63 64
64 if (is.null(opt$xcms_groupids)){ 65 if (is.null(opt$xcms_groupids)) {
65 xcms_groupids <- NULL 66 xcms_groupids <- NULL
66 }else{ 67 }else{
67 xcms_groupids <- trimws(strsplit(opt$xcms_groupids, ',')[[1]]) 68 xcms_groupids <- trimws(strsplit(opt$xcms_groupids, ",")[[1]])
68 } 69 }
69 70
70 71
71 72 if (is.null(opt$include_adducts_custom)) {
72 73 include_adducts_custom <- ""
73
74 if (is.null(opt$include_adducts_custom)){
75 include_adducts_custom <- ''
76 }else{ 74 }else{
77 include_adducts_custom <- opt$include_adducts_custom 75 include_adducts_custom <- opt$include_adducts_custom
78 } 76 }
79 77
80 78
81 if (opt$include_adducts=='None'){ 79 if (opt$include_adducts == "None") {
82 include_adducts <- '' 80 include_adducts <- ""
83 }else{ 81 }else{
84 include_adducts <- opt$include_adducts 82 include_adducts <- opt$include_adducts
85 } 83 }
86 84
87 include_adducts_all <- paste(include_adducts_custom, ',', include_adducts, sep="") 85 include_adducts_all <- paste(include_adducts_custom, ",", include_adducts, sep = "")
88 86
89 include_adducts_all <- gsub("^,", "", include_adducts_all) 87 include_adducts_all <- gsub("^,", "", include_adducts_all)
90 include_adducts_all <- gsub(",$", "", include_adducts_all) 88 include_adducts_all <- gsub(",$", "", include_adducts_all)
91 89
92 include_adducts_all <- gsub("__ob__", "[", include_adducts_all) 90 include_adducts_all <- gsub("__ob__", "[", include_adducts_all)
94 include_adducts_all <- trimws(include_adducts_all) 92 include_adducts_all <- trimws(include_adducts_all)
95 include_adducts_all <- gsub(",", " ", include_adducts_all) 93 include_adducts_all <- gsub(",", " ", include_adducts_all)
96 94
97 95
98 96
99 if(is.null(opt$filter)){ 97 if (is.null(opt$filter)) {
100 filter <- FALSE 98 filter <- FALSE
101 }else{ 99 }else{
102 filter <- TRUE 100 filter <- TRUE
103 } 101 }
104 102
105 103
106 104
107 msPurity::createMSP(pa, 105 msPurity::createMSP(pa,
108 msp_file_pth = file.path(opt$out_dir, 'lcmsms_spectra.msp'), 106 msp_file_pth = file.path(opt$out_dir, "lcmsms_spectra.msp"),
109 metadata = metadata, 107 metadata = metadata,
110 metadata_cols = metadata_cols, 108 metadata_cols = metadata_cols,
111 method = opt$method, 109 method = opt$method,
112 adduct_split = adduct_split, 110 adduct_split = adduct_split,
113 xcms_groupids = xcms_groupids, 111 xcms_groupids = xcms_groupids,
114 filter = filter, 112 filter = filter,
115 intensity_ra=opt$intensity_ra, 113 intensity_ra = opt$intensity_ra,
116 include_adducts=include_adducts_all, 114 include_adducts = include_adducts_all,
117 msp_schema=opt$msp_schema) 115 msp_schema = opt$msp_schema)
118 116
119 print('msp created') 117 print("msp created")