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