Mercurial > repos > marie-tremblay-metatoul > normalization
diff NmrNormalization_wrapper.R @ 3:966fcf7ae66e draft
planemo upload for repository https://github.com/workflow4metabolomics/normalization commit 9ca88a22e9b9394bfa00ea383fbb2b78ef05f990
author | lecorguille |
---|---|
date | Thu, 26 Oct 2017 06:01:14 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NmrNormalization_wrapper.R Thu Oct 26 06:01:14 2017 -0400 @@ -0,0 +1,139 @@ +#!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file + +## 070115_NmrBucketing2galaxy_v1.R +## Marie Tremblay-Franco +## MetaboHUB: The French Infrastructure for Metabolomics and Fluxomics +## www.metabohub.fr/en +## marie.tremblay-franco@toulouse.inra.fr + +runExampleL <- FALSE + + +##------------------------------ +## Options +##------------------------------ +strAsFacL <- options()$stringsAsFactors +options(stringsAsFactors = FALSE) + + +##------------------------------ +## Libraries laoding +##------------------------------ +# For parseCommandArgs function +library(batch) + +# 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("NmrNormalization_script.R") +source_local("DrawSpec.R") + + +##------------------------------ +## Errors ????????????????????? +##------------------------------ + + +##------------------------------ +## Constants +##------------------------------ +topEnvC <- environment() +flagC <- "\n" + + +##------------------------------ +## Script +##------------------------------ +if(!runExampleL) + argLs <- parseCommandArgs(evaluate=FALSE) + + +## Parameters Loading +##------------------- + # Inputs +data <- read.table(argLs[["dataMatrix"]],check.names=FALSE,header=TRUE,sep="\t") +rownames(data) <- data[,1] +data <- data[,-1] + +scaling <- argLs[["scalingMethod"]] +graphique <- argLs[["graphType"]] + +if (scaling=='PQN') +{ + metadataSample <- read.table(argLs[["sampleMetadata"]],check.names=FALSE,header=TRUE,sep="\t") + factor<- argLs[["factor"]] + ControlGroup <- argLs[["controlGroup"]] +} +if (scaling=='QuantitativeVariable') +{ + metadataSample <- read.table(argLs[["sampleMetadata"]],check.names=FALSE,header=TRUE,sep="\t") + factor <- argLs[["factor"]] +} + + # Outputs +nomGraphe <- argLs[["graphOut"]] +dataMatrixOut <- argLs[["dataMatrixOut"]] +log <- argLs[["logOut"]] + +## Checking arguments +##------------------- +error.stock <- "\n" + +if(length(error.stock) > 1) + stop(error.stock) + + +## Computation +##------------ +NormalizationResults <- NmrNormalization(dataMatrix=data,scalingMethod=scaling,sampleMetadata=metadataSample, + bioFactor=factor,ControlGroup=ControlGroup, + graph=graphique,nomFichier=nomGraphe,savLog.txtC=log) + +data_normalized <- NormalizationResults[[1]] + + +## Graphical outputs +##------------------ +if (graphique != "None") +{ + # Graphic Device opening + pdf(nomGraphe,onefile=TRUE) + + if (graphique == "Overlay") + { + # Global spectral window + spectra <- data.frame(t(data_normalized)) + drawSpec(spectra,xlab="", ylab="Intensity", main="") + } + else + { + for (i in 1:ncol(data_normalized)) + { + spectra <- t(data_normalized[,i]) + drawSpec(spectra,xlab="", ylab="Intensity", main=colnames(data_normalized)[i]) + } + } + dev.off() +} + + +## Saving +##------- + # Data +data_normalized <- cbind(rownames(data_normalized),data_normalized) +colnames(data_normalized) <- c("Bucket",colnames(data_normalized)[-1]) +write.table(data_normalized,file=argLs$dataMatrixOut,quote=FALSE,row.names=FALSE,sep="\t") + + +## Ending +##--------------------- +cat("\nEnd of 'Normalization' Galaxy module call: ", as.character(Sys.time()), sep = "") + +options(stringsAsFactors = strAsFacL) + +rm(list = ls())