Mercurial > repos > ethevenot > batchcorrection
annotate batch_correction_wrapper.R @ 0:78cb1efd7606 draft
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
| author | ethevenot | 
|---|---|
| date | Thu, 30 Mar 2017 12:10:43 -0400 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 0 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 1 #!/usr/bin/Rscript --vanilla --slave --no-site-file | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 2 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 3 ################################################################################################ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 4 # batch_correction_wrapper # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 5 # # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 6 # Author: Marion LANDI / Jean-Francois MARTIN / Melanie Petera # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 7 # User: Galaxy # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 8 # Original data: -- # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 9 # Starting date: 22-07-2014 # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 10 # Version 1: 22-07-2014 # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 11 # Version 2: 08-12-2014 # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 12 # Version 2.1: 09-01-2015 modification in Error message of sample matching # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 13 # Version 2.2: 16-03-2015 inclusion of miniTools' functions for special characters # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 14 # Version 2.90: 18-08-2015 new parameter valnull # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 15 # Version 2.91: 25-08-2016 error message improvment # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 16 # # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 17 # # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 18 # Input files: dataMatrix.txt ; sampleMetadata.txt ; variableMetadata.txt (for DBC) # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 19 # Output files: graph_output.pdf ; corrected table ; diagnostic table # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 20 # # | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 21 ################################################################################################ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 22 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 23 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 24 library(batch) #necessary for parseCommandArgs function | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 25 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 26 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 27 source_local <- function(...){ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 28 argv <- commandArgs(trailingOnly = FALSE) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 29 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 30 for(i in 1:length(list(...))){source(paste(base_dir, list(...)[[i]], sep="/"))} | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 31 } | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 32 #Import the different functions | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 33 source_local("Normalisation_QCpool.r","easyrlibrary-lib/RcheckLibrary.R","easyrlibrary-lib/miniTools.R") | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 34 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 35 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 36 ## Reading of input files | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 37 idsample=read.table(args$sampleMetadata,header=T,sep='\t',check.names=FALSE) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 38 iddata=read.table(args$dataMatrix,header=T,sep='\t',check.names=FALSE) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 39 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 40 ### Table match check | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 41 table.check <- match2(iddata,idsample,"sample") | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 42 if(length(table.check)>1){check.err(table.check)} | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 43 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 44 ### StockID | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 45 samp.id <- stockID(iddata,idsample,"sample") | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 46 iddata<-samp.id$dataMatrix ; idsample<-samp.id$Metadata ; samp.id<-samp.id$id.match | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 47 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 48 ### Checking mandatory variables | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 49 mand.check <- "" | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 50 for(mandcol in c("sampleType","injectionOrder","batch")){ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 51 if(!(mandcol%in%colnames(idsample))){ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 52 mand.check <- c(mand.check,"\nError: no '",mandcol,"' column in sample metadata.\n", | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 53 "Note: table must include this exact column name (it is case-sensitive).\n") | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 54 } | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 55 } | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 56 if(length(mand.check)>1){ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 57 mand.check <- c(mand.check,"\nFor more information, see the help section or:", | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 58 "\n http://workflow4metabolomics.org/sites/", | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 59 "workflow4metabolomics.org/files/files/w4e-2016-data_processing.pdf\n") | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 60 check.err(mand.check) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 61 } | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 62 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 63 ### Formating | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 64 idsample[[1]]=make.names(idsample[[1]]) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 65 dimnames(iddata)[[1]]=iddata[[1]] | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 66 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 67 ### Transposition of ions data | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 68 idTdata=t(iddata[,2:dim(iddata)[2]]) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 69 idTdata=data.frame(dimnames(idTdata)[[1]],idTdata) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 70 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 71 ### Merge of 2 files (ok even if the two dataframe are not sorted on the same key) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 72 id=merge(idsample, idTdata, by.x=1, by.y=1) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 73 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 74 id$batch=as.factor(id$batch) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 75 ids=id[id$sampleType == 'pool' | id$sampleType == 'sample',] | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 76 nbid=dim(idsample)[2] | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 77 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 78 ### Checking the number of sample and pool | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 79 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 80 # least 2 samples | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 81 if(length(which(ids$sampleType == "sample"))<2){ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 82 table.check <- c(table.check,"\nError: less than 2 samples specified in sample metadata.", | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 83 "\nMake sure this is not due to errors in sampleType coding.\n") | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 84 } | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 85 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 86 # least 2 pools per batch for all batchs | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 87 B <- rep(0,length(levels(ids$batch))) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 88 for(nbB in length(levels(ids$batch))){ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 89 B[nbB]<-length(which(ids[which(ids$batch==(levels(ids$batch)[nbB])),]$sampleType == "pool")) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 90 } | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 91 if(length(which(B>1))==0){ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 92 table.check <- c(table.check,"\nError: less than 2 pools specified in each batch in sample metadata.", | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 93 "\nMake sure this is not due to errors in sampleType coding.\n") | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 94 } | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 95 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 96 ### Factor of interest | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 97 factbio=args$ref_factor | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 98 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 99 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 100 if(args$analyse == "batch_correction") { | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 101 ## Reading of Metadata Ions file | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 102 metaion=read.table(args$variableMetadata,header=T,sep='\t',check.names=FALSE) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 103 ## Table match check | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 104 table.check <- c(table.check,match2(iddata,metaion,"variable")) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 105 check.err(table.check) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 106 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 107 ## variables | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 108 detail=args$detail | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 109 method=args$method | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 110 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 111 ## outputs | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 112 outlog=args$graph_output | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 113 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 114 ## Launch | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 115 res = norm_QCpool(ids,nbid,outlog,factbio,metaion,detail,F,F,method,args$span,args$valnull) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 116 save(res, file=args$rdata_output) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 117 write.table(reproduceID(res[[1]],res[[3]],"sample",samp.id)$dataMatrix, file=args$dataMatrix_out, sep = '\t', row.names=F, quote=F) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 118 write.table(res[[2]], file=args$variableMetadata_out, sep = '\t', row.names=F, quote=F) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 119 }else{ | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 120 ## error check | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 121 check.err(table.check) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 122 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 123 ## outputs | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 124 out_graph_pdf=args$out_graph_pdf | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 125 out_preNormSummary=args$out_preNormSummary | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 126 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 127 ## Launch | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 128 plotsituation(ids,nbid,out_graph_pdf,out_preNormSummary,factbio,args$span) | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 129 } | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 130 | 
| 
78cb1efd7606
planemo upload for repository https://github.com/workflow4metabolomics/batch_correction.git commit 400138235741cbb21fd7c7ddeeb572235fa769c2-dirty
 ethevenot parents: diff
changeset | 131 rm(args) | 
