Mercurial > repos > marie-tremblay-metatoul > nmr_bucketing
changeset 8:c54c70af216b draft
Uploaded
author | marie-tremblay-metatoul |
---|---|
date | Thu, 20 Apr 2017 06:34:51 -0400 |
parents | 1df0b8efe9fc |
children | 62c62e31fc80 |
files | nmr_bucketing/NmrBucketing_script.R nmr_bucketing/NmrBucketing_wrapper.R nmr_bucketing/NmrBucketing_xml.xml |
diffstat | 3 files changed, 126 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- 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 }
--- 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 ##---------------------
--- 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 @@ -<tool id="NmrBucketing" name="NMR_Bucketing" version="2.0.1"> +<tool id="NmrBucketing" name="NMR_Bucketing" version="1.0.3"> <description> Bucketing and integration of NMR Bruker raw data</description> <requirements> - <requirement type="package" version="3.1.2">R</requirement> <requirement type="package" version="1.1_4">r-batch</requirement> <requirement type="package" version="1.8.8">r-pracma</requirement> </requirements> @@ -15,9 +14,7 @@ <command> 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 @@ <param name="input" type="select" label="Choose your inputs method" > <option value="zip_file" selected="true">Zip file from your history containing your Bruker directories</option> <option value="tsv_file">Tsv file containing preprocessed spectra (from your history)</option> - <option value="lib" >Library directory name</option> </param> <when value="zip_file"> <param name="zip_file" type="data" format="no_unzip.zip" label="Zip file" /> @@ -65,12 +61,6 @@ <when value="tsv_file"> <param name="tsv_file" type="data" format="tabular" label="Tsv file" /> </when> - <when value="lib"> - <param name="library" type="text" size="40" label="Library directory name" help="The name of your directory containing all your data" > - <validator type="empty_field"/> - </param> - </when> - </conditional> <param name="bucket_width" label="Bucket width" type="float" value="0.04" help="Default value is 0.04 ppm"/> @@ -102,18 +92,14 @@ </inputs> <outputs> - <data format="tabular" name="sampleOut" label="${tool.name}_sampleMetadata" > - <filter> input == "zip_file" </filter> - </data> - <data format="tabular" name="variableOut" label="${tool.name}_variableMetadata" > - <filter> input == "zip_file" </filter> - </data> + <data format="tabular" name="sampleOut" label="${tool.name}_sampleMetadata" /> + <data format="tabular" name="variableOut" label="${tool.name}_variableMetadata" /> <data format="tabular" name="dataMatrixOut" label="${tool.name}_bucketedData" /> <data format="pdf" name="graphOut" label="${tool.name}_spectra" > <filter> graphType != "None" </filter> </data> </outputs> - + <tests> <test> <param name="inputs|input" value="zip_file" /> @@ -132,7 +118,7 @@ <output name="variableOut" file="MTBLS1_variableMetadata.tabular" /> </test> </tests> - + <help> .. 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 @@ <citation type="doi">10.1093/bioinformatics/btu813</citation> </citations> </tool> -