require(Biobase)

setClass("ACME",
         contains="ExpressionSet")

setClass("ACMECalc",
         representation(windowsize="integer",
                        threshold="numeric"),
         prototype=list(windowsize=integer(),
           threshold=numeric()),
         contains="ACME")

setMethod("initialize",signature(.Object="ACME"),
          function(.Object,
                   Chromosome,
                   Position,
                   featureData=as(data.frame(Chromosome=Chromosome,Position=Position),"AnnotatedDataFrame"),
                   ...) {
            print('ACMEInit')
            print(match.call())
            if (missing(featureData)) {
              if (missing(Chromosome) || missing(Position)) {
                stop("One of featureData or Chromosome and Position must be specified")
              }
              featureData=as(data.frame(Chromosome=Chromosome,Position=Position),"AnnotatedDataFrame")
            }
            .Object <- callNextMethod(.Object,
                                      featureData=featureData,
                           ...)
            .Object <- .Object[order(pData(featureData(.Object))$Chromosome,pData(featureData(.Object))$Position),]
            return(.Object)
          })

setMethod("initialize",signature(.Object="ACMECalc"),
          function(.Object,
                   Chromosome,
                   Position,
                   featureData=as(data.frame(Chromosome=Chromosome,Position=Position),"AnnotatedDataFrame"),
                   windowsize,
                   threshold,
                   ...) {
            print("ACMECalcInit")
            print(match.call())
            .Object <- callNextMethod(.Object,featureData=featureData,...)
            .Object@windowsize=as.integer(windowsize)
            .Object@threshold=threshold
            return(.Object)
          })

###########
## Test things
###########

chrom = c(1,2,3,4)
position=c(5,6,7,8)
exp1=matrix(1:16,nr=4)
acme=new("ACME",Chromosome=chrom,Position=position,exprs=exp1)
acmec=new("ACMECalc",Chromosome=chrom,Position=position,windowsize=1000,threshold=100,exprs=exp1)
