comparison NmrNormalization_wrapper.R @ 0:a5e6499f1b4d draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/spectral_normalization commit 559844c168f0450b9657346ba890d9c028d7537a
author marie-tremblay-metatoul
date Tue, 22 Nov 2016 06:42:44 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a5e6499f1b4d
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
35 ##------------------------------
36 ## Errors ?????????????????????
37 ##------------------------------
38
39
40 ##------------------------------
41 ## Constants
42 ##------------------------------
43 topEnvC <- environment()
44 flagC <- "\n"
45
46
47 ##------------------------------
48 ## Script
49 ##------------------------------
50 if(!runExampleL)
51 argLs <- parseCommandArgs(evaluate=FALSE)
52
53
54 ## Parameters Loading
55 ##-------------------
56 # Inputs
57 data <- read.table(argLs[["dataMatrix"]],check.names=FALSE,header=TRUE,sep="\t")
58 rownames(data) <- data[,1]
59 data <- data[,-1]
60
61 scaling <- argLs[["scalingMethod"]]
62 graphique <- argLs[["graphType"]]
63
64 if (scaling=='PQN')
65 {
66 metadataSample <- read.table(argLs[["sampleMetadata"]],check.names=FALSE,header=TRUE,sep="\t")
67 factor<- argLs[["factor"]]
68 ControlGroup <- argLs[["controlGroup"]]
69 }
70 if (scaling=='QuantitativeVariable')
71 {
72 metadataSample <- read.table(argLs[["sampleMetadata"]],check.names=FALSE,header=TRUE,sep="\t")
73 factor <- argLs[["factor"]]
74 }
75
76 # Outputs
77 nomGraphe <- argLs[["graphOut"]]
78 dataMatrixOut <- argLs[["dataMatrixOut"]]
79 sampleMetadataOut <- argLs[["sampleMetadataOut"]]
80 variableMetadataOut <- argLs[["variableMetadataOut"]]
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 data_sample <- NormalizationResults[[2]]
99 data_variable <- NormalizationResults[[3]]
100
101
102
103 ## Saving
104 ##-------
105 # Data
106 data_normalized <- cbind(rownames(data_normalized),data_normalized)
107 colnames(data_normalized) <- c("Bucket",colnames(data_normalized)[-1])
108 write.table(data_normalized,file=argLs$dataMatrixOut,quote=FALSE,row.names=FALSE,sep="\t")
109 # Sample
110 data_sample <- cbind(rownames(data_sample),data_sample)
111 colnames(data_sample) <- c("Sample",colnames(data_sample)[-1])
112 write.table(data_sample,file=argLs$sampleMetadataOut,quote=FALSE,row.names=FALSE,sep="\t")
113 # Variable
114 data_variable <- cbind(rownames(data_variable),data_variable)
115 colnames(data_variable) <- c("Bucket",colnames(data_variable)[-1])
116 write.table(data_variable,file=argLs$variableMetadataOut,quote=FALSE,row.names=FALSE,sep="\t")
117
118
119 ## Ending
120 ##---------------------
121
122 cat("\nEnd of 'Normalization' Galaxy module call: ", as.character(Sys.time()), sep = "")
123
124 ## sink(NULL)
125
126 options(stringsAsFactors = strAsFacL)
127
128 rm(list = ls())