comparison 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
comparison
equal deleted inserted replaced
2:3cd762aac7a4 3:966fcf7ae66e
1 #!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
2
3 ## 070115_NmrBucketing2galaxy_v1.R
4 ## Marie Tremblay-Franco
5 ## MetaboHUB: The French Infrastructure for Metabolomics and Fluxomics
6 ## www.metabohub.fr/en
7 ## marie.tremblay-franco@toulouse.inra.fr
8
9 runExampleL <- FALSE
10
11
12 ##------------------------------
13 ## Options
14 ##------------------------------
15 strAsFacL <- options()$stringsAsFactors
16 options(stringsAsFactors = FALSE)
17
18
19 ##------------------------------
20 ## Libraries laoding
21 ##------------------------------
22 # For parseCommandArgs function
23 library(batch)
24
25 # R script call
26 source_local <- function(fname)
27 {
28 argv <- commandArgs(trailingOnly = FALSE)
29 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
30 source(paste(base_dir, fname, sep="/"))
31 }
32 #Import the different functions
33 source_local("NmrNormalization_script.R")
34 source_local("DrawSpec.R")
35
36
37 ##------------------------------
38 ## Errors ?????????????????????
39 ##------------------------------
40
41
42 ##------------------------------
43 ## Constants
44 ##------------------------------
45 topEnvC <- environment()
46 flagC <- "\n"
47
48
49 ##------------------------------
50 ## Script
51 ##------------------------------
52 if(!runExampleL)
53 argLs <- parseCommandArgs(evaluate=FALSE)
54
55
56 ## Parameters Loading
57 ##-------------------
58 # Inputs
59 data <- read.table(argLs[["dataMatrix"]],check.names=FALSE,header=TRUE,sep="\t")
60 rownames(data) <- data[,1]
61 data <- data[,-1]
62
63 scaling <- argLs[["scalingMethod"]]
64 graphique <- argLs[["graphType"]]
65
66 if (scaling=='PQN')
67 {
68 metadataSample <- read.table(argLs[["sampleMetadata"]],check.names=FALSE,header=TRUE,sep="\t")
69 factor<- argLs[["factor"]]
70 ControlGroup <- argLs[["controlGroup"]]
71 }
72 if (scaling=='QuantitativeVariable')
73 {
74 metadataSample <- read.table(argLs[["sampleMetadata"]],check.names=FALSE,header=TRUE,sep="\t")
75 factor <- argLs[["factor"]]
76 }
77
78 # Outputs
79 nomGraphe <- argLs[["graphOut"]]
80 dataMatrixOut <- argLs[["dataMatrixOut"]]
81 log <- argLs[["logOut"]]
82
83 ## Checking arguments
84 ##-------------------
85 error.stock <- "\n"
86
87 if(length(error.stock) > 1)
88 stop(error.stock)
89
90
91 ## Computation
92 ##------------
93 NormalizationResults <- NmrNormalization(dataMatrix=data,scalingMethod=scaling,sampleMetadata=metadataSample,
94 bioFactor=factor,ControlGroup=ControlGroup,
95 graph=graphique,nomFichier=nomGraphe,savLog.txtC=log)
96
97 data_normalized <- NormalizationResults[[1]]
98
99
100 ## Graphical outputs
101 ##------------------
102 if (graphique != "None")
103 {
104 # Graphic Device opening
105 pdf(nomGraphe,onefile=TRUE)
106
107 if (graphique == "Overlay")
108 {
109 # Global spectral window
110 spectra <- data.frame(t(data_normalized))
111 drawSpec(spectra,xlab="", ylab="Intensity", main="")
112 }
113 else
114 {
115 for (i in 1:ncol(data_normalized))
116 {
117 spectra <- t(data_normalized[,i])
118 drawSpec(spectra,xlab="", ylab="Intensity", main=colnames(data_normalized)[i])
119 }
120 }
121 dev.off()
122 }
123
124
125 ## Saving
126 ##-------
127 # Data
128 data_normalized <- cbind(rownames(data_normalized),data_normalized)
129 colnames(data_normalized) <- c("Bucket",colnames(data_normalized)[-1])
130 write.table(data_normalized,file=argLs$dataMatrixOut,quote=FALSE,row.names=FALSE,sep="\t")
131
132
133 ## Ending
134 ##---------------------
135 cat("\nEnd of 'Normalization' Galaxy module call: ", as.character(Sys.time()), sep = "")
136
137 options(stringsAsFactors = strAsFacL)
138
139 rm(list = ls())