# HG changeset patch # User marie-tremblay-metatoul # Date 1492684491 14400 # Node ID c54c70af216b30535de4939c85468de0ba112d62 # Parent 1df0b8efe9fce0bcf7a50e28f355ae1e7b34f315 Uploaded diff -r 1df0b8efe9fc -r c54c70af216b nmr_bucketing/NmrBucketing_script.R --- a/nmr_bucketing/NmrBucketing_script.R Mon Mar 06 06:34:01 2017 -0500 +++ b/nmr_bucketing/NmrBucketing_script.R Thu Apr 20 06:34:51 2017 -0400 @@ -109,14 +109,32 @@ } if (exclusion.in) - j <- j + 1 + { + # Bucketing + { + BLB <- BUB - bucketSize + bucket <- spectrum[j,] + while (j < dim(spectrum)[1] && spectrum[j,1] > BLB) + { + j <- j + 1 + if (spectrum[j,1] > BLB) + bucket <- rbind(bucket,spectrum[j,]) + } + + f.bucket[b,] <- c(round(mean(bucket[,1]),3),0) + + # Next bucket boundary + BUB <- spectrum[j,1] + b <- b + 1 + } + } if (!exclusion.in) # Bucketing { BLB <- BUB - bucketSize bucket <- spectrum[j,] - while (j < dim(spectrum)[1] && spectrum[j,1] >= BLB) + while (j < dim(spectrum)[1] && spectrum[j,1] > BLB) { j <- j + 1 if (spectrum[j,1] > BLB) @@ -219,6 +237,7 @@ identifiants <- gsub("([- , * { } | \\[ ])","_",colnames(bucketedSpectra)[-1]) colnames(bucketedSpectra) <- c(colnames(bucketedSpectra)[1],identifiants) + bucketedSpectra <- bucketedSpectra[bucketedSpectra[,1]!=0,] rownames(bucketedSpectra) <- paste("B",bucketedSpectra[,1],sep="") bucketedSpectra <- bucketedSpectra[,-1] @@ -232,7 +251,7 @@ rownames(variableMetadata) <- rownames(bucketedSpectra) colnames(variableMetadata) <- "VariableOrder" - ## OUTPUTS + return(list(bucketedSpectra,sampleMetadata,variableMetadata,ppm)) # ,truncatedSpectrum_matrice } diff -r 1df0b8efe9fc -r c54c70af216b nmr_bucketing/NmrBucketing_wrapper.R --- a/nmr_bucketing/NmrBucketing_wrapper.R Mon Mar 06 06:34:01 2017 -0500 +++ b/nmr_bucketing/NmrBucketing_wrapper.R Thu Apr 20 06:34:51 2017 -0400 @@ -39,7 +39,7 @@ ## Libraries laoding ##------------------------------ # For parseCommandArgs function -library(batch) +library(batch) # For cumtrapz function library(pracma) @@ -72,8 +72,6 @@ if(!runExampleL) argLs <- parseCommandArgs(evaluate=FALSE) -## sink(argLs[["logOut"]]) - ## Parameters Loading ##------------------- @@ -83,14 +81,6 @@ zipfile= argLs[["zipfile"]] directory=unzip(zipfile, list=F) directory=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/") -} else if (!is.null(argLs[["library"]])){ - fileType="zip" - directory=argLs[["library"]] - if(!file.exists(directory)){ - error_message=paste("Cannot access the directory :",directory,".Please verify if the directory exists or not.") - print(error_message) - stop(error_message) - } } else if (!is.null(argLs[["tsvfile"]])){ fileType="tsv" directory <- read.table(argLs[["tsvfile"]],check.names=FALSE,header=TRUE,sep="\t") @@ -128,12 +118,12 @@ if(length(error.stock) > 1) stop(error.stock) - - + + ## Computation ##------------ -outputs <- NmrBucketing(fileType=fileType, fileName=directory, leftBorder=leftBorder, rightBorder=rightBorder, bucketSize=bucketSize, - exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders, graph=graphique, nomFichier=nomGraphe, +outputs <- NmrBucketing(fileType=fileType, fileName=directory, leftBorder=leftBorder, rightBorder=rightBorder, bucketSize=bucketSize, + exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders, graph=graphique, nomFichier=nomGraphe, savLog.txtC=logFile) data_bucket <- outputs[[1]] data_sample <- outputs[[2]] @@ -166,17 +156,33 @@ ## Zoomed spectral window depending on exclusion zone(s) if (nbZones != 0) { - spectra <- data.frame(t(data_bucket[1:(which(ppm == excludedZone[n])[[1]]),])) + BInf <- excludedZone[n] + if (round(BInf,1) == BInf) + { + BInf <- BInf+0.01 + } + spectra <- data.frame(t(data_bucket[1:(which(ppm == BInf)[[1]]),])) drawSpec(spectra,xlab="", ylab="Intensity", main="") n <- n - 1 while (n >= nbZones & nbZones > 1) { - spectra <- data.frame(t(data_bucket[(which(ppm == excludedZone[n])[[1]]):(which(ppm == excludedZone[n-1])[[1]]),])) + BInf <- excludedZone[n-1] + if (round(BInf,1) > BInf) + { + BInf <- BInf+0.01 + } + spectra <- data.frame(t(data_bucket[(which(ppm == excludedZone[n])[[1]]):(which(ppm == BInf)[[1]]),])) drawSpec(spectra,xlab="", ylab="Intensity", main="") n <- n - 2 } - spectra <- data.frame(t(data_bucket[(which(ppm == excludedZone[1])[[1]]):nrow(data_bucket),])) + + BInf <- excludedZone[1] + if (round(BInf,1) <= BInf) + { + BInf <- BInf+0.01 + } + spectra <- data.frame(t(data_bucket[(which(ppm == BInf)[[1]]):nrow(data_bucket),])) drawSpec(spectra,xlab="", ylab="Intensity", main="") } } @@ -187,47 +193,95 @@ par(mfrow=c((nbZones+2),1)) n <- length(excludedZone) spectra <- t(data_bucket[,i]) - drawSpec(spectra,xlab="", ylab="Intensity", main=colnames(data_bucket)[i]) - + names(spectra) <- rownames(data_bucket) + plot(1:length(spectra), spectra, type='l', xlab="", ylab="Intensity", main=colnames(data_bucket)[i], xaxt = "n") + xPos <- 1 + nAxisPos <- 4 + startP <- length(nAxisPos) + endP <- nrow(data_bucket) + GraphRange <- c(startP:endP) + tempVal = trunc(length(GraphRange)/nAxisPos) + xPos = c(0:nAxisPos) * tempVal + axis(1, at = xPos, labels = rownames(data_bucket)[xPos + startP]) + ## Zoomed spectral window depending on exclusion zone(s) if (nbZones != 0) { - spectra <- t(data_bucket[1:(which(ppm == excludedZone[n])[[1]]),i]) - drawSpec(spectra,xlab="", ylab="Intensity", main="") + BInf <- excludedZone[n] + if (round(BInf,1) == BInf) + { + BInf <- BInf+0.01 + } + spectra <- t(data_bucket[1:(which(ppm == BInf)[[1]]),i]) + names(spectra) <- rownames(data_bucket)[1:(which(ppm == BInf)[[1]])] + plot(1:length(spectra), spectra, type='l',xlab="", ylab="Intensity", main="", xaxt = "n") + xPos <- 1 + nAxisPos <- 4 + startP <- length(nAxisPos) + endP <- length(spectra) + GraphRange <- c(startP:endP) + tempVal = trunc(length(GraphRange)/nAxisPos) + xPos = c(0:nAxisPos) * tempVal + axis(1, at = xPos, labels = rownames(data_bucket)[xPos + startP]) n <- n - 1 while (n >= nbZones & nbZones > 1) { - spectra <- t(data_bucket[(which(ppm == excludedZone[n])[[1]]):(which(ppm == excludedZone[n-1])[[1]]),i]) - drawSpec(spectra,xlab="", ylab="Intensity", main="") + BInf <- excludedZone[n-1] + if (round(BInf,1) > BInf) + { + BInf <- BInf+0.01 + } + spectra <- t(data_bucket[(which(ppm == excludedZone[n])[[1]]):(which(ppm == BInf)[[1]]),i]) + names(spectra) <- rownames(data_bucket)[(which(ppm == excludedZone[n])[[1]]):(which(ppm == BInf)[[1]])] + plot(1:length(spectra), spectra, type='l',xlab="", ylab="Intensity", main="", xaxt = "n") + xPos <- 1 + nAxisPos <- 4 + startP <- length(nAxisPos) + endP <- length(spectra) + GraphRange <- c(startP:endP) + tempVal = trunc(length(GraphRange)/nAxisPos) + xPos = c(0:nAxisPos) * tempVal + axis(1, at = xPos, labels = rownames(data_bucket)[xPos + startP]) n <- n - 2 } - spectra <- t(data_bucket[(which(ppm == excludedZone[1])[[1]]):nrow(data_bucket),i]) - drawSpec(spectra,xlab="", ylab="Intensity", main="") + BInf <- excludedZone[1] + if (round(BInf,1) <= BInf) + { + BInf <- BInf+0.01 + } + spectra <- t(data_bucket[(which(ppm == BInf)[[1]]):nrow(data_bucket),i]) + names(spectra) <- rownames(data_bucket)[(which(ppm == BInf)[[1]]):nrow(data_bucket)] + plot(1:length(spectra), spectra, type='l',xlab="", ylab="Intensity", main="", xaxt = "n") + xPos <- 1 + nAxisPos <- 4 + startP <- length(nAxisPos) + endP <- length(spectra) + GraphRange <- c(startP:endP) + tempVal = trunc(length(GraphRange)/nAxisPos) + xPos = c(0:nAxisPos) * tempVal + axis(1, at = xPos, labels = rownames(data_bucket)[xPos + startP]) } } } dev.off() } - ## Saving ##------- # Data data_bucket <- cbind(rownames(data_bucket),data_bucket) colnames(data_bucket) <- c("Bucket",colnames(data_bucket)[-1]) write.table(data_bucket,file=argLs$dataMatrixOut,quote=FALSE,row.names=FALSE,sep="\t") -if (fileType=="zip") -{ # Sample - data_sample <- cbind(rownames(data_sample),data_sample) - colnames(data_sample) <- c("Sample",colnames(data_sample)[-1]) - write.table(data_sample,file=argLs$sampleOut,quote=FALSE,row.names=FALSE,sep="\t") - # Variable - data_variable <- cbind(rownames(data_variable),data_variable) - colnames(data_variable) <- c("Bucket",colnames(data_variable)[-1]) - write.table(data_variable,file=argLs$variableOut,quote=FALSE,row.names=FALSE,sep="\t") -} +data_sample <- cbind(rownames(data_sample),data_sample) +colnames(data_sample) <- c("Sample",colnames(data_sample)[-1]) +write.table(data_sample,file=argLs$sampleOut,quote=FALSE,row.names=FALSE,sep="\t") + # Variable +data_variable <- cbind(rownames(data_variable),data_variable) +colnames(data_variable) <- c("Bucket",colnames(data_variable)[-1]) +write.table(data_variable,file=argLs$variableOut,quote=FALSE,row.names=FALSE,sep="\t") + ## Ending ##--------------------- diff -r 1df0b8efe9fc -r c54c70af216b nmr_bucketing/NmrBucketing_xml.xml --- a/nmr_bucketing/NmrBucketing_xml.xml Mon Mar 06 06:34:01 2017 -0500 +++ b/nmr_bucketing/NmrBucketing_xml.xml Thu Apr 20 06:34:51 2017 -0400 @@ -1,9 +1,8 @@ - + Bucketing and integration of NMR Bruker raw data - R r-batch r-pracma @@ -15,9 +14,7 @@ Rscript '$__tool_directory__/NmrBucketing_wrapper.R' - #if $inputs.input == "lib": - library '$__app__.config.user_library_import_dir/$__user_email__/$inputs.library' - #elif $inputs.input == "tsv_file": + #if $inputs.input == "tsv_file": tsvfile '$inputs.tsv_file' #elif $inputs.input == "zip_file": zipfile '$inputs.zip_file' @@ -57,7 +54,6 @@ - @@ -65,12 +61,6 @@ - - - - - - @@ -102,18 +92,14 @@ - - input == "zip_file" - - - input == "zip_file" - + + graphType != "None" - + @@ -132,7 +118,7 @@ - + .. class:: infomark @@ -157,9 +143,9 @@ **Upstream tools** ========================= ============================ ======= -Name output file format +Name output file format ========================= ============================ ======= -NMRAlignment NMR_Alignment_alignedSpectra tsv +NMRAlignment NMR_Alignment_alignedSpectra tsv ========================= ============================ ======= **Downstream tools** @@ -194,7 +180,6 @@ You have three methods for your inputs: | Zip file (recommended): You can put a zip file containing your inputs as raw Bruker files: myinputs.zip (containing all your conditions as sub-directories). -| library folder: You must specify the name of your "library" (folder) created within your space project (for example: /projet/externe/institut/login/galaxylibrary/yourlibrary). Your library must contain all your conditions as sub-directories. | Tsv file: You can put a tsv file containing your inputs as preprocessed spectra: myinputs.tsv (containing all your conditions in columns and chemical shifts in rows). .. image:: ./static/images/Mth_Architecture_Repertoire_Bruker.png @@ -230,7 +215,7 @@ Right exclusion zone | Lower boundary of exclusion zone -| *Notes:* +| *Notes:* | - these parameters can be used several times using the "Add new exclusion zones" button | @@ -264,7 +249,7 @@ spectra.pdf | pdf output | Graphical chart of bucketed and integrated data -| +| --------------------------------------------------- @@ -288,11 +273,11 @@ **Version 1.0.3 - 24/10/2016** -- ENHANCEMENT: add possibility of bucketing processed files (upstream tools) - +- ENHANCEMENT: add possibility of bucketing processed files (upstream tools) + **Version 1.0.2 - 12/08/2016** -- ENHANCEMENT: x-axis customization: add chemical shift labels +- ENHANCEMENT: x-axis customization: add chemical shift labels **Version 1.0.1 - 04/04/2016** @@ -306,4 +291,3 @@ 10.1093/bioinformatics/btu813 -