\name{bankDensityProfile}
\alias{bankDensityProfile}

\title{Computes density profile(s) of a bank of fasta sequences}
\description{
  Computes profile(s) of user defined quantities from the begining or
  the end of sequence fragments.
  
  Profile(s) is(are) constituted of bins of equal size with the mean,
  the standard deviation and the number  of valid events for each bin.    
}
\usage{
bankDensityProfile (file, seqno=0, fun=seqSkew, fileout= NULL, nbin,
                    sizeBin, allSeq=FALSE, fromEnd=FALSE, name = "all",
                    threshold=0, strand=getStrand(),accu=FALSE,case="all")

}
%- nBinL et nBinR fused in only one variable nBins
%- flags for Strand, threshold and masked sequences must be added
%- maybe also 'usage' for other objects documented here

\arguments{
  \item{file}{Integer/scalar, File name of the bank (fasta file)}
  \item{seqno}{Integer/scalar, Sequence number (buffer number)}
  \item{strand}{Integer/scalar, Strand (forward: 0, reverse: 1)}
  \item{fun}{Function, Function to be used (for example seqSkew}
  \item{fileout}{String/scalar, If not NULL, a file to write results}
  \item{nbin}{Integer/scalar, Number of bins to be created before the origin}
  \item{sizeBin}{Integer/scalar, Size of the bins}
  \item{allSeq}{Logical/scalar, If TRUE, Imput sequence is the whole sequence, if FALSE,
    input is only the half sequence}
  \item{fromEnd}{Logical/scalar, TRUE: Origin is the end of each sequence, 
   if FALSE: Origin is the begining of each sequence }
  \item{name}{String/vector, Names of sequences in bank file, "all": uses all sequences of the bank}
  \item{threshold}{Integer/scalar, For each bin, maximum number of N tolerated in the sequence to participate 
  to the computation}
  \item{case}{String/scalar, Case of the letters taken into account ("all", "upper", "lower")}
  \item{accu}{Flag, if true, returns sum , sum of square, and count on
    demanding function; else returns, mean and standard error on mean.}
}

\value{
  a list of matrices, with the mean(s), the standard deviation(s) and the number of valid sub-fragments
  in each bin.

}

\author{Emna Marrakchi and Antoine Lucas}

\seealso{\code{\link{densityProfile}},\code{\link{bankSummary}},\code{\link{GCcontent}},\code{\link{seqSkew}}}

\keyword{utilities}

\examples{

  ## We create 2 banks
  for(i in 1:10)
  {
    s=randomSeq(n=100)
    placeString(s,seqno=0)
    writeFasta("toto_norm.fa",append=TRUE,name=i)

    s=randomSeq(prob=c(0.3,1,1,1,0)/3.3,n=100)
    placeString(s,seqno=0)
    writeFasta("toto_lowT.fa",append=TRUE,name=i)
  }


  densNorm <- bankDensityProfile("toto_norm.fa",nbin=10,sizeBin=10,allSeq=TRUE)
  densLowT <- bankDensityProfile("toto_lowT.fa",nbin=10,sizeBin=10,allSeq=TRUE)


  par(mfrow=c(1,2))
  ## Plot skew in normal bank
  plot(densNorm$skta,main="TA skew Normal bank",ylim=c(-0.8,0.3))

  ## Plot skew in low T bank
  plot(densLowT$skta,main="TA skew low T bank",ylim=c(-0.8,0.3))

  ## Show numbers
  densLowT
}