useDynLib(IRanges)

import(methods)
importFrom(utils, stack, read.table)
importFrom(stats, cov, cor, median, quantile,
           smoothEnds, runmed, "window<-", aggregate,
           setNames)

import(BiocGenerics)
import(S4Vectors)
importFrom(stats4, summary)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 classes
###

exportClasses(
    ## DataFrameList-class.R:
    DataFrameList, DFrameList,
    SimpleDataFrameList, SimpleDFrameList,
    SplitDataFrameList, SplitDFrameList,
    SimpleSplitDataFrameList, SimpleSplitDFrameList,

    ## AtomicList-class.R:
    AtomicList, SimpleAtomicList,
    LogicalList, SimpleLogicalList,
    IntegerList, SimpleIntegerList,
    NumericList, SimpleNumericList,
    ComplexList, SimpleComplexList,
    CharacterList, SimpleCharacterList,
    RawList, SimpleRawList,
    RleList, SimpleRleList,
    FactorList, SimpleFactorList,

    ## Ranges-and-RangesList-classes.R:
    Ranges, IntegerRanges, Pos,
    RangesList, SimpleRangesList,
    IntegerRangesList, SimpleIntegerRangesList,
    PosList, SimplePosList,

    ## IPosRanges-class.R:
    IPosRanges,

    ## IntegerRangesList-class.R
    IntegerRangesList, SimpleIntegerRangesList,

    ## IRanges-class.R:
    IRanges, NormalIRanges,

    ## IPos-class.R:
    IPos, UnstitchedIPos, StitchedIPos,

    ## Grouping-class.R:
    Grouping, ManyToOneGrouping, ManyToManyGrouping,
    H2LGrouping, Dups,
    GroupingRanges, GroupingIRanges,
    Partitioning, PartitioningByEnd, PartitioningByWidth, PartitioningMap,

    ## Views-class.R:
    Views,

    ## RleViews-class.R:
    RleViews,

    ## SimpleGrouping-class.R:
    SimpleGrouping,
    SimpleManyToOneGrouping,
    BaseManyToManyGrouping,
    SimpleManyToManyGrouping,

    ## IRangesList-class.R:
    IRangesList, SimpleIRangesList,
    NormalIRangesList, SimpleNormalIRangesList,

    ## IPosList-class.R:
    IPosList, SimpleIPosList,

    ## ViewsList-class.R:
    ViewsList, SimpleViewsList,

    ## RleViewsList-class.R:
    RleViewsList, SimpleRleViewsList,

    ## RangedSelection-class.R:
    RangedSelection,

    ## MaskCollection-class.R:
    MaskCollection,

    ## CompressedList-class.R:
    CompressedList,

    ## CompressedDataFrameList-class.R:
    CompressedDataFrameList, CompressedDFrameList,
    CompressedSplitDataFrameList, CompressedSplitDFrameList,

    ## CompressedAtomicList-class.R:
    CompressedAtomicList,
    CompressedLogicalList,
    CompressedIntegerList,
    CompressedNumericList,
    CompressedComplexList,
    CompressedCharacterList,
    CompressedRawList,
    CompressedRleList,
    CompressedFactorList,

    ## CompressedGrouping-class.R:
    CompressedGrouping,
    CompressedManyToOneGrouping, CompressedManyToManyGrouping,

    ## CompressedRangesList-class.R:
    CompressedRangesList, CompressedPosList,
    CompressedIntegerRangesList,
    CompressedIRangesList, CompressedNormalIRangesList, CompressedIPosList,

    ## NCList-class.R:
    NCList, NCLists,

    ## nearest-methods.R:
    IntegerRanges_OR_missing
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S3 methods
###

S3method(as.data.frame, IPosRanges)
S3method(as.data.frame, IPos)

S3method(diff, AtomicList)

S3method(summary, IPosRanges)
S3method(summary, IPos)

S3method(`window<-`, Vector)
S3method(`window<-`, vector)
S3method(`window<-`, factor)

### We also export them thru the export() directive so that (a) they can be
### called directly, (b) tab-completion on the name of the generic shows them,
### and (c) methods() doesn't asterisk them.
export(
    as.data.frame.IPosRanges,
    as.data.frame.IPos,

    diff.AtomicList,

    summary.IPosRanges,
    summary.IPos,

    "window<-.Vector",
    "window<-.vector",
    "window<-.factor"
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 methods for generics NOT defined in this package
###

exportMethods(
    ## Methods for generics defined in the base package:
    length, "length<-",
    names, "names<-",
    dim,
    dimnames, "dimnames<-",
    "[", "[<-", "[[", "[[<-",
    as.integer,
    as.character,
    as.factor,
    as.matrix,
    drop,
    min, max, range,
    diff,
    transform,
    nchar, chartr, tolower, toupper,
    sub, gsub,
    startsWith, endsWith,
    "split<-",
    "!",
    merge,
    is.na,
    by,

    ## Methods for generics defined in the methods package:
    coerce, show,
    Ops, Math, Math2, Summary, Complex,

    ## Methods for generics defined in the utils package:
    stack,

    ## Methods for generics defined in the stats package:
    mean, var, cov, cor, sd, median, quantile, mad, IQR, smoothEnds, runmed,
    "window<-",

    ## Methods for generics defined in the stats4 package:
    summary,

    ## Methods for generics defined in the BiocGenerics package:
    nrow, ncol,
    NROW, NCOL,
    rownames, "rownames<-",
    colnames, "colnames<-",
    rbind, cbind,
    unlist, relist, unsplit,
    lapply, tapply,
    as.vector, as.list, as.data.frame,
    which, which.max, which.min,
    pmax, pmin, pmax.int, pmin.int,
    match, duplicated, unique, anyDuplicated,
    is.unsorted, order,
    append,
    paste,
    table,
    union, intersect, setdiff,
    start, "start<-", end, "end<-", width, "width<-", pos,
    dims, nrows, ncols,
    updateObject,

    ## Methods for generics defined in the S4Vectors package:
    ROWNAMES, "ROWNAMES<-",
    bindROWS,
    extractROWS, replaceROWS, getListElement,
    parallel_slot_names,
    classNameForDisplay,
    from, to,
    nLnode, nRnode,
    pcompare, pcompareRecursively,
    selfmatch,
    runLength, "runValue<-",
    runsum, runmean, runwtsum, runq,
    elementNROWS, isEmpty,
    revElements,
    as.env,
    active, "active<-"
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export non-generic functions
###

export(
    multisplit,
    IRanges, solveUserSEW,
    successiveIRanges,
    slidingIRanges,
    breakInChunks,
    whichAsIRanges,
    asNormalIRanges,
    rangeComparisonCodeToLetter,
    IPos,
    NCList, NCLists,
    H2LGrouping, Dups,
    PartitioningByEnd, PartitioningByWidth, PartitioningMap,
    RangedSelection,
    IRangesList,
    RleViewsList,
    "%over%", "%within%", "%outside%",
    "%pover%", "%pwithin%", "%poutside%",
    mergeByOverlaps, findOverlapPairs,
    MaskCollection.show_frame,
    Mask,
    read.gapMask,
    read.agpMask,
    read.liftMask,
    read.rmMask,
    read.trfMask,
    ##read.chain,
    successiveViews, slidingViews,
    LogicalList, IntegerList, NumericList, ComplexList,
    CharacterList, RawList, RleList, FactorList,
    DataFrameList, SplitDataFrameList,
    ManyToOneGrouping, ManyToManyGrouping, regroup,
    heads, tails,
    selectNearest,
    INCOMPATIBLE_ARANGES_MSG, extractListFragments, equisplit
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 generics defined in IRanges, and corresponding methods
###

export(
    ## range-squeezers.R:
    ranges, rglist,

    ## Ranges-and-RangesList-classes.R:
    mid,
    isNormal, whichFirstNotNormal,

    ## Views-class.R:
    subject,
    "ranges<-",
    Views,
    trim, subviews,
    viewApply, viewMins, viewMaxs, viewSums, viewMeans,
    viewWhichMins, viewWhichMaxs, viewRangeMins, viewRangeMaxs,

    ## Grouping-class.R:
    nobj, grouplengths, members, vmembers, togroup, togrouplength,
    high2low, low2high, grouprank, togrouprank, mapOrder,

    ## Rle-class-leftovers.R:
    findRange, splitRanges,

    ## extractList.R:
    extractList,

    ## DataFrameList-class.R:
    commonColnames, "commonColnames<-",
    columnMetadata, "columnMetadata<-",

    ## IntegerRangesList-class.R:
    space,

    ## MaskCollection-class.R:
    nir_list,
    desc, "desc<-",
    maskedwidth, maskedratio,
    collapse,

    ## findOverlaps-methods.R:
    findOverlaps, countOverlaps, overlapsAny, subsetByOverlaps,
    overlapsRanges,
    poverlaps,

    ## windows-methods.R:
    windows, narrow,

    ## intra-range-methods.R:
    update_ranges,
    shift, resize, flank, promoters, terminators,
    reflect, restrict, threebands,

    ## inter-range-methods.R:
    reduce, gaps, disjoin, isDisjoint, disjointBins,

    ## reverse-methods.R:
    reverse,

    ## coverage-methods.R:
    coverage,

    ## cvg-methods.R:
    cvg,

    ## slice-methods.R:
    slice,

    ## setops-methods.R:
    punion, pintersect, psetdiff, pgap,

    ## nearest-methods.R:
    precede, follow, nearest, distance, distanceToNearest,

    ## tile-methods.R:
    tile, slidingWindows,

    ## AtomicList-utils.R:
    ifelse2
)

### Same list as above.
exportMethods(
    ranges, rglist,
    runsum, runmean, runwtsum, runq,
    mid,
    isNormal, whichFirstNotNormal,
    subject,
    "ranges<-",
    Views,
    trim, subviews,
    viewApply, viewMins, viewMaxs, viewSums, viewMeans,
    viewWhichMins, viewWhichMaxs, viewRangeMins, viewRangeMaxs,
    nobj, grouplengths, members, vmembers, togroup, togrouplength,
    high2low, low2high, grouprank, togrouprank, mapOrder,
    findRange, splitRanges,
    extractList,
    commonColnames, "commonColnames<-",
    columnMetadata, "columnMetadata<-",
    space,
    nir_list,
    desc, "desc<-",
    maskedwidth, maskedratio,
    collapse,
    findOverlaps, countOverlaps, overlapsAny, subsetByOverlaps,
    overlapsRanges,
    poverlaps,
    windows, narrow,
    update_ranges,
    shift, resize, flank, promoters, terminators,
    reflect, restrict, threebands,
    reduce, gaps, disjoin, isDisjoint, disjointBins,
    reverse,
    coverage,
    cvg,
    slice,
    punion, pintersect, psetdiff, pgap,
    precede, follow, nearest, distance, distanceToNearest,
    tile, slidingWindows,
    ifelse2
)

