# HG changeset patch # User marie-tremblay-metatoul # Date 1490968599 14400 # Node ID 908e1345d7ca05d570229c3512c4a87a2da03368 # Parent 58eecef626daadf4354d39eaf77e9e2066bf2b8f Uploaded diff -r 58eecef626da -r 908e1345d7ca nmr_alignement/NmrAlignment_script.R --- a/nmr_alignement/NmrAlignment_script.R Thu Mar 02 10:23:37 2017 -0500 +++ b/nmr_alignement/NmrAlignment_script.R Fri Mar 31 09:56:39 2017 -0400 @@ -425,13 +425,43 @@ # - data.read: n x p matrix # # - data.aligned: n x p matrix # ################################################################################################ -nmr.alignment <- function(directory, leftBorder= 10.0, rightBorder= 0.5, exclusionZones=FALSE, +nmr.alignment <- function(fileType, directory, leftBorder= 10.0, rightBorder= 0.5, exclusionZones=FALSE, exclusionZonesBorders=NULL, reference=0, nDivRange=64, baselineThresh=50000, maxshift=50, verbose=FALSE) { - data.read <- NmrRead(directory=directory, leftBorder=leftBorder, rightBorder=rightBorder, exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders) - rownames(data.read) <- data.read[,1] - data.read <- data.read[,-1] - data.read <- t(data.read) + if (fileType=="zip") + { + data.read <- NmrRead(directory=directory, leftBorder=leftBorder, rightBorder=rightBorder, exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders) + rownames(data.read) <- data.read[,1] + data.read <- data.read[,-1] + data.read <- t(data.read) + } + if (fileType=="tsv") + { + data.read <- t(directory) + ppm <- round(as.numeric(colnames(data.read)),2) + + if (!is.null(exclusionZonesBorders)) + { + excludedZone <- NULL + for (c in 1:length(exclusionZonesBorders)) + { + excludedZone <- c(excludedZone,exclusionZonesBorders[[c]]) + excludedZone <- sort(excludedZone) + } + + nbZones <- length(excludedZone)/2 + n <- length(excludedZone) + data <- data.read[,1:which(ppm == excludedZone[n])[1]] + n <- n - 1 + while (n >= nbZones & nbZones > 1) + { + data <- cbind(data, data.read[,(which(ppm == excludedZone[n])[1]):(which(ppm == excludedZone[n-1])[1])]) + n <- n - 2 + } + data <- cbind(data, data.read[,(which(ppm == excludedZone[1])[1]):ncol(data.read)]) + data.read <- data + } + } data.aligned <- cluPA.alignment(data=data.read, reference=reference, nDivRange=nDivRange, baselineThresh=baselineThresh, maxshift=maxshift, verbose=verbose) diff -r 58eecef626da -r 908e1345d7ca nmr_alignement/NmrAlignment_wrapper.R --- a/nmr_alignement/NmrAlignment_wrapper.R Thu Mar 02 10:23:37 2017 -0500 +++ b/nmr_alignement/NmrAlignment_wrapper.R Fri Mar 31 09:56:39 2017 -0400 @@ -57,16 +57,21 @@ # Inputs ## Library of spectra to align if (!is.null(argLs[["zipfile"]])){ + fileType="zip" 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") } @@ -110,7 +115,7 @@ ## Computation ##------------ -directory.alignement <- nmr.alignment(directory=directory,leftBorder=leftBorder,rightBorder=rightBorder,exclusionZones=exclusionZones, +directory.alignement <- nmr.alignment(fileType=fileType,directory=directory,leftBorder=leftBorder,rightBorder=rightBorder,exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders, reference=reference, nDivRange=nDivRange, baselineThresh=baselineThresh, maxshift=50, verbose=FALSE) directory.raw <- directory.alignement[[1]] diff -r 58eecef626da -r 908e1345d7ca nmr_alignement/NmrAlignment_xml.xml --- a/nmr_alignement/NmrAlignment_xml.xml Thu Mar 02 10:23:37 2017 -0500 +++ b/nmr_alignement/NmrAlignment_xml.xml Fri Mar 31 09:56:39 2017 -0400 @@ -1,4 +1,4 @@ - + based on the Cluster-based Peak Alignment (CluPA) algorithm R @@ -15,6 +15,8 @@ ## File input #if $inputs.input == "lib": library '$__app__.config.user_library_import_dir/$__user_email__/$inputs.library' + #elif $inputs.input == "tsv_file": + tsvfile $inputs.tsv_file #elif $inputs.input == "zip_file": zipfile '$inputs.zip_file' #end if @@ -50,11 +52,15 @@ + + + +