comparison flagRemove.R @ 9:10e56e53668c draft default tip

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 20a48a1862267264f98b7c514287f9a5cba1143f
author computational-metabolomics
date Thu, 13 Jun 2024 11:41:39 +0000
parents 33d733850e85
children
comparison
equal deleted inserted replaced
8:33d733850e85 9:10e56e53668c
1 library(msPurity) 1 library(msPurity)
2 library(xcms)
2 library(optparse) 3 library(optparse)
3 print(sessionInfo()) 4 print(sessionInfo())
4 option_list <- list( 5 option_list <- list(
5 make_option(c("-o", "--out_dir"), 6 make_option(c("-o", "--out_dir"),
6 type = "character", default = getwd(), 7 type = "character", default = getwd(),
115 } 116 }
116 117
117 118
118 print(opt) 119 print(opt)
119 120
120 getxcmsSetObject <- function(xobject) { 121 # This R function can handle both XCMS object versions (so following code
121 # XCMS 1.x 122 # no longer required - kept here for reference)
122 if (class(xobject) == "xcmsSet") { 123 # getxcmsSetObject <- function(xobject) {
123 return(xobject) 124 # # XCMS 1.x
124 } 125 # if (class(xobject) == "xcmsSet"){
125 # XCMS 3.x 126 # return(xobject)
126 if (class(xobject) == "XCMSnExp") { 127 # }
127 # Get the legacy xcmsSet object 128 # # XCMS 3.x
128 suppressWarnings(xset <- as(xobject, "xcmsSet")) 129 # if (class(xobject) == "XCMSnExp") {
129 xcms::sampclass(xset) <- xset@phenoData$sample_group 130 # # Get the legacy xcmsSet object
130 return(xset) 131 # suppressWarnings(xset <- as(xobject, "xcmsSet"))
131 } 132 # if (!is.null(xset@phenoData$sample_group)){
132 } 133 # xcms::sampclass(xset) <- xset@phenoData$sample_group
134 # }else{
135 # xcms::sampclass(xset) <- "."
136 # }
137 # return(xset)
138 # }
139 # }
133 140
134 141
135 loadRData <- function(rdata_path, name) { 142 loadRData <- function(rdata_path, name) {
136 # loads an RData file, and returns the named xset object if it is there 143 # loads an RData file, and returns the named xset object if it is there
137 load(rdata_path) 144 load(rdata_path)
138 return(get(ls()[ls() %in% name])) 145 return(get(ls()[ls() %in% name]))
139 } 146 }
140 147
141 xset <- getxcmsSetObject(loadRData(opt$xset_path, c("xset", "xdata"))) 148 xset <- loadRData(opt$xset_path, c("xset", "xdata"))
142 149
143 print(xset) 150
144 if (is.null(opt$samplelist)) { 151 if (is.null(opt$samplelist)) {
145 blank_class <- opt$blank_class 152 blank_class <- opt$blank_class
146 } else { 153 } else {
147 samplelist <- read.table(opt$samplelist, sep = "\t", header = TRUE) 154 samplelist <- read.table(opt$samplelist, sep = "\t", header = TRUE)
148 samplelist_blank <- unique(samplelist$sample_class[samplelist$blank == "yes"]) 155 samplelist_blank <- unique(samplelist$sample_class[samplelist$blank == "yes"])
153 quit() 160 quit()
154 } 161 }
155 blank_class <- as.character(chosen_blank) 162 blank_class <- as.character(chosen_blank)
156 print(blank_class) 163 print(blank_class)
157 } 164 }
165
166
158 167
159 168
160 if (is.null(opt$multilist)) { 169 if (is.null(opt$multilist)) {
161 ffrm_out <- flag_remove(xset, 170 ffrm_out <- flag_remove(xset,
162 pol = opt$polarity, 171 pol = opt$polarity,
199 file.path(opt$out_dir, "removed_peaks.tsv"), 208 file.path(opt$out_dir, "removed_peaks.tsv"),
200 row.names = FALSE, sep = "\t" 209 row.names = FALSE, sep = "\t"
201 ) 210 )
202 } else { 211 } else {
203 # nolint start 212 # nolint start
204 # TODO 213 # TODO - potential for multilist analysis (e)
205 # xsets <- split(xset, multilist_df$multlist)
206 #
207 # mult_grps <- unique(multilist_df$multlist)
208 #
209 # for (mgrp in mult_grps){
210 # xset_i <- xsets[mgrp]
211 # xcms::group(xset_i,
212 #
213 # }
214 # nolint end 214 # nolint end
215 } 215 }