Mercurial > repos > marie-tremblay-metatoul > nmr_preprocessing
comparison ReadFids_wrapper.R @ 2:5e64657b4fe5 draft
planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 22ca8782d7c4c0211e13c95b425d4f29f53f995e
| author | lecorguille |
|---|---|
| date | Wed, 28 Mar 2018 08:05:12 -0400 |
| parents | |
| children | 122df1bf0a8c |
comparison
equal
deleted
inserted
replaced
| 1:cbea5e9fd0b4 | 2:5e64657b4fe5 |
|---|---|
| 1 #!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file | |
| 2 | |
| 3 ## 08122016_ReadFids_wrapper.R | |
| 4 ## Manon Martin | |
| 5 ## manon.martin@uclouvain.be | |
| 6 | |
| 7 ##====================================================== | |
| 8 ##====================================================== | |
| 9 # Preamble | |
| 10 ##====================================================== | |
| 11 ##====================================================== | |
| 12 | |
| 13 runExampleL <- FALSE | |
| 14 | |
| 15 | |
| 16 ##------------------------------ | |
| 17 ## Options | |
| 18 ##------------------------------ | |
| 19 strAsFacL <- options()$stringsAsFactors | |
| 20 options(stringsAsFactors = FALSE) | |
| 21 options(warn=1) | |
| 22 | |
| 23 ##------------------------------ | |
| 24 ## Libraries laoding | |
| 25 ##------------------------------ | |
| 26 library(batch) | |
| 27 library(ggplot2) | |
| 28 library(gridExtra) | |
| 29 library(reshape2) | |
| 30 | |
| 31 | |
| 32 # R script call | |
| 33 source_local <- function(fname) | |
| 34 { | |
| 35 argv <- commandArgs(trailingOnly = FALSE) | |
| 36 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | |
| 37 source(paste(base_dir, fname, sep="/")) | |
| 38 } | |
| 39 #Import the different functions | |
| 40 source_local("ReadFids_script.R") | |
| 41 source_local("DrawFunctions.R") | |
| 42 ##------------------------------ | |
| 43 ## Errors ????????????????????? | |
| 44 ##------------------------------ | |
| 45 | |
| 46 | |
| 47 ##------------------------------ | |
| 48 ## Constants | |
| 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 | |
| 103 ##====================================================== | |
| 104 ##====================================================== | |
| 105 sink(logOut,append=TRUE) | |
| 106 | |
| 107 if(length(warnings())>0){ # or !is.null(warnings()) | |
| 108 print("something happened") | |
| 109 } | |
| 110 | |
| 111 ## Starting | |
| 112 cat("\nStart of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), "\n\n", sep = "") | |
| 113 | |
| 114 outputs <- ReadFids(path = path, l=l, subdirs = subdirs, dirs.names = dirs.names) | |
| 115 | |
| 116 data_matrix <- outputs[["Fid_data"]] # Data matrix | |
| 117 data_sample <- outputs[["Fid_info"]] # Sample metadata | |
| 118 | |
| 119 | |
| 120 | |
| 121 pdf(nomGraphe, onefile = TRUE, width = 13, height = 13) | |
| 122 title = "Raw FID data" | |
| 123 DrawSignal(data_matrix, subtype = "stacked", | |
| 124 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, | |
| 125 xlab = "Frequency", num.stacked = 4, | |
| 126 main = title, createWindow=FALSE) | |
| 127 invisible(dev.off()) | |
| 128 | |
| 129 ##====================================================== | |
| 130 ##====================================================== | |
| 131 ## Saving | |
| 132 ##====================================================== | |
| 133 ##====================================================== | |
| 134 | |
| 135 # Data matrix | |
| 136 write.table(data_matrix,file=argLs$dataMatrix, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE) | |
| 137 | |
| 138 # Sample metadata | |
| 139 write.table(data_sample,file=argLs$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 | |
| 144 # input arguments | |
| 145 cat("\n INPUT and OUTPUT ARGUMENTS :\n") | |
| 146 | |
| 147 argLs | |
| 148 | |
| 149 ## Ending | |
| 150 | |
| 151 cat("\nEnd of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), sep = "") | |
| 152 | |
| 153 sink() | |
| 154 | |
| 155 | |
| 156 options(stringsAsFactors = strAsFacL) | |
| 157 | |
| 158 rm(list = ls()) |
