Mercurial > repos > computational-metabolomics > mspurity_flagremove
diff frag4feature.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 | 5d0461edc7fd |
children | a0ee43397d1e |
line wrap: on
line diff
--- a/frag4feature.R Fri Nov 13 09:50:17 2020 +0000 +++ b/frag4feature.R Thu Mar 04 12:30:15 2021 +0000 @@ -3,18 +3,18 @@ library(xcms) print(sessionInfo()) -xset_pa_filename_fix <- function(opt, pa, xset=NULL){ +xset_pa_filename_fix <- function(opt, pa, xset=NULL) { - if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){ + if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)) { # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables # needs to be done due to Galaxy moving the files around and screwing up any links to files - filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]]) + filepaths <- trimws(strsplit(opt$mzML_files, ",")[[1]]) # nolint + filepaths <- filepaths[filepaths != ""] - new_names <- basename(filepaths) - galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]]) + galaxy_names <- trimws(strsplit(opt$galaxy_names, ",")[[1]]) galaxy_names <- galaxy_names[galaxy_names != ""] nsave <- names(pa@fileList) @@ -28,14 +28,14 @@ } print(pa@fileList) - if(!is.null(xset)){ + if (!is.null(xset)) { print(xset@filepaths) - if(!all(basename(pa@fileList)==basename(xset@filepaths))){ - if(!all(names(pa@fileList)==basename(xset@filepaths))){ - print('FILELISTS DO NOT MATCH') - message('FILELISTS DO NOT MATCH') + if (!all(basename(pa@fileList) == basename(xset@filepaths))) { + if (!all(names(pa@fileList) == basename(xset@filepaths))) { + print("FILELISTS DO NOT MATCH") + message("FILELISTS DO NOT MATCH") quit(status = 1) }else{ xset@filepaths <- unname(pa@fileList) @@ -48,26 +48,26 @@ option_list <- list( - make_option(c("-o", "--out_dir"), type="character"), - make_option("--pa", type="character"), - make_option("--xset", type="character"), - make_option("--ppm", default=10), - make_option("--plim", default=0.0), - make_option("--convert2RawRT", action="store_true"), - make_option("--intense", action="store_true"), - make_option("--createDB", action="store_true"), - make_option("--cores", default=4), - make_option("--mzML_files", type="character"), - make_option("--galaxy_names", type="character"), - make_option("--grp_peaklist", type="character"), - make_option("--useGroup", action="store_true") + make_option(c("-o", "--out_dir"), type = "character"), + make_option("--pa", type = "character"), + make_option("--xset", type = "character"), + make_option("--ppm", default = 10), + make_option("--plim", default = 0.0), + make_option("--convert2RawRT", action = "store_true"), + make_option("--intense", action = "store_true"), + make_option("--createDB", action = "store_true"), + make_option("--cores", default = 4), + make_option("--mzML_files", type = "character"), + make_option("--galaxy_names", type = "character"), + make_option("--grp_peaklist", type = "character"), + make_option("--useGroup", action = "store_true") ) # store options -opt<- parse_args(OptionParser(option_list=option_list)) +opt <- parse_args(OptionParser(option_list = option_list)) print(opt) -loadRData <- function(rdata_path, name){ +loadRData <- function(rdata_path, name) { #loads an RData file, and returns the named xset object if it is there load(rdata_path) return(get(ls()[ls() %in% name])) @@ -78,19 +78,19 @@ getxcmsSetObject <- function(xobject) { # XCMS 1.x if (class(xobject) == "xcmsSet") - return (xobject) + return(xobject) # XCMS 3.x if (class(xobject) == "XCMSnExp") { # Get the legacy xcmsSet object - suppressWarnings(xset <- as(xobject, 'xcmsSet')) + suppressWarnings(xset <- as(xobject, "xcmsSet")) sampclass(xset) <- xset@phenoData$sample_group - return (xset) + return(xset) } } # Requires -pa <- loadRData(opt$pa, 'pa') -xset <- loadRData(opt$xset, c('xset','xdata')) +pa <- loadRData(opt$pa, "pa") +xset <- loadRData(opt$xset, c("xset", "xdata")) xset <- getxcmsSetObject(xset) pa@cores <- opt$cores @@ -98,63 +98,60 @@ print(pa@fileList) print(xset@filepaths) -if(is.null(opt$intense)){ - intense = FALSE +if (is.null(opt$intense)) { + intense <- FALSE }else{ - intense = TRUE + intense <- TRUE } -if(is.null(opt$convert2RawRT)){ - convert2RawRT = FALSE +if (is.null(opt$convert2RawRT)) { + convert2RawRT <- FALSE }else{ - convert2RawRT= TRUE + convert2RawRT <- TRUE } -if(is.null(opt$createDB)){ - createDB = FALSE +if (is.null(opt$createDB)) { + createDB <- FALSE }else{ - createDB = TRUE + createDB <- TRUE } -if(is.null(opt$useGroup)){ +if (is.null(opt$useGroup)) { fix <- xset_pa_filename_fix(opt, pa, xset) pa <- fix[[1]] xset <- fix[[2]] - useGroup=FALSE + useGroup <- FALSE }else{ # if are only aligning to the group not eah file we do not need to align the files between the xset and pa object - print('useGroup') + print("useGroup") fix <- xset_pa_filename_fix(opt, pa) pa <- fix[[1]] - useGroup=TRUE + useGroup <- TRUE } -if(is.null(opt$grp_peaklist)){ - grp_peaklist = NA +if (is.null(opt$grp_peaklist)) { + grp_peaklist <- NA }else{ - grp_peaklist = opt$grp_peaklist + grp_peaklist <- opt$grp_peaklist } print(useGroup) - - -pa <- msPurity::frag4feature(pa=pa, - xset=xset, - ppm=opt$ppm, - plim=opt$plim, - intense=intense, - convert2RawRT=convert2RawRT, - db_name='alldata.sqlite', - out_dir=opt$out_dir, - grp_peaklist=grp_peaklist, - create_db=createDB, - use_group=useGroup) - +pa <- msPurity::frag4feature(pa = pa, + xset = xset, + ppm = opt$ppm, + plim = opt$plim, + intense = intense, + convert2RawRT = convert2RawRT, + db_name = "alldata.sqlite", + out_dir = opt$out_dir, + grp_peaklist = grp_peaklist, + create_db = createDB, + use_group = useGroup) print(pa) -save(pa, file=file.path(opt$out_dir, 'frag4feature_output.RData')) +save(pa, file = file.path(opt$out_dir, "frag4feature_output.RData")) pa@grped_df$filename <- sapply(pa@grped_df$fileid, function(x) names(pa@fileList)[as.integer(x)]) print(head(pa@grped_df)) -write.table(pa@grped_df, file.path(opt$out_dir, 'frag4feature_output.tsv'), row.names=FALSE, sep='\t') +write.table(pa@grped_df, file.path(opt$out_dir, "frag4feature_output.tsv"), row.names = FALSE, sep = "\t")