diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..f068a92 --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,14 @@ +Package: speaq +Type: Package +Title: An R-package for NMR spectrum alignment and quantitation +Version: 1.2.0 +Date: 2015-05-01 +Author: Trung Nghia VU, Kris Laukens and Dirk Valkenborg +Maintainer: Trung Nghia VU +Description: Integrated NMR spectrum alignment and quantitation based on Hierarchial Clustering Based Peak Alignment (CluPA) +Depends: R (>= 3.0.0), MassSpecWavelet +License: Apache License 2.0 +biocViews: NuclearMagneticResonance, Bioinformatics, Spectrum, + Alignment, Quantitation,Proteomics, Clustering, + MassSpectrometry, NMR +Packaged: 2015-01-04 20:26:17 UTC; trungvu diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..55d7aef --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,6 @@ +importFrom(graphics, abline, contour, hist, legend, lines, par, plot, + points, segments, text, title) +importFrom(stats, fft) +importFrom(MassSpecWavelet, peakDetectionCWT) + +export(detectSpecPeaks,dohCluster,dohClusterCustommedSegments,doShift,drawSpec,findRef,returnLocalMaxima,export2file,findSegPeakList,findShiftStepFFT,hClustAlign,BWR,drawBW,createNullSampling) \ No newline at end of file diff --git a/R/BWR.R b/R/BWR.R new file mode 100644 index 0000000..88843da --- /dev/null +++ b/R/BWR.R @@ -0,0 +1,34 @@ +BWR <-function(X, groupLabel) +{ + groupNum=length(levels(groupLabel)); + m=colMeans(X); + groupMean=list(); + groupW=list(); + B=X; + B[,]=0; + for (i in 1:groupNum){ + groupLabeli=which(groupLabel==levels(groupLabel)[i]); + Xi=X[groupLabeli,] + mi=colMeans(Xi); + groupMean[[i]]=mi; + tempi=matrix(data=rep(mi,nrow(Xi)),nrow=nrow(Xi), + ncol=length(mi),byrow=TRUE); + + Wi=(Xi-tempi)^2; + groupW[[i]]=Wi; + temp=matrix(data=rep(m,nrow(Xi)),nrow=nrow(Xi), + ncol=length(m),byrow=TRUE); + B[groupLabeli,]=(tempi-temp)^2; + } + + BW=double(ncol(B)); + for (i in 1:length(BW)){ + BW_denominator=0; + for (j in 1:groupNum){ + BW_denominator=BW_denominator+sum(groupW[[j]][,i]); + } + Bw_numerator=sum(B[,i]); + BW[i]=Bw_numerator/BW_denominator; + } + return(BW); +} \ No newline at end of file diff --git a/R/createNullSampling.R b/R/createNullSampling.R new file mode 100644 index 0000000..35d2e98 --- /dev/null +++ b/R/createNullSampling.R @@ -0,0 +1,32 @@ +createNullSampling <-function(X, groupLabel, N=1000, + filename=NULL, verbose=TRUE){ + + groupNum=length(levels(groupLabel)); + samplePool=X; + groupMean=list(); + + for (i in 1:groupNum){ + groupLabeli=which(groupLabel==levels(groupLabel)[i]); + Xi=X[groupLabeli,] + mi=colMeans(Xi); + groupMean[[i]]=mi; + } + + for (i in 1:nrow(samplePool)){ + samplePool[i,]= + X[i,]-groupMean[[which(levels(groupLabel)==groupLabel[i])]]; + } + + L=nrow(X); + H0=matrix(data=0,nrow=N,ncol=ncol(X)); + + for(i in 1 : N){ + if (verbose) cat(i,"\n"); + index=sample(L); + H0[i,]=BWR(samplePool[index,],groupLabel); + } + + if (!is.null(filename)) + write.csv(H0,filename,row.names=FALSE,col.names=FALSE); + return(H0); +} diff --git a/R/detectSpecPeaks.R b/R/detectSpecPeaks.R new file mode 100644 index 0000000..3fe39d5 --- /dev/null +++ b/R/detectSpecPeaks.R @@ -0,0 +1,43 @@ +detectSpecPeaks <-function(X, nDivRange=128, scales=seq(1,16,2), + baselineThresh=50000, SNR.Th=-1, verbose=TRUE){ +nFea=ncol(X); +nSamp=nrow(X); +noiseEsp=0.005; +if (SNR.Th<0) SNR.Th=max(scales) * 0.05; +pList=NULL; +for (i in 1:nSamp){ + myPeakRes=NULL; + mySpec=X[i,]; + for (k in 1:length(nDivRange)){ + divR=nDivRange[k]; + for (j in 1:(trunc(nFea/divR)-3)){ + startR=(j-1)*divR+1; + if (startR>=nFea) startR=nFea; + endR=(j+3)*divR; + if (endR>nFea) endR=nFea; + + xRange=mySpec[startR:endR]; + xMean=mean(xRange); + xMedian=median(xRange); + if ((xMean==xMedian)||abs(xMean-xMedian)/((xMean+xMedian)*2)0){ + myPeakRes=c(myPeakRes,majorPeakInfo$peakIndex+startR-1); + } + } + } + } + pList[i]=list(myPeakRes); + pList[[i]]=sort(unique(pList[[i]])); + pList[[i]]=pList[[i]][which(X[i,pList[[i]]]>baselineThresh)] + pList[[i]]=sort(pList[[i]]); + if (verbose) cat("\n Spectrum ",i," has ",length(pList[[i]])," peaks"); +} + +return (pList) +} diff --git a/R/doShift.R b/R/doShift.R new file mode 100644 index 0000000..64406c1 --- /dev/null +++ b/R/doShift.R @@ -0,0 +1,15 @@ +doShift <-function(specSeg, shiftStep){ + nFea=length(specSeg); + newSegment=double(nFea); + for (j in 1:nFea) + if (shiftStep+j>0&&shiftStep+j<=nFea) + newSegment[shiftStep+j]=specSeg[j]; + if (shiftStep>0){ + for (j in 1: shiftStep) newSegment[j]=newSegment[shiftStep+1]; + } + else{ + for (j in (nFea+shiftStep): nFea) + newSegment[j]=newSegment[(nFea+shiftStep-1)]; + } + return (newSegment); +} diff --git a/R/dohCluster.R b/R/dohCluster.R new file mode 100644 index 0000000..3d71f7c --- /dev/null +++ b/R/dohCluster.R @@ -0,0 +1,31 @@ +dohCluster <-function(X, peakList, refInd=0, + maxShift =100, acceptLostPeak=TRUE, verbose=TRUE){ + Y=X; + peakListNew=peakList; + + if (verbose) startTime=proc.time(); + refSpec=Y[refInd,]; + for (tarInd in 1: nrow(X)) + if (tarInd!=refInd) + { + if (verbose) cat("\n aligning spectrum ",tarInd); + targetSpec=Y[tarInd,]; + myPeakList=c(peakList[[refInd]],peakList[[tarInd]]); + myPeakLabel=double(length(myPeakList)); + for (i in 1:length(peakList[[refInd]]) ) myPeakLabel[i]=1; + startP=1; + endP=length(targetSpec); + res=hClustAlign(refSpec,targetSpec,myPeakList,myPeakLabel,startP,endP, + maxShift=maxShift,acceptLostPeak=acceptLostPeak) + Y[tarInd,]=res$tarSpec; + + peakListNew[[tarInd]]= + res$PeakList[(length(peakList[[refInd]])+1):length(myPeakList)] + } + peakList=peakListNew; + if (verbose){ + endTime=proc.time(); + cat("\n Alignment time: ",(endTime[3]-startTime[3])/60," minutes"); + } + return(Y); +} diff --git a/R/dohClusterCustommedSegments.R b/R/dohClusterCustommedSegments.R new file mode 100644 index 0000000..fb533e5 --- /dev/null +++ b/R/dohClusterCustommedSegments.R @@ -0,0 +1,58 @@ +dohClusterCustommedSegments <-function(X, peakList, refInd, maxShift, + acceptLostPeak=TRUE, infoFilename, minSegSize=128,verbose=TRUE){ + + myinfo=read.csv(infoFilename,header=TRUE,sep=","); + myinfo=as.matrix(myinfo); + + if (myinfo[1,1]>minSegSize) + mysegments=c(1,myinfo[1,1]-1,0,0,0) else mysegments=c(); + i = 0; + if (nrow(myinfo)>1){ + for (i in 1:(nrow(myinfo)-1)){ + mysegments=c(mysegments,c(myinfo[i,])) + if (myinfo[i+1,1]-myinfo[i,2]>minSegSize) + mysegments=c(mysegments,c(myinfo[i,2]+1,myinfo[i+1,1]-1,0,0,0)) + } + } + mysegments=c(mysegments,c(myinfo[i+1,])) + + if (ncol(X)-myinfo[i+1,2]-1>minSegSize) + mysegments=c(mysegments,c(myinfo[i+1,2]+1,ncol(X),0,0,0)) + + mysegments=matrix(data=mysegments,nrow=length(mysegments)/5, + ncol=5,byrow=TRUE,dimnames=NULL) + + mysegments[which(mysegments[,4]==0),4]=refInd; + mysegments[which(mysegments[,5]==0),5]=maxShift; + + if (sum(mysegments[,3]!=0)==0){ + cat("\n No segments are set for alignment! Please put + at least 1 row in ",infoFilename, " containing forAlign=1.") + return; + } + + Y=X; + + for (i in 1:nrow(mysegments)) + if (mysegments[i,3]!=0) + { + if (verbose) + cat("\n Doing alignment a segment from ", + mysegments[i,1]," to ",mysegments[i,2]," ..."); + + segmentpeakList=peakList; + for (j in 1:length(peakList)){ + segmentpeakList[[j]]= + findSegPeakList(peakList[[j]],mysegments[i,1],mysegments[i,2]); + } + Y[,c(mysegments[i,1]:mysegments[i,2])]= + dohCluster(X[,c(mysegments[i,1]:mysegments[i,2])],peakList=segmentpeakList, + refInd=mysegments[i,4],maxShift =mysegments[i,5], + acceptLostPeak=acceptLostPeak, verbose=verbose); + }else{ + if (verbose) + cat("\n The segment ", + mysegments[i,1],"-",mysegments[i,2], " is not aligned"); + } + return(Y) +} \ No newline at end of file diff --git a/R/drawBW.R b/R/drawBW.R new file mode 100644 index 0000000..2e6c371 --- /dev/null +++ b/R/drawBW.R @@ -0,0 +1,18 @@ +drawBW <-function(BW, perc, X, startP=-1, endP=-1, groupLabel=NULL, + highBound=-1, lowBound=-1, nAxisPos=4, offside=0){ + if (startP==-1) startP=1; + if (endP==-1) endP=ncol(X); + GraphRange<-c(startP:endP); + op=par(mfrow=c(2,1)) + + plot(BW[GraphRange],ylim=c(min(c(BW[GraphRange]),perc[GraphRange]), + max(c(BW[GraphRange]),perc[GraphRange])),type="n", ylab="BW", + xlab="index", xaxt="n") + tempVal =trunc(length(GraphRange)/nAxisPos); + xPos=c(0:nAxisPos) * tempVal; + axis(1,at=xPos,groupLabel=xPos+startP+offside); + lines(BW[GraphRange],col= "blue") + lines(perc[GraphRange],col= "black") + drawSpec(X,xlab="index",ylab="intensity",startP=startP,endP=endP,groupLabel=groupLabel, + offside=offside,highBound=highBound,lowBound=lowBound) +} diff --git a/R/drawSpec.R b/R/drawSpec.R new file mode 100644 index 0000000..379ca2d --- /dev/null +++ b/R/drawSpec.R @@ -0,0 +1,64 @@ +drawSpec <-function(X, startP=-1, endP=-1, groupLabel=NULL, useLog=-1, + highBound=-1, lowBound=-1, xlab=NULL, ylab=NULL, main=NULL, + nAxisPos=4, offside=0) +{ + groupLabel_name=groupLabel; + X=as.data.frame(X); + colnames(X)=c(1:ncol(X)); + X=as.matrix(X); + if (highBound!=-1){ + for (i in 1:nrow(X)){ + myIndex=which(X[i,]>highBound); + X[i,myIndex]=highBound; + } + } + + if (lowBound!=-1){ + for (i in 1:nrow(X)){ + myIndex=which(X[i,]startP&&peakList[i]M)) maxShift=M; + if (anyNA(vals)){ + lag =0; + return(list(corValue=maxi,stepAdj=lag)); + } + + for (i in 1:maxShift){ + if (vals[i]>maxi){ + maxi=vals[i]; + maxpos=i; + } + if (vals[lenVals-i+1]>maxi){ + maxi=vals[lenVals-i+1]; + maxpos=lenVals-i+1; + } + } + if (maxi<0.1){ + lag =0; + return(list(corValue=maxi,stepAdj=lag)); + } + if (maxpos>lenVals/2) lag=maxpos-lenVals-1 else lag =maxpos-1; + return(list(corValue=maxi,stepAdj=lag)); +} \ No newline at end of file diff --git a/R/hClustAlign.R b/R/hClustAlign.R new file mode 100644 index 0000000..92760ec --- /dev/null +++ b/R/hClustAlign.R @@ -0,0 +1,95 @@ +hClustAlign <-function(refSpec, tarSpec, peakList, peakLabel, startP, endP, + distanceMethod="average", maxShift=0, acceptLostPeak=FALSE){ +minpeakList=min(peakList)[1]; +maxpeakList=max(peakList)[1]; +startCheckP=startP+which.min(tarSpec[startP:(minpeakList-1)])[1]-1; +if (is.na(startCheckP)) startCheckP=startP; + +endCheckP=maxpeakList+ which.min(tarSpec[(maxpeakList+1):endP])[1]; +if (is.na(endCheckP)) endCheckP=endP; + +if ((endCheckP-startCheckP)<2) { + return (list(tarSpec=tarSpec,peakList=peakList)); +} +adj=findShiftStepFFT(refSpec[startCheckP:endCheckP], + tarSpec[startCheckP:endCheckP],maxShift=maxShift); +if (adj$stepAdj!=0){ + if (acceptLostPeak) isImplementShift=TRUE + else isImplementShift=(adj$stepAdj<0&&adj$stepAdj+ + minpeakList >=startCheckP )||(adj$stepAdj>0&&adj$stepAdj+ + maxpeakList<=endCheckP); + if (isImplementShift) + { + newTargetSpecRegion=doShift(tarSpec[startCheckP:endCheckP],adj$stepAdj); + tarSpec[startCheckP:endCheckP]=newTargetSpecRegion; + + peakListTarget=which(peakLabel==0); + peakList[peakListTarget]=peakList[peakListTarget]+adj$stepAdj; + + lostPeaks=which(peakList<=0); + if (length(lostPeaks) >0){ + + peakList=peakList[-lostPeaks]; + peakLabel=peakLabel[-lostPeaks]; + } + } +} + +if (length(peakList)<3) {return (list(tarSpec=tarSpec,peakList=peakList));} +hc=hclust(dist(peakList),method=distanceMethod) +clusterLabel=cutree(hc,h=hc$height[length(hc$height)-1]); +if (length(unique(clusterLabel))<2){ + return (list(tarSpec=tarSpec,peakList=peakList)); + } + +labelID1=which(clusterLabel==1); +subData1=peakList[labelID1]; +subLabel1=peakLabel[labelID1]; + +labelID2=which(clusterLabel==2); +subData2=peakList[labelID2]; +subLabel2=peakLabel[labelID2]; +maxsubData1=max(subData1)[1]; +minsubData2=min(subData2)[1]; + +if (maxsubData11){ + res=hClustAlign(refSpec,tarSpec,subData1,subLabel1,startP,endP1, + distanceMethod=distanceMethod,maxShift=maxShift, + acceptLostPeak=acceptLostPeak); + tarSpec=res$tarSpec; + peakList[labelID1]=res$peakList; + } + if (length(unique(subLabel2))>1){ + res=hClustAlign(refSpec,tarSpec,subData2,subLabel2,startP2,endP, + distanceMethod=distanceMethod,maxShift=maxShift, + acceptLostPeak=acceptLostPeak); + tarSpec=res$tarSpec; + peakList[labelID2]=res$peakList; + } +}else{ + maxsubData2=max(subData2)[1]; + minsubData1=min(subData1)[1]; + endP2=maxsubData2+which.min(tarSpec[(maxsubData2+1) :(minsubData1-1)])[1]; + if (is.na(endP2)) endP2=maxsubData2; + startP1=endP2+1; + if (length(unique(subLabel2))>1){ + res=hClustAlign(refSpec,tarSpec,subData2,subLabel2,startP,endP2, + distanceMethod=distanceMethod,maxShift=maxShift, + acceptLostPeak=acceptLostPeak); + tarSpec=res$tarSpec; + peakList[labelID2]=res$peakList; + } + if (length(unique(subLabel1))>1){ + res=hClustAlign(refSpec,tarSpec,subData1,subLabel1,startP1,endP, + distanceMethod=distanceMethod,maxShift=maxShift, + acceptLostPeak=acceptLostPeak); + tarSpec=res$tarSpec; + peakList[labelID1]=res$peakList; + } +} +return (list(tarSpec=tarSpec,peakList=peakList)); +} \ No newline at end of file diff --git a/R/returnLocalMaxima.R b/R/returnLocalMaxima.R new file mode 100644 index 0000000..353cb55 --- /dev/null +++ b/R/returnLocalMaxima.R @@ -0,0 +1,9 @@ +returnLocalMaxima <-function(spectrum){ + l=length(spectrum); + diffs=diff(spectrum); + diffl=diffs[1:(l-1)]; + diffr=diffs[2:l]; + locMax=unique(c(which((diffl>=0&diffr<0))+1,which((diffl>0&diffr<=0))+1)); + pkMax=spectrum[locMax]; +return(list(pkMax=pkMax,locMax=locMax)) +} diff --git a/man/BWR.Rd b/man/BWR.Rd new file mode 100644 index 0000000..4432b6e --- /dev/null +++ b/man/BWR.Rd @@ -0,0 +1,42 @@ +\name{BWR} +\alias{BWR} + +\title{ +BW ratio calculation +} +\description{ +Compute the BW ratios from data groups +} +\usage{ +BWR(X, + groupLabel) +} + +\arguments{ + \item{X}{ +The spectral dataset in the matrix format in which each row contains a single sample +} + \item{groupLabel}{ +Group label of samples in the dataset. +} +} +\details{ +Compute the BW ratios from data groups +} +\value{ +Return BW ratio +} +\author{ +Trung Nghia VU +} + +\seealso{ +\code{\link{createNullSampling}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ BW } + diff --git a/man/createNullSampling.Rd b/man/createNullSampling.Rd new file mode 100644 index 0000000..446370c --- /dev/null +++ b/man/createNullSampling.Rd @@ -0,0 +1,43 @@ +\name{createNullSampling} +\alias{createNullSampling} + +\title{ +Building a null hypothesis data +} +\description{ +Create a null sampling data (N times) and write them to a file +} +\usage{ +createNullSampling(X, groupLabel, N = 1000, filename = NULL, verbose=TRUE) +} + +\arguments{ + \item{X}{ +The spectral dataset in the matrix format in which each row contains a single sample +} + \item{groupLabel}{ +Group label of samples in the dataset. +} + \item{N}{ +The number of iteration for creating null sample distribution +} + \item{filename}{ +The name of output file. +} + \item{verbose}{ +A boolean value to allow print out process information. +} +} +\details{ +Create a null sampling data (N times) and write them to a file +} +\author{ +Trung Nghia VU +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ null hypothesis } + diff --git a/man/detectSpecPeaks.Rd b/man/detectSpecPeaks.Rd new file mode 100644 index 0000000..596fc9f --- /dev/null +++ b/man/detectSpecPeaks.Rd @@ -0,0 +1,52 @@ +\name{detectSpecPeaks} +\alias{detectSpecPeaks} + +\title{ +Peak detection for spectra +} +\description{ +Divide the whole spectra into smaller segments and detect peaks by using MassSpecWavelet package. Note that, the peak lists could be found by using other methods, this function is just a choice. +} +\usage{ +detectSpecPeaks(X, nDivRange = 128, scales = seq(1, 16, 2), + baselineThresh = 50000, SNR.Th = -1, verbose=TRUE) +} + +\arguments{ + \item{X}{ +The spectral dataset in matrix format in which each row contains a single sample +} + \item{nDivRange}{ +The size of a single small segment after division of spectra +} + \item{scales}{ +The parameter of peakDetectionCWT function of MassSpecWavelet package, look it up in the original function. +} + \item{baselineThresh}{ +It will remove all peaks under an intensity set by baselineThresh. +} + \item{SNR.Th}{ +The parameter of peakDetectionCWT function of MassSpecWavelet package, look it up in the original function. If you set -1, the function will itseff re-compute this value. +} + \item{verbose}{ +A boolean value to allow print out process information. +} +} +\details{ +Divide the whole spectra into smaller segments and detect peaks by using MassSpecWavelet package. Note that, the peak lists could be found by using other methods, this function is just a choice. +} +\value{ + +The peak lists of the spectra +} +\author{ +Trung Nghia VU +} + +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ peak detection } + diff --git a/man/doShift.Rd b/man/doShift.Rd new file mode 100644 index 0000000..7c9f1cc --- /dev/null +++ b/man/doShift.Rd @@ -0,0 +1,43 @@ +\name{doShift} +\alias{doShift} + +\title{ +Segment shift +} +\description{ +Move a spectral segment of a sample shiftStep points to right or left +} +\usage{ +doShift(specSeg, + shiftStep) +} + +\arguments{ + \item{specSeg}{ +The segment which needs to be shifted +} + \item{shiftStep}{ +The shift step for moving. If it is a negative (positive) value, the segment is moved to left (right). +} +} +\details{ +Move a spectral segment of a sample shiftStep points to right or left +} +\value{ +The new segment after shifting. +} + +\author{ +Trung Nghia VU +} + +\seealso{ +\code{\link{hClustAlign}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ ~kwd1 } +\keyword{ ~kwd2 } diff --git a/man/dohCluster.Rd b/man/dohCluster.Rd new file mode 100644 index 0000000..1fefe0c --- /dev/null +++ b/man/dohCluster.Rd @@ -0,0 +1,61 @@ +\name{dohCluster} +\alias{dohCluster} + +\title{ +CluPA function for multiple spectra. +} +\description{ +Use CluPA for alignment for multiple spectra. +} +\usage{ +dohCluster(X, + peakList, + refInd = 0, + maxShift = 100, + acceptLostPeak = TRUE, + verbose=TRUE) +} + +\arguments{ + \item{X}{ +The spectral dataset in the matrix format in which each row contains a single sample +} + \item{peakList}{ +The peak lists of the spectra +} + \item{refInd}{ +The index of the reference spectrum. +} + \item{maxShift}{ +The maximum number of the points for a shift step. +} + \item{acceptLostPeak}{ +This is an option for users, TRUE is the default value. If the users believe that all the peaks in the peak list are true positive, change it to FALSE. +} + \item{verbose}{ +A boolean value to allow print out process information. +} +} +\details{ +Use CluPA for alignment for multiple spectra. +} +\value{ + +The aligned spectra. +} +\author{ +Trung Nghia VU +} + + + +\seealso{ +\code{\link{dohClusterCustommedSegments}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ CluPA } +\keyword{ alignment } diff --git a/man/dohClusterCustommedSegments.Rd b/man/dohClusterCustommedSegments.Rd new file mode 100644 index 0000000..84f0fea --- /dev/null +++ b/man/dohClusterCustommedSegments.Rd @@ -0,0 +1,94 @@ +\name{dohClusterCustommedSegments} +\alias{dohClusterCustommedSegments} + +\title{ +Use CluPA for alignment with additional information +} +\description{ +This function integrates some additional information from user such as references for each specific segment, segment ignorance, maximum step size.. +to align spectra using CluPA. + +} +\usage{ +dohClusterCustommedSegments(X, + peakList, + refInd, + maxShift, + acceptLostPeak = TRUE, + infoFilename, + minSegSize = 128, + verbose=TRUE) +} + +\arguments{ + \item{X}{ +The spectral dataset in matrix format in which each row contains a single sample. +} + \item{peakList}{ +The peak lists of the spectra. +} + \item{refInd}{ +The index of the reference spectrum. +} + \item{maxShift}{ +The maximum number of points for a shift step. +} + \item{acceptLostPeak}{ +This is an option for users, TRUE is the default value. If the users believe that all the peaks in the peak list are true positive, change it to FALSE. +} + \item{infoFilename}{ +The name of the file containing the additional information from the users in the CSV format with a header. + +} + \item{minSegSize}{ +The minimum size of the segments which could be considered for alignment. +} + \item{verbose}{ +A boolean value to allow print out process information. +} +} +\details{ +Each line of the infoFilename includes 5 numbers separated by commas, for instance: + +# + +begin,end,forAlign,ref,maxShift + +3600,4000,0,0,0 + +5600,6200,1,0,50 + +# + +- begin: the starting point of the segment. + +- end: the end point of the segment. + +- forAlign: the segment is aligned (1) or not (0). + +- ref: the index of the reference spectrum. If 0, the algorithm will select the reference found by the reference finding step. + +- maxShift: the maximum number of points of a shift to left/right. + +It is worth to note that only segments with forAlign=1 will be taken into account for spectral alignment. +} +\value{ + +The aligned spectral segments. +} + +\author{ +Trung Nghia VU +} + +\seealso{ +\code{\link{dohCluster}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ segment } +\keyword{ CluPA } +\keyword{ alignment } diff --git a/man/drawBW.Rd b/man/drawBW.Rd new file mode 100644 index 0000000..de5fbd3 --- /dev/null +++ b/man/drawBW.Rd @@ -0,0 +1,74 @@ +\name{drawBW} +\alias{drawBW} + +\title{ +BW and percentile ratios plot +} +\description{ +This function is used to plot BW and percentile ratios +} +\usage{ +drawBW(BW, + perc, + X, + startP = -1, + endP = -1, + groupLabel = NULL, + highBound = -1, + lowBound = -1, + nAxisPos = 4, + offside = 0) +} + +\arguments{ + \item{BW}{ +An array of the BW ratios. +} + \item{perc}{ +An array of the percentile ratios. +} + \item{X}{ +The spectral dataset in matrix format in which each row contains a single sample. +} + \item{startP}{ +The starting point of the segment. If it is -1, the starting point is from begining of the spectra. +} + \item{endP}{ +The ending point of the segment. If it is -1, the ending point is the last point of the spectra. +} + \item{groupLabel}{ +The default value is NULL, it means that a single spectrum has a distinct color. Otherwise, the spectra is colored by their label. +} + \item{highBound}{ +Default value is -1, that means the plot covers also the highest intesity peaks in the figure. +If the users want to limit the upper height of the figure, set this parameter by the limited value. +} + \item{lowBound}{ +Default value is -1, that means the plot covers also the lowest intesity peaks in the figure. +If the users want to limit the under height of the figure, set this parameter by the limited value. +} + \item{nAxisPos}{ +The number of ticks that will be displayed in the horizontal axis. +} + \item{offside}{ +The offside of values in x-axis for display. +} +} +\details{ +This function is used to plot BW and percentile ratios +} + +\author{ +Trung Nghia VU +} + +\seealso{ +\code{\link{drawSpec}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ BW } +\keyword{ plot } diff --git a/man/drawSpec.Rd b/man/drawSpec.Rd new file mode 100644 index 0000000..a1d30d7 --- /dev/null +++ b/man/drawSpec.Rd @@ -0,0 +1,82 @@ +\name{drawSpec} +\alias{drawSpec} + +\title{ +Spectral plot +} +\description{ +This function allows to draw a segment or the whole spectra with limited high/low bounds of intensity. +} +\usage{ +drawSpec(X, + startP = -1, + endP = -1, + groupLabel = NULL, + useLog = -1, + highBound = -1, + lowBound = -1, + xlab = NULL, + ylab = NULL, + main = NULL, + nAxisPos = 4, + offside = 0) +} + +\arguments{ + \item{X}{ +The spectral dataset in matrix format in which each row contains a single sample. +} + \item{startP}{ +The starting point of the segment. If it is -1, the starting point is from begining of the spectra. +} + \item{endP}{ +The ending point of the segment. If it is -1, the ending point is the last point of the spectra. +} + \item{groupLabel}{ +The default value is NULL, it means that a single spectrum has a distinct color. Otherwise, the spectra is colored by their label. +} + \item{useLog}{ +The default value is -1, that means do not use a logarit transformation. If users want to transform the intensities to logarit values before ploting, set it to 1. +} + \item{highBound}{ +Default value is -1, that means the plot covers also the highest intesity peaks in the figure. +If the users want to limit the upper height of the figure, set this parameter by the limited value. +} + \item{lowBound}{ +Default value is -1, that means the plot covers also the lowest intesity peaks in the figure. +If the users want to limit the under height of the figure, set this parameter by the limited value. +} + \item{xlab}{ +The default value is NULL, if so, "index" is displayed at the horizontal axis. +} + \item{ylab}{ +The default value is NULL, if so, "intensity" is displayed at the vertical axis. +} + \item{main}{ +The default value is NULL, if so, the title shows the values of startP and endP +} + \item{nAxisPos}{ +The number of ticks that you want to display in horizontal axis. +} + \item{offside}{ +The offside of values in x-axis for display. +} +} +\details{ +This function allows to draw a segment or the whole spectra with limited high/low bounds of intensity. +} + +\author{ +Trung Nghia VU +} +\seealso{ + \code{\link{drawBW}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ plot } +\keyword{ segment } +\keyword{ spectra } diff --git a/man/export2file.Rd b/man/export2file.Rd new file mode 100644 index 0000000..8a5f934 --- /dev/null +++ b/man/export2file.Rd @@ -0,0 +1,41 @@ +\name{export2file} +\alias{export2file} + +\title{ +Export spectra to files +} +\description{ +This function allows to export each spectrum to a single file in caMassClass format. +} +\usage{ +export2file(X, dirPath="./", fileList="InputFiles.csv",saveDirPath="outDir") +} + +\arguments{ + \item{X}{ +The spectral dataset in matrix format in which each row contains a single sample +} + \item{dirPath}{ +The directory containing "fileList", the information files of spectra. +} + \item{fileList}{ +The name of the information file. The information file is a CSV file with header, including three columns: samplenames, label, filenames. This follows the input file format of caMassClass package. +} + \item{saveDirPath}{ +The path to the new directory containing the exported files. +} +} +\details{ +This function allows to export each spectrum to a single file +} + +\author{ +Trung Nghia VU +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ export } +\keyword{ caMassClass } diff --git a/man/findRef.Rd b/man/findRef.Rd new file mode 100644 index 0000000..622f551 --- /dev/null +++ b/man/findRef.Rd @@ -0,0 +1,41 @@ +\name{findRef} +\alias{findRef} + +\title{ +Reference finding +} +\description{ +This function is to heuristically detect a reference spectrum. +} +\usage{ +findRef(peakList) +} + +\arguments{ + \item{peakList}{ +The peak lists of the spectra. +} +} +\details{ +This function is to heuristically detect a reference spectrum, see the reference for more details. + +} +\value{ + +\item{refInd }{ The index of the reference spectrum found by the algorithm} +\item{orderSpec }{ A sorted array of the spectra by their goodness values} + +} +\references{ +Vu TN, Valkenborg D, Smets K, Verwaest KA, Dommisse R, Lemie`re F, Verschoren A, Goethals B, Laukens K. (2011) An integrated workflow for robust alignment and simplified quantitative analysis of NMR spectrometry data. BMC Bioinformatics. 2011 Oct 20;12:405. +} +\author{ +Trung Nghia VU +} + +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + +\keyword{ reference } + diff --git a/man/findSegPeakList.Rd b/man/findSegPeakList.Rd new file mode 100644 index 0000000..c559806 --- /dev/null +++ b/man/findSegPeakList.Rd @@ -0,0 +1,47 @@ +\name{findSegPeakList} +\alias{findSegPeakList} + +\title{ +Selecting the peaks in a segment +} +\description{ +This function is to find out which peaks belonging to a segment which ranges from startP to endP +} +\usage{ +findSegPeakList(peakList, + startP, + endP) +} + +\arguments{ + \item{peakList}{ +The peak lists of the spectra. +} + \item{startP}{ +The starting point of the segment. +} + \item{endP}{ +The ending point of the segment. +} +} +\details{ +This function is to find out which peaks belonging to a segment which ranges from startP to endP +} +\value{ +The list of peaks in the segment. +} + +\author{ +Trung Nghia VU +} + +\seealso{ +\code{\link{dohClusterCustommedSegments}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ segment } +\keyword{ peak list } diff --git a/man/findShiftStepFFT.Rd b/man/findShiftStepFFT.Rd new file mode 100644 index 0000000..0138611 --- /dev/null +++ b/man/findShiftStepFFT.Rd @@ -0,0 +1,48 @@ +\name{findShiftStepFFT} +\alias{findShiftStepFFT} + +\title{ +Finding the shift-step by using Fast Fourier Transform cross-correlation +} +\description{ +This function uses Fast Fourier Transform cross-correlation to find out the shift step between two spectra. +} +\usage{ +findShiftStepFFT(refSpec, + tarSpec, + maxShift = 0) +} + +\arguments{ + \item{refSpec}{ +The reference spectrum. +} + \item{tarSpec}{ +The target spectrum which needs to be aligned. +} + \item{maxShift}{ +The maximum number of points for a shift step. If this value is zero, the algorithm will check on the whole length of the spectra. +} +} +\details{ + Finding the shift-step by using Fast Fourier Transform cross-correlation +} +\value{ +\item{corValue }{The best correlation value} +\item{stepAdj }{ The shift step found by the algorithm} +} +\author{ +Trung Nghia VU +} + +\seealso{ + \code{\link{hClustAlign}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ FFT } +\keyword{ spectrum shift } +\keyword{ cross-correlation } diff --git a/man/hClustAlign.Rd b/man/hClustAlign.Rd new file mode 100644 index 0000000..7728c05 --- /dev/null +++ b/man/hClustAlign.Rd @@ -0,0 +1,77 @@ +\name{hClustAlign} +\alias{hClustAlign} + +\title{ +CluPA function for two spectra. +} +\description{ +This function implements the idea of the CluPA algorithm to align the target spectrum against the reference spectrum. +} +\usage{ +hClustAlign(refSpec, + tarSpec, + peakList, + peakLabel, + startP, + endP, + distanceMethod = "average", + maxShift = 0, + acceptLostPeak = FALSE) +} + +\arguments{ + \item{refSpec}{ +The reference spectrum. +} + \item{tarSpec}{ +The target spectrum. +} + \item{peakList}{ +List of peaks of the both reference and target spectra +} + \item{peakLabel}{ +The list of the labels of the peaks +} + \item{startP}{ +The starting point of the segment. +} + \item{endP}{ +The ending point of the segment. +} + \item{distanceMethod}{ +The distance method for the hierarchial clustering algorithm. +} + \item{maxShift}{ +The maximum number of points for a shift step. +} + \item{acceptLostPeak}{ +This is an option for users, TRUE is the default value. If the users believe that all the peaks in the peak list are true positive, change it to FALSE. +} +} +\details{ + This function implements the idea of the CluPA algorithm to align the target spectrum against the reference spectrum. +} +\value{ + +\item{tarSpec }{The target spectrum after alignment} +\item{peakList }{The peak list after alignment} + +} +\references{ + Vu TN, Valkenborg D, Smets K, Verwaest KA, Dommisse R, Lemie`re F, Verschoren A, Goethals B, Laukens K. (2011) An integrated workflow for robust alignment and simplified quantitative analysis of NMR spectrometry data. BMC Bioinformatics. 2011 Oct 20;12:405. +} +\author{ + Trung Nghia VU +} + +\seealso{ + \code{\link{dohCluster}} +} +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + + +\keyword{ CluPA } +\keyword{ Alignment } + diff --git a/man/returnLocalMaxima.Rd b/man/returnLocalMaxima.Rd new file mode 100644 index 0000000..7400fb7 --- /dev/null +++ b/man/returnLocalMaxima.Rd @@ -0,0 +1,35 @@ +\name{returnLocalMaxima} +\alias{returnLocalMaxima} + +\title{ +Local maximum detection +} +\description{ +Find and return local maximum of a single spectrum. +} +\usage{ +returnLocalMaxima(spectrum) +} + +\arguments{ + \item{spectrum}{ +A spectral sample in the vector format. +} +} +\details{ +Find and return local maximum of a single spectrum. +} +\value{ + +\item{locMax }{ Locations of the found local maximum peaks} +\item{pkMax }{ Intensities of the found local maxumum peaks} + +} +\author{ +Trung Nghia VU +} + +\examples{ cat("\n Please see more examples in the vignettes file.") + +} + diff --git a/man/speaq-package.Rd b/man/speaq-package.Rd new file mode 100644 index 0000000..cd567e6 --- /dev/null +++ b/man/speaq-package.Rd @@ -0,0 +1,34 @@ +\name{speaq-package} +\alias{speaq-package} +\alias{speaq} +\docType{package} +\title{ +An R-package for NMR spectrum alignment and quantitation +} +\description{ +Integrated NMR spectrum alignment and quantitation based on Hierarchial Clustering Based Peak Alignment (CluPA)} +\details{ +\tabular{ll}{ +Package: \tab speaq\cr +Type: \tab Package\cr +Version: \tab 1.2.0\cr +Date: \tab 2015-05-01\cr +License: \tab Apache License 2.0\cr +LazyLoad: \tab yes\cr +} + + +} +\author{ +Trung Nghia VU, Kris Laukens and Dirk Valkenborg + +Maintainer: Trung Nghia VU + +} +\references{ +Vu TN, Valkenborg D, Smets K, Verwaest KA, Dommisse R, Lemie`re F, Verschoren A, Goethals B, Laukens K. (2011) An integrated workflow for robust alignment and simplified quantitative analysis of NMR spectrometry data. BMC Bioinformatics. 2011 Oct 20;12:405. +} + +\keyword{ package } + + diff --git a/vignettes/speaq.pdf b/vignettes/speaq.pdf new file mode 100644 index 0000000..15d4943 Binary files /dev/null and b/vignettes/speaq.pdf differ