comparison NmrBucketing_wrapper.R @ 0:a99a6026c972 draft

planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
author marie-tremblay-metatoul
date Fri, 08 Apr 2016 10:56:14 -0400
parents
children d61f6ceef5d6
comparison
equal deleted inserted replaced
-1:000000000000 0:a99a6026c972
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 if(runExampleL) {
12 ##------------------------------
13 ## Example of arguments
14 ##------------------------------
15 argLs <- list(StudyDir = "Tlse_BPASourisCerveau",
16 upper = "10.0",
17 lower = "0.50",
18 bucket.width = "0.01",
19 exclusion = "TRUE",
20 exclusion.zone = list(c(6.5,4.5)),
21 graph="Overlay")
22
23 argLs <- c(argLs,
24 list(dataMatrixOut = paste(directory,"_NmrBucketing_dataMatrix.tsv",sep=""),
25 sampleMetadataOut = paste(directory,"_NmrBucketing_sampleMetadata.tsv",sep=""),
26 variableMetadataOut = paste(directory,"_NmrBucketing_variableMetadata.tsv",sep=""),
27 graphOut = paste(directory,"_NmrBucketing_graph.pdf",sep=""),
28 logOut = paste(directory,"_NmrBucketing_log.txt",sep="")))
29 }
30
31 ##------------------------------
32 ## Options
33 ##------------------------------
34 strAsFacL <- options()$stringsAsFactors
35 options(stringsAsFactors = FALSE)
36
37
38 ##------------------------------
39 ## Libraries laoding
40 ##------------------------------
41 # For parseCommandArgs function
42 library(batch)
43 # For cumtrapz function
44 library(pracma)
45
46 # R script call
47 source_local <- function(fname)
48 {
49 argv <- commandArgs(trailingOnly = FALSE)
50 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
51 source(paste(base_dir, fname, sep="/"))
52 }
53 #Import the different functions
54 source_local("NmrBucketing_script.R")
55
56 ##------------------------------
57 ## Errors ?????????????????????
58 ##------------------------------
59
60
61 ##------------------------------
62 ## Constants
63 ##------------------------------
64 topEnvC <- environment()
65 flagC <- "\n"
66
67
68 ##------------------------------
69 ## Script
70 ##------------------------------
71 if(!runExampleL)
72 argLs <- parseCommandArgs(evaluate=FALSE)
73
74 ## sink(argLs[["logOut"]])
75
76
77 ## Parameters Loading
78 ##-------------------
79 # Inputs
80 if (!is.null(argLs[["zipfile"]])){
81 zipfile= argLs[["zipfile"]]
82 directory=unzip(zipfile, list=F)
83 directory=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/")
84 } else if (!is.null(argLs[["library"]])){
85 directory=argLs[["library"]]
86 if(!file.exists(directory)){
87 error_message=paste("Cannot access the directory :",directory,".Please verify if the directory exists or not.")
88 print(error_message)
89 stop(error_message)
90 }
91 }
92
93 leftBorder <- argLs[["left_border"]]
94 rightBorder <- argLs[["right_border"]]
95 bucketSize <- argLs[["bucket_width"]]
96 exclusionZones <- argLs[["zone_exclusion_choices.choice"]]
97
98 exclusionZonesBorders <- NULL
99 if (!is.null(argLs$zone_exclusion_left))
100 {
101 for(i in which(names(argLs)=="zone_exclusion_left"))
102 {
103 exclusionZonesBorders <- c(exclusionZonesBorders,list(c(argLs[[i]],argLs[[i+1]])))
104 }
105 }
106
107 graphique <- argLs[["graphType"]]
108
109 # Outputs
110 nomGraphe <- argLs[["graphOut"]]
111 dataMatrixOut <- argLs[["dataMatrixOut"]]
112 sampleMetadataOut <- argLs[["sampleOut"]]
113 variableMetadataOut <- argLs[["variableOut"]]
114 log <- argLs[["logOut"]]
115
116 ## Checking arguments
117 ##-------------------
118 error.stock <- "\n"
119
120 if(length(error.stock) > 1)
121 stop(error.stock)
122
123
124 ## Computation
125 ##------------
126 outputs <- NmrBucketing(directory,leftBorder,rightBorder,bucketSize,exclusionZones,exclusionZonesBorders,graphique,nomGraphe,log)
127 data_bucket <- outputs[[1]]
128 data_sample <- outputs[[2]]
129 data_variable <- outputs[[3]]
130
131 ## Saving
132 ##-------
133 # Data
134 data_bucket <- cbind(rownames(data_bucket),data_bucket)
135 colnames(data_bucket) <- c("Bucket",colnames(data_bucket)[-1])
136 write.table(data_bucket,file=argLs$dataMatrixOut,quote=FALSE,row.names=FALSE,sep="\t")
137 # Sample
138 data_sample <- cbind(rownames(data_sample),data_sample)
139 colnames(data_sample) <- c("Sample",colnames(data_sample)[-1])
140 write.table(data_sample,file=argLs$sampleOut,quote=FALSE,row.names=FALSE,sep="\t")
141 # Variable
142 data_variable <- cbind(rownames(data_variable),data_variable)
143 colnames(data_variable) <- c("Bucket",colnames(data_variable)[-1])
144 write.table(data_variable,file=argLs$variableOut,quote=FALSE,row.names=FALSE,sep="\t")
145
146
147 ## Ending
148 ##---------------------
149
150 cat("\nEnd of 'NMR bucketing' Galaxy module call: ", as.character(Sys.time()), sep = "")
151
152 ## sink(NULL)
153
154 options(stringsAsFactors = strAsFacL)
155
156 rm(list = ls())