comparison 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
comparison
equal deleted inserted replaced
6:6e837e9352a2 7:122df1bf0a8c
1 #!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file 1 ## ------------------------------
2 2 ## Libraries laoding
3 ## 08122016_ReadFids_wrapper.R 3 ## ------------------------------
4 ## Manon Martin 4 # library(batch)
5 ## manon.martin@uclouvain.be 5 library(optparse) # argument parsing
6
7 ##======================================================
8 ##======================================================
9 # Preamble
10 ##======================================================
11 ##======================================================
12
13 runExampleL <- FALSE
14 6
15 7
16 ##------------------------------ 8 ## Outputs
17 ## Options 9 dataMatrix <- "dataMatrix.tsv"
18 ##------------------------------ 10 sampleMetadata <- "sampleMetadata.tsv"
19 strAsFacL <- options()$stringsAsFactors 11 nomGraphe <- "graphOut.pdf"
20 options(stringsAsFactors = FALSE) 12 logOut <- "logOut.txt"
21 options(warn=1) 13 sink(logOut, append = TRUE, split = TRUE)
22 14
23 ##------------------------------ 15 # ------------------------------
24 ## Libraries laoding 16 # Command line interface (optparse)
25 ##------------------------------ 17 # ------------------------------
26 library(batch) 18 option_list <- list(
27 library(ggplot2) 19 make_option(c("-f", "--fidzipfile"), type = "character", help = "Path to zipped Bruker FID file"),
28 library(gridExtra) 20 make_option(c("-t", "--title_line"), type = "character", help = "Title line for output"),
29 library(reshape2) 21 make_option(c("-s", "--subdirectories"), action = "store_true", dest = "subdirectories", default = FALSE, help = "Whether to use subdirectories (boolean flag)"),
22 make_option(c("-d", "--dirs_names"), action = "store_true", dest = "dirs_names", default = FALSE, help = "Whether to use dirs_names (boolean flag)")
23 )
24
25 opt_parser <- OptionParser(option_list = option_list)
26 args <- parse_args(opt_parser)
27 print(args)
30 28
31 29
32 # R script call 30 ## ======================================================
33 source_local <- function(fname) 31 ## ======================================================
34 { 32 ## Parameters Loading
35 argv <- commandArgs(trailingOnly = FALSE) 33 ## ======================================================
36 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) 34 ## ======================================================
37 source(paste(base_dir, fname, sep="/")) 35
38 } 36 ## Inputs
39 #Import the different functions 37 # Path
40 source_local("ReadFids_script.R") 38 ## Bruker FIDs
41 source_local("DrawFunctions.R") 39 fileType <- "Bruker"
42 ##------------------------------ 40 zipfile <- args$fidzipfile
43 ## Errors ????????????????????? 41 directory <- unzip(zipfile, list = FALSE)
44 ##------------------------------ 42 path <- paste(getwd(), strsplit(directory[1], "/")[[1]][2], sep = "/")
43 print(path)
44
45 # other inputs from ReadFids
46 l <- args$title_line
47 subdirs <- args$subdirectories
48 dirs.names <- args$dirs_names
45 49
46 50
47 ##------------------------------ 51 ## ======================================================
48 ## Constants 52 ## ======================================================
49 ##------------------------------
50 topEnvC <- environment()
51 flagC <- "\n"
52
53
54 ##------------------------------
55 ## Script
56 ##------------------------------
57 if(!runExampleL)
58 argLs <- parseCommandArgs(evaluate=FALSE)
59
60 sink(argLs$logOut)
61
62 ##======================================================
63 ##======================================================
64 ## Parameters Loading
65 ##======================================================
66 ##======================================================
67
68 ## Inputs
69 # Path
70 ## Bruker FIDs
71 fileType="Bruker"
72 zipfile= argLs[["fidzipfile"]]
73 directory=unzip(zipfile, list=F)
74 path=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/")
75
76
77 # other inputs from ReadFids
78 l = argLs[["title_line"]]
79 subdirs <- argLs[["subdirectories"]]
80 dirs.names <- argLs[["dirs_names"]]
81
82
83 # Outputs
84 # dataMatrix <- argLs[["dataMatrix"]]
85 # sampleMetadata <- argLs[["sampleMetadata"]]
86 logOut <- argLs[["logOut"]]
87 nomGraphe <- argLs[["graphOut"]]
88
89
90
91 ## Checking arguments
92 ##-------------------
93 error.stock <- "\n"
94
95 if(length(error.stock) > 1)
96 stop(error.stock)
97
98
99
100 ##======================================================
101 ##======================================================
102 ## Computation 53 ## Computation
103 ##====================================================== 54 ## ======================================================
104 ##====================================================== 55 ## ======================================================
105 sink(logOut,append=TRUE) 56 if (length(warnings()) > 0) { # or !is.null(warnings())
106 57 print("something happened")
107 if(length(warnings())>0){ # or !is.null(warnings())
108 print("something happened")
109 } 58 }
110 59
111 ## Starting 60 ## Starting
112 cat("\nStart of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), "\n\n", sep = "") 61 cat("\nStart of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), "\n\n", sep = "")
113 62
114 outputs <- ReadFids(path = path, l=l, subdirs = subdirs, dirs.names = dirs.names) 63 outputs <- ReadFids(path = path, l = l, subdirs = subdirs, dirs.names = dirs.names)
115
116 data_matrix <- outputs[["Fid_data"]] # Data matrix 64 data_matrix <- outputs[["Fid_data"]] # Data matrix
117 data_sample <- outputs[["Fid_info"]] # Sample metadata 65 data_sample <- outputs[["Fid_info"]] # Sample metadata
118 66
119
120
121 pdf(nomGraphe, onefile = TRUE, width = 13, height = 13) 67 pdf(nomGraphe, onefile = TRUE, width = 13, height = 13)
122 title = "Raw FID data" 68 DrawSignal(data_matrix,
123 DrawSignal(data_matrix, subtype = "stacked", 69 subtype = "stacked",
124 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 70 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
125 xlab = "Frequency", num.stacked = 4, 71 xlab = "Frequency", num.stacked = 4,
126 main = title, createWindow=FALSE) 72 main = "Raw FID data", createWindow = FALSE
73 )
127 invisible(dev.off()) 74 invisible(dev.off())
128 75
129 ##====================================================== 76 ## ======================================================
130 ##====================================================== 77 ## ======================================================
131 ## Saving 78 ## Saving
132 ##====================================================== 79 ## ======================================================
133 ##====================================================== 80 ## ======================================================
134 81
135 # Data matrix 82 # Data matrix
136 write.table(data_matrix,file=argLs$dataMatrix, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE) 83 write.table(data_matrix, file = dataMatrix, quote = FALSE, row.names = TRUE, sep = "\t", col.names = TRUE)
137 84
138 # Sample metadata 85 # Sample metadata
139 write.table(data_sample,file=argLs$sampleMetadata, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE) 86 write.table(data_sample, file = sampleMetadata, quote = FALSE, row.names = TRUE, sep = "\t", col.names = TRUE)
140
141 # log file
142 # write.table(t(data.frame(argLs)), file = argLs$logOut, col.names = FALSE, quote=FALSE)
143 87
144 # input arguments 88 # input arguments
145 cat("\n INPUT and OUTPUT ARGUMENTS :\n") 89 cat("\n INPUT and OUTPUT ARGUMENTS :\n")
146 90
147 argLs 91 # Reproductibility
148 92 print(sessionInfo())
149 ## Ending 93 ## Ending
150 94
151 cat("\nEnd of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), sep = "") 95 cat("\nEnd of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), sep = "")
152 96
153 sink() 97 sink()
154
155
156 options(stringsAsFactors = strAsFacL)
157
158 rm(list = ls())