useDynLib(IRanges)

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

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


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

exportClasses(
    functionORNULL,
    CompressedList,
    Ranges, RangesORmissing,
    IRanges, NormalIRanges,
    NCList, NCLists,
    IntervalTree, IntervalForest, 
    Grouping, ManyToOneGrouping,
    H2LGrouping, Dups,
    Partitioning, PartitioningByEnd, PartitioningByWidth, PartitioningMap,
    Views,
    RleViews,
    MaskCollection,
    AtomicList, CompressedAtomicList, SimpleAtomicList,
    LogicalList, CompressedLogicalList, SimpleLogicalList,
    IntegerList, CompressedIntegerList, SimpleIntegerList,
    NumericList, CompressedNumericList, SimpleNumericList,
    ComplexList, CompressedComplexList, SimpleComplexList,
    CharacterList, CompressedCharacterList, SimpleCharacterList,
    RawList, CompressedRawList, SimpleRawList,
    RleList, CompressedRleList, SimpleRleList,
    FactorList, CompressedFactorList, SimpleFactorList,
    RangesList, SimpleRangesList,
    IRangesList, CompressedIRangesList, SimpleIRangesList,
    NormalIRangesList, CompressedNormalIRangesList, SimpleNormalIRangesList,
    GappedRanges,
    ViewsList, SimpleViewsList,
    RleViewsList, SimpleRleViewsList,
    DataFrameList, SimpleDataFrameList,
    SplitDataFrameList, CompressedSplitDataFrameList, SimpleSplitDataFrameList,
    RangedData, RangedDataList, RDApplyParams,
    HitsList, CompressedHitsList, 
    RangedSelection
)


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

S3method(as.data.frame, GappedRanges)
S3method(as.data.frame, Hits)
S3method(as.data.frame, RangedData)
S3method(as.data.frame, Ranges)

S3method(as.list, Vector)
S3method(as.list, CompressedNormalIRangesList)
S3method(as.list, Hits)

S3method(duplicated, Dups)
S3method(duplicated, CompressedList)
S3method(duplicated, CompressedIntegerList)

S3method(sort, List)

S3method(unique, RleList)
S3method(unique, CompressedList)

S3method(window, Rle)

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.GappedRanges,
    as.data.frame.Hits,
    as.data.frame.RangedData,
    as.data.frame.Ranges,

    as.list.Vector,
    as.list.CompressedNormalIRangesList,
    as.list.Hits,

    duplicated.Dups,
    duplicated.CompressedList,

    sort.List,

    unique.RleList,
    unique.CompressedList,

    window.Rle,

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


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 methods for generics not defined in IRanges
###

exportMethods(
    length, "length<-",
    names, "names<-",
    nrow, NROW,
    ncol, NCOL,
    dim,
    rownames, "rownames<-",
    colnames, "colnames<-",
    dimnames, "dimnames<-",
    "[", "[<-", "[[", "[[<-", "$<-",
    as.vector,
    as.integer,
    as.matrix,
    as.data.frame,
    as.list,
    as.table,
    coerce,
    c,
    show,
    "==", "<=",
    match, duplicated, unique, anyDuplicated, "%in%",
    order, sort, rank, xtfrm, is.unsorted,
    Ops, Math, Math2, Summary, Complex,
    summary,
    rev,
    rep,
    drop,
    start, "start<-", end, "end<-", width, "width<-",
    min, max, range, which.max, which.min,
    diff,
    mean, var, cov, cor, sd, median, quantile, mad, IQR, smoothEnds, runmed,
    subset, window, "window<-", transform,
    nchar, chartr, tolower, toupper, sub, gsub,
    unlist, stack, "split<-", unsplit,
    relist,
    update,
    append,
    "!", which,
    merge,
    with, within,
    t,
    is.na,
    by, 
    cbind, rbind,
    lapply,
    pmax, pmin, pmax.int, pmin.int,
    paste,
    rep.int,
    table,
    tapply,
    union, intersect, setdiff,
    updateObject,
    values, "values<-",
    classNameForDisplay,
    queryHits, subjectHits,
    queryLength, subjectLength,
    compare,
    selfmatch,
    runLength, "runValue<-",
    shiftApply,
    runsum, runmean, runwtsum, runq,
    elementLengths, isEmpty, revElements,
    endoapply, mendoapply,
    as.env,
    active, "active<-", filterRules
)


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

export(
    splitAsList,
    multisplit,
    solveUserSEW0, IRanges, solveUserSEW,
    successiveIRanges,
    breakInChunks,
    whichAsIRanges,
    asNormalIRanges,
    rangeComparisonCodeToLetter,
    NCList, NCLists,
    IntervalTree, IntervalForest, 
    H2LGrouping, Dups,
    PartitioningByEnd, PartitioningByWidth, PartitioningMap,
    RangedData, RangedDataList,
    RangedSelection,
    RDApplyParams,
    RangesList,
    IRangesList,
    RleViewsList,
    CompressedHitsList, 
    "%over%", "%within%", "%outside%",
    MaskCollection.show_frame,
    Mask,
    read.gapMask,
    read.agpMask,
    read.liftMask,
    read.rmMask,
    read.trfMask,
    ##read.chain,
    newViews, successiveViews,
    LogicalList, IntegerList, NumericList, ComplexList,
    CharacterList, RawList, RleList, FactorList, 
    DataFrameList, SplitDataFrameList
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 generics defined in IRanges + export corresponding methods
###

export(
    ## Vector-class-leftovers.R:
    showAsCell,
    mstack,

    ## Ranges-class.R:
    mid,
    isNormal, whichFirstNotNormal,

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

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

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

    ## extractList.R:
    relistToClass,
    extractList,

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

    ## RangesList-class.R:
    universe, "universe<-", space,

    ## GappedRanges-class.R:
    ngap,

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

    ## RangedData-class.R:
    score, "score<-",

    ## RangedData-utils.R:
    rdapply,

    ## RDApplyParams-class.R:
    rangedData, "rangedData<-",
    applyFun, "applyFun<-",
    applyParams, "applyParams<-",
    ##excludePattern, "excludePattern<-",
    "filterRules<-",
    simplify, "simplify<-",
    reducerFun, "reducerFun<-",
    reducerParams, "reducerParams<-",
    iteratorFun, "iteratorFun<-",

    ## mapCoords.R:
    mapCoords, pmapCoords,

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

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

    ## reverse-methods.R:
    reverse,

    ## coverage-methods.R:
    coverage,

    ## slice-methods.R:
    slice,

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

    ## findOverlaps-methods.R:
    findOverlaps, countOverlaps, overlapsAny, subsetByOverlaps, mergeByOverlaps,

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

    ## expand-methods.R:
    expand,

    ## tile-methods.R:
    tile
)

### Exactly the same list as above.
exportMethods(
    runsum, runmean, runwtsum, runq,
    showAsCell,
    mstack,
    mid,
    isNormal, whichFirstNotNormal,
    subject,
    ranges, "ranges<-",
    Views,
    trim, subviews,
    viewApply, viewMins, viewMaxs, viewSums, viewMeans,
    viewWhichMins, viewWhichMaxs, viewRangeMins, viewRangeMaxs,
    nobj, grouplength, members, vmembers, togroup, togrouplength,
    high2low, low2high, grouprank, togrouprank, mapOrder,
    findRange, splitRanges,
    relistToClass,
    extractList,
    columnMetadata, "columnMetadata<-",
    universe, "universe<-", space,
    ngap,
    nir_list,
    desc, "desc<-",
    maskedwidth, maskedratio,
    collapse,
    score, "score<-",
    rdapply,
    rangedData, "rangedData<-",
    applyFun, "applyFun<-",
    applyParams, "applyParams<-",
    ##excludePattern, "excludePattern<-",
    "filterRules<-",
    simplify, "simplify<-",
    reducerFun, "reducerFun<-",
    reducerParams, "reducerParams<-",
    iteratorFun, "iteratorFun<-",
    shift, narrow, resize, flank, reflect, promoters, restrict, threebands,
    reduce, gaps, disjoin, isDisjoint, disjointBins,
    reverse,
    coverage,
    slice,
    punion, pintersect, psetdiff, pgap,
    findOverlaps, countOverlaps, overlapsAny, subsetByOverlaps,
    precede, follow, nearest, distance, distanceToNearest,
    expand,
    tile
)
