annotate NmrBucketing_script.R @ 3:58679e85745f draft

planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 7cd224b2cbddcb2535640a3f76194bd235acb602-dirty
author lecorguille
date Fri, 12 Aug 2016 05:47:27 -0400
parents 761312f27add
children d61f6ceef5d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
1 ################################################################################################
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
2 # SPECTRA BUCKETING AND INTEGRATION FROM RAW BRUKER FILES #
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
3 # User : Galaxy #
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
4 # Original data : -- #
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
5 # Starting date : 20-10-2014 #
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
6 # Version 1 : 18-12-2014 #
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
7 # Version 2 : 07-01-2015 #
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
8 # #
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
9 # Input files : files in included in user-defined directory #
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
10 ################################################################################################
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
11 NmrBucketing <- function(directory,leftBorder = 10.0,rightBorder = 0.5,bucketSize = 0.04,exclusionZones,exclusionZonesBorders=NULL,
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
12 graph=c("None","Overlay","One_per_individual"),nomFichier,savLog.txtC = NULL)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
13 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
14 ## Option
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
15 ##---------------
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
16 strAsFacL <- options()$stringsAsFactors
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
17 options(stingsAsFactors = FALSE)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
18 options(warn = -1)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
19
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
20
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
21 ## Constants
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
22 ##---------------
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
23 topEnvC <- environment()
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
24 flgC <- "\n"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
25
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
26 ## Log file (in case of integration into Galaxy)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
27 ##----------------------------------------------
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
28 if(!is.null(savLog.txtC))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
29 sink(savLog.txtC, append = TRUE)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
30
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
31 ## Functions definition
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
32 ##---------------------
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
33 ## RAW BRUKER FILE READING FUNCTION
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
34 NmRBrucker_read <- function(DataDir,SampleSpectrum)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
35 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
36
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
37 bruker.get_param <- function (ACQ,paramStr)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
38 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
39 regexpStr <- paste("^...",paramStr,"=",sep="")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
40 as.numeric(gsub("^[^=]+= ","" ,ACQ[which(simplify2array(regexpr(regexpStr,ACQ))>0)]))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
41 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
42
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
43 ACQFILE <- "acqus"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
44 SPECFILE <- paste(DataDir,"/1r",sep="")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
45 PROCFILE <- paste(DataDir,"/procs",sep="")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
46
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
47 ACQ <- readLines(ACQFILE)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
48 TD <- bruker.get_param(ACQ,"TD")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
49 SW <- bruker.get_param(ACQ,"SW")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
50 SWH <- bruker.get_param(ACQ,"SW_h")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
51 DTYPA <- bruker.get_param(ACQ,"DTYPA")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
52 BYTORDA <- bruker.get_param(ACQ,"BYTORDA")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
53 #ENDIAN = ifelse( BYTORDA==0, "little", "big")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
54 ENDIAN <- "little"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
55 SIZE = ifelse( DTYPA==0, 4, 8)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
56
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
57 PROC <- readLines(PROCFILE)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
58 OFFSET <- bruker.get_param(PROC,"OFFSET")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
59 SI <- bruker.get_param(PROC,"SI")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
60
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
61 to.read = file(SPECFILE,"rb")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
62 maxTDSI = max(TD,SI)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
63 # signal<-rev(readBin(to.read, what="int",size=SIZE, n=TD, signed = TRUE, endian = ENDIAN))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
64 signal<-rev(readBin(to.read, what="int",size=SIZE, n=maxTDSI, signed = TRUE, endian = ENDIAN))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
65 close(to.read)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
66
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
67 td <- length(signal)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
68
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
69 # dppm <- SW/(TD-1)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
70 dppm <- SW/(td-1)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
71 pmax <- OFFSET
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
72 pmin <- OFFSET - SW
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
73 ppmseq <- seq(from=pmin, to=pmax, by=dppm)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
74 signal <- 100*signal/max(signal)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
75
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
76 SampleSpectrum <- cbind(ppmseq,signal)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
77 return(SampleSpectrum)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
78 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
79
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
80 ## SPECTRUM BUCKETING
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
81 NmrBrucker_bucket <- function(spectrum)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
82 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
83 # Initialisations
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
84 b <- 1
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
85 j <- 1
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
86 # Variable number
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
87 J <- round((spectrum[1,1]-spectrum[dim(spectrum)[1],1])/bucketSize)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
88 f.bucket <- matrix(rep(0,J*2),ncol=2)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
89 colnames(f.bucket) <- c("Bucket",FileNames[i])
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
90
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
91
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
92 # Data bucketing
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
93 while (j < dim(spectrum)[1])
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
94 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
95 # chemical shift
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
96 BUB <- spectrum[j,1]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
97
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
98 # In zone exclusion?
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
99 exclusion.in <- FALSE
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
100 if (!is.null(exclusionZonesBorders))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
101 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
102 for (k in 1:nrow(exclusion.zone.m))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
103 if (BUB <= exclusion.zone.m[k,1] && exclusion.zone.m[k,2] < BUB)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
104 exclusion.in <- TRUE
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
105 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
106
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
107 if (exclusion.in)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
108 j <- j + 1
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
109
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
110 if (!exclusion.in)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
111 # Bucketing
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
112 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
113 BLB <- BUB - bucketSize
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
114 bucket <- spectrum[j,]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
115 while (j < dim(spectrum)[1] && spectrum[j,1] > BLB)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
116 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
117 j <- j + 1
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
118 if (spectrum[j,1] > BLB)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
119 bucket <- rbind(bucket,spectrum[j,])
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
120 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
121
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
122 # Integration (trapezoid method)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
123 s <- cumtrapz(bucket[,1],bucket[,2])
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
124 f.bucket[b,] <- c(round(mean(bucket[,1]),3),abs(s[length(s)][[1]]))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
125
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
126 # Next bucket boundary
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
127 BUB <- spectrum[j,1]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
128 b <- b + 1
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
129 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
130 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
131 return(f.bucket)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
132 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
133
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
134
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
135 # File names
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
136 FileNames <- list.files(directory)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
137 n <- length(FileNames)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
138
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
139 # Exclusion zones
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
140 ## if (exclusionZones == "yes")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
141 if (!is.null(exclusionZonesBorders))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
142 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
143 exclusion.zone.m <- matrix(exclusionZonesBorders[[1]],nrow=1)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
144 if (length(exclusionZonesBorders) > 1)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
145 for (k in 2:length(exclusionZonesBorders))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
146 exclusion.zone.m <- rbind(exclusion.zone.m,exclusionZonesBorders[[k]])
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
147 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
148
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
149 # Reading and Bucketing
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
150 directory <- paste(directory,"/",sep="")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
151
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
152 i <- 1
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
153 while (i <= n)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
154 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
155 # File reading
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
156 SampleDir <- paste(directory,FileNames[i],"/1/",sep="")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
157 setwd(SampleDir)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
158 DataDir <- "pdata/1"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
159
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
160 rawSpectrum <- NmRBrucker_read(DataDir,rawSpectrum)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
161
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
162 orderedSpectrum <- rawSpectrum[order(rawSpectrum[,1],decreasing=T), ]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
163
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
164 # Removal of chemical shifts > leftBorder or < rightBorder boundaries
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
165 truncatedSpectrum <- orderedSpectrum[orderedSpectrum[,1] < leftBorder & orderedSpectrum[,1] > rightBorder, ]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
166 truncatedSpectrum[,1] <- round(truncatedSpectrum[,1],3)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
167
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
168 # Bucketing
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
169 spectrum.bucket <- NmrBrucker_bucket(truncatedSpectrum)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
170
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
171 # spectrum Concatenation
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
172 if (i == 1)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
173 bucketedSpectra <- spectrum.bucket
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
174 if (i > 1)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
175 bucketedSpectra <- cbind(bucketedSpectra,spectrum.bucket[,2])
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
176 colnames(bucketedSpectra)[i+1] <- FileNames[i]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
177
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
178 # Next sample
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
179 rm(spectrum.bucket)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
180 i <- i +1
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
181 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
182 identifiants <- gsub("([- , * { } | \\[ ])","_",colnames(bucketedSpectra)[-1])
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
183 colnames(bucketedSpectra) <- c(colnames(bucketedSpectra)[1],identifiants)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
184
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
185 bucketedSpectra <- bucketedSpectra[bucketedSpectra[,1]!=0,]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
186 rownames(bucketedSpectra) <- paste("B",bucketedSpectra[,1],sep="")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
187 bucketedSpectra <- bucketedSpectra[,-1]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
188
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
189 # Metadata matrice outputs
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
190 sampleMetadata <- data.frame(1:n)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
191 rownames(sampleMetadata) <- colnames(bucketedSpectra)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
192 colnames(sampleMetadata) <- "SampleOrder"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
193
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
194 variableMetadata <- data.frame(1:nrow(bucketedSpectra))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
195 rownames(variableMetadata) <- rownames(bucketedSpectra)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
196 colnames(variableMetadata) <- "VariableOrder"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
197
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
198 # Directory
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
199 cd(directory)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
200
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
201 # Bucketed spectra graph
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
202 if (graph != "None")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
203 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
204 # Graphic Device opening
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
205 pdf(nomFichier,onefile=TRUE)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
206
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
207 if (graph == "Overlay")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
208 {
3
58679e85745f planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 7cd224b2cbddcb2535640a3f76194bd235acb602-dirty
lecorguille
parents: 2
diff changeset
209 x <- 1:length(bucketedSpectra[,1])
0
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
210 ymax <- max(bucketedSpectra)
3
58679e85745f planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 7cd224b2cbddcb2535640a3f76194bd235acb602-dirty
lecorguille
parents: 2
diff changeset
211 plot(x,bucketedSpectra[,1],ylim=c(0,ymax),type='l',col=1,xlab="",xaxt="n",ylab="Intensity")
58679e85745f planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 7cd224b2cbddcb2535640a3f76194bd235acb602-dirty
lecorguille
parents: 2
diff changeset
212 # x-axis labels
58679e85745f planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 7cd224b2cbddcb2535640a3f76194bd235acb602-dirty
lecorguille
parents: 2
diff changeset
213 axis(1, at=seq(1,length(x),by=50),labels=gsub("B","",rownames(bucketedSpectra)[seq(1,length(x),by=50)]), las=2)
0
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
214 for (i in 2:ncol(bucketedSpectra))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
215 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
216 spectre <- bucketedSpectra[,i]
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
217 lines(spectre,col=i)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
218 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
219 # legend(0,ymax,lty=c(1,1),legend=colnames(bucketedSpectra),col=1:ncol(bucketedSpectra))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
220 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
221 else
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
222 {
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
223 for (i in 1:ncol(bucketedSpectra))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
224 {
3
58679e85745f planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 7cd224b2cbddcb2535640a3f76194bd235acb602-dirty
lecorguille
parents: 2
diff changeset
225 x <- 1:length(bucketedSpectra[,1])
58679e85745f planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 7cd224b2cbddcb2535640a3f76194bd235acb602-dirty
lecorguille
parents: 2
diff changeset
226 plot(x,bucketedSpectra[,i],type='l',col=1,xlab="",xaxt="n",ylab="Intensity")
58679e85745f planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 7cd224b2cbddcb2535640a3f76194bd235acb602-dirty
lecorguille
parents: 2
diff changeset
227 axis(1, at=seq(1,length(x),by=50),labels=gsub("B","",rownames(bucketedSpectra)[seq(1,length(x),by=50)]), las=2)
0
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
228 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
229 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
230 dev.off()
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
231 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
232 return(list(bucketedSpectra,sampleMetadata,variableMetadata)) # ,truncatedSpectrum_matrice
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
233 }
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
234
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
235
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
236 #################################################################################################################
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
237 ## Typical function call
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
238 #################################################################################################################
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
239 ## StudyDir <- "K:/PROJETS/Metabohub/Bruker/Tlse_BPASourisCerveau/"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
240 ## upper <- 9.5
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
241 ## lower <- 0.8
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
242 ## bucket.width <- 0.01
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
243 ## exclusion <- TRUE
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
244 ## exclusion.zone <- list(c(5.1,4.5))
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
245 ## graphique <- "Overlay"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
246 ## nomFichier <- "Tlse_BPASourisCerveau_NmrBucketing_graph.pdf"
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
247 ## tlse_cerveaupnd21.bucket <- NmrBucketing(StudyDir,upper,lower,bucket.width,exclusion,exclusion.zone,graphique,nomFichier)
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
248 ## write.table(tlse_cerveaupnd21.bucket,file=paste(StudyDir,"Tlse_BPASourisCerveau_NmrBucketing_dataMatrix.tsv",sep=""),
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
249 ## quote=FALSE,row.nmaes=FALSE,sep="\t")
a99a6026c972 planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit 44fd4fc42930d2e9ad7b77cf575f2231547de15c
marie-tremblay-metatoul
parents:
diff changeset
250 #################################################################################################################