Mercurial > repos > marie-tremblay-metatoul > nmr_preprocessing
diff ReadFids_wrapper.R @ 7:122df1bf0a8c draft default tip
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 3d328007dd7716848ec2eeb6c2a472f27eeb2995
author | workflow4metabolomics |
---|---|
date | Fri, 11 Jul 2025 08:33:38 +0000 |
parents | 5e64657b4fe5 |
children |
line wrap: on
line diff
--- a/ReadFids_wrapper.R Wed May 13 03:52:09 2020 -0400 +++ b/ReadFids_wrapper.R Fri Jul 11 08:33:38 2025 +0000 @@ -1,158 +1,97 @@ -#!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file - -## 08122016_ReadFids_wrapper.R -## Manon Martin -## manon.martin@uclouvain.be - -##====================================================== -##====================================================== -# Preamble -##====================================================== -##====================================================== - -runExampleL <- FALSE +## ------------------------------ +## Libraries laoding +## ------------------------------ +# library(batch) +library(optparse) # argument parsing -##------------------------------ -## Options -##------------------------------ -strAsFacL <- options()$stringsAsFactors -options(stringsAsFactors = FALSE) -options(warn=1) - -##------------------------------ -## Libraries laoding -##------------------------------ -library(batch) -library(ggplot2) -library(gridExtra) -library(reshape2) - +## Outputs +dataMatrix <- "dataMatrix.tsv" +sampleMetadata <- "sampleMetadata.tsv" +nomGraphe <- "graphOut.pdf" +logOut <- "logOut.txt" +sink(logOut, append = TRUE, split = TRUE) -# R script call -source_local <- function(fname) -{ - argv <- commandArgs(trailingOnly = FALSE) - base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) - source(paste(base_dir, fname, sep="/")) -} -#Import the different functions -source_local("ReadFids_script.R") -source_local("DrawFunctions.R") -##------------------------------ -## Errors ????????????????????? -##------------------------------ +# ------------------------------ +# Command line interface (optparse) +# ------------------------------ +option_list <- list( + make_option(c("-f", "--fidzipfile"), type = "character", help = "Path to zipped Bruker FID file"), + make_option(c("-t", "--title_line"), type = "character", help = "Title line for output"), + make_option(c("-s", "--subdirectories"), action = "store_true", dest = "subdirectories", default = FALSE, help = "Whether to use subdirectories (boolean flag)"), + make_option(c("-d", "--dirs_names"), action = "store_true", dest = "dirs_names", default = FALSE, help = "Whether to use dirs_names (boolean flag)") +) - -##------------------------------ -## Constants -##------------------------------ -topEnvC <- environment() -flagC <- "\n" +opt_parser <- OptionParser(option_list = option_list) +args <- parse_args(opt_parser) +print(args) -##------------------------------ -## Script -##------------------------------ -if(!runExampleL) - argLs <- parseCommandArgs(evaluate=FALSE) - -sink(argLs$logOut) - -##====================================================== -##====================================================== +## ====================================================== +## ====================================================== ## Parameters Loading -##====================================================== -##====================================================== +## ====================================================== +## ====================================================== - ## Inputs - # Path - ## Bruker FIDs -fileType="Bruker" -zipfile= argLs[["fidzipfile"]] -directory=unzip(zipfile, list=F) -path=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/") - +## Inputs +# Path +## Bruker FIDs +fileType <- "Bruker" +zipfile <- args$fidzipfile +directory <- unzip(zipfile, list = FALSE) +path <- paste(getwd(), strsplit(directory[1], "/")[[1]][2], sep = "/") +print(path) # other inputs from ReadFids -l = argLs[["title_line"]] -subdirs <- argLs[["subdirectories"]] -dirs.names <- argLs[["dirs_names"]] - - -# Outputs -# dataMatrix <- argLs[["dataMatrix"]] -# sampleMetadata <- argLs[["sampleMetadata"]] -logOut <- argLs[["logOut"]] -nomGraphe <- argLs[["graphOut"]] - +l <- args$title_line +subdirs <- args$subdirectories +dirs.names <- args$dirs_names -## Checking arguments -##------------------- -error.stock <- "\n" - -if(length(error.stock) > 1) - stop(error.stock) - - - -##====================================================== -##====================================================== +## ====================================================== +## ====================================================== ## Computation -##====================================================== -##====================================================== -sink(logOut,append=TRUE) - -if(length(warnings())>0){ # or !is.null(warnings()) - print("something happened") +## ====================================================== +## ====================================================== +if (length(warnings()) > 0) { # or !is.null(warnings()) + print("something happened") } ## Starting cat("\nStart of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), "\n\n", sep = "") -outputs <- ReadFids(path = path, l=l, subdirs = subdirs, dirs.names = dirs.names) - +outputs <- ReadFids(path = path, l = l, subdirs = subdirs, dirs.names = dirs.names) data_matrix <- outputs[["Fid_data"]] # Data matrix data_sample <- outputs[["Fid_info"]] # Sample metadata - - pdf(nomGraphe, onefile = TRUE, width = 13, height = 13) -title = "Raw FID data" -DrawSignal(data_matrix, subtype = "stacked", - ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, - xlab = "Frequency", num.stacked = 4, - main = title, createWindow=FALSE) +DrawSignal(data_matrix, + subtype = "stacked", + ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, + xlab = "Frequency", num.stacked = 4, + main = "Raw FID data", createWindow = FALSE +) invisible(dev.off()) -##====================================================== -##====================================================== +## ====================================================== +## ====================================================== ## Saving -##====================================================== -##====================================================== +## ====================================================== +## ====================================================== # Data matrix -write.table(data_matrix,file=argLs$dataMatrix, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE) +write.table(data_matrix, file = dataMatrix, quote = FALSE, row.names = TRUE, sep = "\t", col.names = TRUE) # Sample metadata -write.table(data_sample,file=argLs$sampleMetadata, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE) - -# log file -# write.table(t(data.frame(argLs)), file = argLs$logOut, col.names = FALSE, quote=FALSE) +write.table(data_sample, file = sampleMetadata, quote = FALSE, row.names = TRUE, sep = "\t", col.names = TRUE) # input arguments cat("\n INPUT and OUTPUT ARGUMENTS :\n") -argLs - +# Reproductibility +print(sessionInfo()) ## Ending cat("\nEnd of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), sep = "") sink() - - -options(stringsAsFactors = strAsFacL) - -rm(list = ls()) \ No newline at end of file