##
## Importing
##

import(methods)
import(S4Vectors)
import(IRanges)
import(GenomicRanges)
import(SummarizedExperiment)
import(DelayedArray)
import(HDF5Array)
import(BiocParallel)
import(limma)
importFrom(BiocGenerics, "anyDuplicated", "cbind", "colnames",
           "combine", "density", "intersect", "lapply", "ncol",
           "nrow", "order", "paste", "pmax", "pmin", "rbind",
           "Reduce", "rep.int", "rownames", "sapply", "setdiff",
           "strand", "strand<-", "union", "unique", "updateObject", "unstrand")
importFrom(stats, "approxfun", "fisher.test", "ppoints",
           "predict", "preplot", "qchisq",
           "qqplot", "qunif", "cov2cor",
           "setNames")
importFrom(graphics, "abline", "axis", "layout", "legend", "lines",
           "mtext", "par", "plot", "points", "polygon", "rect", "rug", "text", "hist")
import(parallel)
importFrom(locfit, "locfit", "lp")
importFrom(DelayedMatrixStats, "rowSds", "rowVars", "colMeans2", "colSums2",
           "rowSums2", "rowMeans2", "rowAlls")

importFrom(scales, "alpha")
importClassesFrom(Biobase, "AnnotatedDataFrame")
importMethodsFrom(Biobase, "annotatedDataFrameFrom",
                  "pData", "pData<-",
                  "sampleNames", "sampleNames<-")
importFrom(Biobase, "validMsg")
importMethodsFrom(Seqinfo, "seqlengths", "seqlengths<-", "seqinfo",
                  "seqinfo<-", "seqnames", "seqnames<-", "seqlevels",
                  "seqlevels<-", "sortSeqlevels")
importFrom(Seqinfo, "Seqinfo")
importFrom(gtools, "combinations")
importFrom(beachmat, initializeCpp)
importFrom(Rcpp, sourceCpp)

# NOTE: data.table has some NAMESPACE clashes with functions in Bioconductor,
#       e.g., shift(). If new ones are discovered, add them to this list.
import(data.table, except = c(shift, first, second))
importFrom(permute, "shuffleSet", "how")
importFrom(Biostrings, "DNAString", "vmatchPattern", "reverseComplement")
importFrom(utils, "read.delim", "read.table")
importFrom(BSgenome, "vmatchPattern")
importFrom(tools, "file_path_as_absolute")
importFrom(R.utils, "isGzipped", "isBzipped", "gunzip", "bunzip2")

##
## Exporting
##

exportClasses("hasGRanges",
              "BSseq",
              "BSseqTstat",
              "BSseqStat",
              "matrixOrNULL")

exportMethods("[", "show",
              "seqnames", "seqnames<-",
              "seqlevels", "seqlevels<-",
              "seqlengths", "seqlengths<-",
              "start", "start<-",
              "end", "end<-",
              "width", "width<-",
              "strand", "strand<-",
              "granges",
              "dim", "nrow", "ncol",
              "sampleNames", "sampleNames<-",
              "pData", "pData<-",
              "findOverlaps", "overlapsAny", "subsetByOverlaps",
              "combine", "updateObject")

export("BSseq", "getMeth", "getCoverage", "getBSseq", "getStats",
       "collapseBSseq", "orderBSseq", "hasBeenSmoothed", "chrSelectBSseq",
       "BSmooth", "BSmooth.tstat", "dmrFinder", "fisherTests",
       "combineList", "strandCollapse",
       "plotRegion", "plotManyRegions",
       "read.bismark", "read.bedMethyl",
       "read.modbam2bed", "read.modkit",
       "poissonGoodnessOfFit", "binomialGoodnessOfFit",
       "data.frame2GRanges", "BSseqTstat",
       "BSseqStat",
       "findLoci","estimateErrorRate",
       "getCpGs",
       "getMaxLikelihoodMatrix","getCpGMatrix")

S3method("print", "chisqGoodnessOfFit")
S3method("plot", "chisqGoodnessOfFit")
S3method("print", "summary.BSseqTstat")
S3method("summary", "BSseqTstat")
S3method("plot", "BSseqTstat")

## Fixes, to be removed

exportMethods("assays", "assayNames")

# C++ code registration
useDynLib(bsseq, .registration = TRUE, .fixes = "cxx_")
