useDynLib(IRanges)

import(methods)
importFrom(utils, head, read.table, tail, stack, relist)
importFrom(stats, start, end, var, cov, cor, sd, median, quantile, mad,
           IQR, smoothEnds, runmed, window, "window<-", aggregate,
           na.omit, na.exclude, complete.cases)

import(BiocGenerics)
importFrom(stats4, summary, update)
importFrom(parallel, mclapply, mcmapply)

exportClasses(
    AsIs, xtabs,
    characterORNULL, functionORNULL,
    Annotated,
    DataTable, DataTableORNULL,
    Vector,
    List, SimpleList, CompressedList,
    Ranges, RangesORmissing,
    IRanges, NormalIRanges,
    IntervalTree,
    Grouping, H2LGrouping, Dups,
    Partitioning, PartitioningByEnd, PartitioningByWidth,
    SharedVector, SharedVector_Pool,
    SharedRaw, SharedRaw_Pool,
    SharedInteger, SharedDouble,
    Views,
    XVector, XRaw, XInteger, XDouble,
    GroupedIRanges, XVectorList, XRawList,
    XIntegerViews,
    Rle, 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,
    RangesList, SimpleRangesList,
    IRangesList, CompressedIRangesList, SimpleIRangesList,
    NormalIRangesList, CompressedNormalIRangesList, SimpleNormalIRangesList,
    GappedRanges,
    ViewsList, SimpleViewsList,
    RleViewsList, SimpleRleViewsList,
    DataFrame,
    DataFrameList, SimpleDataFrameList,
    SplitDataFrameList, CompressedSplitDataFrameList, SimpleSplitDataFrameList,
    RangedData, RangedDataList, FilterRules, RDApplyParams,
    Hits, HitsList,
    OverlapEncodings,
    RangedSelection, RangesMapping
)

export(
    ## Non-generic functions:
    setValidity2, new2,
    .Call2,
    isTRUEorFALSE, isSingleInteger, isSingleNumber, isSingleString,
    isSingleNumberOrNA, isSingleStringOrNA,
    recycleIntegerArg, recycleNumericArg,
    fold,
    safeExplode,
    strsplitAsListOfIntegerVectors,
    svn.time,
    solveUserSEW0, IRanges, solveUserSEW,
    successiveIRanges,
    breakInChunks,
    whichAsIRanges,
    asNormalIRanges,
    IntervalTree,
    H2LGrouping, Dups, PartitioningByEnd, PartitioningByWidth,
    RangedData, RangedDataList,
    RangedSelection,
    FilterRules, RDApplyParams,
    RangesList,
    IRangesList,
    RleViewsList,
    MaskCollection.show_frame,
    Mask,
    read.gapMask,
    read.agpMask,
    read.liftMask,
    read.rmMask,
    read.trfMask,
    ##read.chain,
    SharedVector.compare,
    SharedVector.copy,
    SharedRaw,
    SharedRaw.readInts, SharedRaw.writeInts,
    SharedRaw.read, SharedRaw.write,
    SharedRaw.readComplexes,
    #SharedInteger, SharedInteger.read, SharedInteger.write,
    #SharedDouble, SharedDouble.read, SharedDouble.write,
    XRaw, XInteger, XDouble, XNumeric,
    XVectorList,
    unlist_list_of_XVectorList, unsplit_list_of_XVectorList,
    newViews, successiveViews,
    SimpleList, DataFrame,
    LogicalList, IntegerList, NumericList, ComplexList,
    CharacterList, RawList, RleList,
    DataFrameList, SplitDataFrameList,

    ## Generic endomorphism functions
    endoapply,
    mendoapply,

    ## Vector API:
    splitAsListReturnedClass, splitAsList,
    metadata, "metadata<-",
    elementMetadata, "elementMetadata<-",
    mcols, "mcols<-",
    values, "values<-",
    isConstant,
    isEmpty,
    seqselect, "seqselect<-",
    rename,

    ## Non-generic and generic functions in the List API:
    elementType, elementLengths,
    seqapply, mseqapply, tseqapply, seqsplit, seqby, multisplit,
    revElements,
    
    ## Generic functions in the Ranges API:
    width,
    mid,
    "start<-",
    "width<-",
    "end<-",
    isNormal, whichFirstNotNormal,
    compare, rangeComparisonCodeToLetter,
    shift, narrow, flank, reflect, resize, restrict, threebands,
    reduce, gaps, disjoin, isDisjoint, disjointBins,
    punion, pintersect, psetdiff, pgap,
    findOverlaps, countOverlaps, subsetByOverlaps,
    nearest, precede, follow, distance, distanceToNearest,
    
    ## Generic functions in the Rle API:
    Rle, runLength, runValue, nrun, "runLength<-", "runValue<-", shiftApply,
    findRange, findRun,

    ## Generic functions in the Grouping API:
    nobj, grouplength, members, vmembers, togroup, togrouplength, tofactor,
    high2low, low2high, grouprank, togrouprank,

    ## Generic functions in the GappedRanges API:
    ngap,

    ## Generic functions in the DataTable API:
    as.env,
    
    ## MaskCollection API
    nir_list,
    active, "active<-",
    desc, "desc<-",
    maskedwidth, maskedratio,
    collapse,
    ranges, "ranges<-",
    subseq, "subseq<-",

    ## Views API
    subject, Views, subviews, trim,
    slice,
    runmean, runsum, runwtsum, runq,
    viewApply, viewMins, viewMaxs, viewSums, viewMeans,
    viewWhichMins, viewWhichMaxs, viewRangeMins, viewRangeMaxs,

    ## rdapply API
    rangedData, "rangedData<-", applyFun, "applyFun<-", applyParams,
    "applyParams<-", simplify, "simplify<-",
    ##excludePattern, "excludePattern<-",
    filterRules, "filterRules<-",
    evalSeparately, subsetByFilter, params,
    reducerFun, "reducerFun<-", reducerParams, "reducerParams<-",
    iteratorFun, "iteratorFun<-",
    rdapply,

    ## RangedData API
    universe, "universe<-", space, score, "score<-",
    columnMetadata, "columnMetadata<-",

    ## Hits API
    matchMatrix, queryHits, subjectHits, remapHits,
    hits, map, pmap,

    ## OverlapEncodings
    Loffset, Roffset, encoding, flippedQuery,
    Lencoding, Rencoding, Lngap, Rngap,
    encodeOverlaps1, RangesList_encodeOverlaps, encodeOverlaps,

    ## Other generic functions:
    xvcopy, compact,
    reverse,

    ## coverage.R:
    coverage
)

exportMethods(
    ## Methods for generics defined in the base packages:
    "[", "[<-", "[[", "[[<-", "$",
    "==", "!=", "<=", ">=", "<", ">",
    Ops, Math, Math2, Summary, Complex,
    coerce,
    show,
    summary,
    length, "length<-",
    names, "names<-",
    nrow, NROW, ncol, NCOL, dim,
    rownames, colnames, dimnames,
    "rownames<-", "colnames<-", "dimnames<-",
    sort, rank, is.unsorted,
    rev,
    rep,
    head, tail,
    drop,
    start, end,
    min, max, range, which.max, which.min,
    diff,
    mean, var, cov, cor, sd, median, quantile, mad, IQR, smoothEnds, runmed,
    subset, window, "window<-", aggregate,
    nchar, substr, substring, chartr, tolower, toupper, sub, gsub,
    levels, "levels<-", nlevels,
    as.vector,
    as.logical, as.integer, as.numeric, as.complex, as.character, as.raw,
    as.factor,
    as.matrix,
    as.data.frame,
    as.list,
    as.table,
    toString,
    unlist, stack, mstack, "split<-", unsplit,
    update,
    append,
    "!", which,
    ifelse,
    c,
    merge,
    split, splitRanges,
    with, within,
    t,
    is.na, na.omit, na.exclude, complete.cases,
    "%in%", by, match,

    ## Methods for generics defined in the BiocGenerics package:
    cbind, rbind,
    duplicated,
    eval,
    lapply, sapply,
    mapply,
    pmax, pmin, pmax.int, pmin.int,
    order,
    paste,
    Reduce, Filter, Find, Map, Position,
    rep.int,
    table,
    tapply,
    union, intersect, setdiff,
    unique,
    xtabs,
    updateObject,

    ## Methods for generics defined in this package:
    endoapply,
    mendoapply,
    
    splitAsListReturnedClass, relist,
    metadata, "metadata<-",
    elementMetadata, "elementMetadata<-",
    mcols, "mcols<-",
    isConstant,
    isEmpty,
    seqselect, "seqselect<-",
    elementType, elementLengths,
    revElements,

    width,
    mid,
    "start<-",
    "width<-",
    "end<-",
    isNormal, whichFirstNotNormal,
    compare,
    shift, narrow, flank, reflect, resize, restrict, threebands,
    range, reduce, gaps, disjoin, isDisjoint, disjointBins,
    punion, pintersect, psetdiff, pgap,
    findOverlaps, countOverlaps, subsetByOverlaps,
    nearest, precede, follow, distance, distanceToNearest,

    Rle, runLength, runValue, nrun, "runLength<-", "runValue<-", shiftApply,
    findRange, findRun,

    nobj, grouplength, members, vmembers, togroup, togrouplength,
    high2low, low2high, grouprank, togrouprank,

    ngap,

    as.env,

    nir_list,
    active, "active<-",
    desc, "desc<-",
    maskedwidth, maskedratio,
    collapse,
    ranges, "ranges<-",
    subseq, "subseq<-",
    subject, Views, subviews, trim,
    slice,
    values, "values<-",
    columnMetadata, "columnMetadata<-",
    runmean, runsum, runwtsum, runq,
    viewApply, viewMins, viewMaxs, viewSums, viewMeans,
    viewWhichMins, viewWhichMaxs, viewRangeMins, viewRangeMaxs,
    rangedData, "rangedData<-", applyFun, "applyFun<-", applyParams,
    "applyParams<-", simplify, "simplify<-",
    ##excludePattern, "excludePattern<-",
    filterRules, "filterRules<-",
    evalSeparately, subsetByFilter,
    reducerFun, "reducerFun<-", reducerParams, "reducerParams<-",
    iteratorFun, "iteratorFun<-",
    rdapply,
    universe, "universe<-", space, score, "score<-",
    queryHits, subjectHits, queryLength, subjectLength,
    countQueryHits, countSubjectHits,
    Loffset, Roffset, encoding, flippedQuery,
    Lencoding, Rencoding, Lngap, Rngap, encodeOverlaps,
    xvcopy, compact,
    reverse,
    coverage,
    expand
)

