useDynLib(Biostrings)

import(methods)
importFrom(utils, data, packageVersion)
importFrom(grDevices, rgb)
importFrom(graphics, axis, legend, lines, par, plot.new, plot.window, title)
importFrom(stats, chisq.test, complete.cases, diffinv, pchisq, setNames)

importFrom(crayon, make_style, black)

import(BiocGenerics)
import(S4Vectors)
import(IRanges)
import(XVector)


### ==========================================================================
### BASIC CONTAINERS
### --------------------------------------------------------------------------
###   IUPAC_CODE_MAP.R
###   AMINO_ACID_CODE.R
###   GENETIC_CODE.R
###   XStringCodec-class.R
###   seqtype.R
###   XString-class.R
###   XStringSet-class.R
###   XStringSet-comparison.R
###   XStringViews-class.R
###   MaskedXString-class.R
###   XStringSetList-class.R
###   xscat.R

exportClasses(
    XString, BString, DNAString, RNAString, AAString,
    XStringSet, BStringSet, DNAStringSet, RNAStringSet, AAStringSet,
    XStringViews,
    MaskedXString,
    MaskedBString, MaskedDNAString, MaskedRNAString, MaskedAAString,
    XStringSetList,
    BStringSetList, DNAStringSetList, RNAStringSetList, AAStringSetList
)

export(
    ## IUPAC_CODE_MAP.R + AMINO_ACID_CODE.R + GENETIC_CODE.R:
    IUPAC_CODE_MAP, mergeIUPACLetters,
    AMINO_ACID_CODE, AA_ALPHABET, AA_STANDARD, AA_PROTEINOGENIC,
    GENETIC_CODE, RNA_GENETIC_CODE,
    GENETIC_CODE_TABLE, getGeneticCode,

    ## XStringCodec-class.R:
    DNA_BASES, RNA_BASES, DNA_ALPHABET, RNA_ALPHABET,

    ## seqtype.R:
    seqtype, "seqtype<-", get_seqtype_conversion_lookup, alphabet, xscodes,

    ## XString-class.R:
    extract_character_from_XString_by_positions,
    extract_character_from_XString_by_ranges,
    make_XString_from_string,
    BString, DNAString, RNAString, AAString,

    ## XStringSet-class.R:
    make_XStringSet_from_strings,
    BStringSet, DNAStringSet, RNAStringSet, AAStringSet,

    ## MaskedXString-class.R:
    unmasked,

    ## XStringSetList-class.R:
    BStringSetList, DNAStringSetList, RNAStringSetList, AAStringSetList,

    ## xscat.R:
    xscat
)

exportMethods(
    length,
    nchar, width,
    seqtype, "seqtype<-",
    updateObject,
    names, "names<-", "[", "[[",
    show, showAsCell,
    relistToClass,
    union, intersect, setdiff, setequal,
    "%in%", match,
    pcompare, "==", "!=", match,
    coerce, as.character, unlist, as.matrix, as.list, toString, toComplex,
    as.data.frame,
    windows, subseq, threebands, "subseq<-", collapse, gaps,
    Views,
    unmasked, maskedwidth, maskedratio, masks, "masks<-"
)


### ==========================================================================
### UTILITIES
### --------------------------------------------------------------------------
###   XStringSet-io.R
###   letter.R
###   getSeq.R
###   letterFrequency.R
###   dinucleotideFrequencyTest.R
###   chartr.R
###   reverse.R
###   translate.R
###   toComplex.R
###   replaceAt.R
###   replaceLetterAt.R
###   injectHardMask.R
###   padAndClip.R
###   strsplit-methods.R
###   misc.R

export(
    ## XStringSet-io.R:
    readBStringSet, readDNAStringSet, readRNAStringSet, readAAStringSet,
    fasta.index, fasta.seqlengths, fastq.seqlengths, fastq.geometry,
    writeXStringSet,
    saveXStringSet,

    ## letter.R:
    letter,

    ## getSeq.R:
    getSeq,

    ## letterFrequency.R:
    letterFrequency,
    letterFrequencyInSlidingView,
    alphabetFrequency, hasOnlyBaseLetters, uniqueLetters,
    consensusMatrix, consensusString,
    mkAllStrings,
    oligonucleotideFrequency,
    dinucleotideFrequency, trinucleotideFrequency,
    nucleotideFrequencyAt,
    oligonucleotideTransitions,
    twoWayAlphabetFrequency,

    ## chartr.R:
    replaceAmbiguities,

    ## dinucleotideFrequencyTest.R
    dinucleotideFrequencyTest,

    ## reverseComplement.R:
    complement, reverseComplement,

    ## translate.R:
    translate, codons,

    ## toComplex.R:
    toComplex,

    ## replaceAt.R:
    extractAt, replaceAt,

    ## replaceLetterAt.R:
    replaceLetterAt, .inplaceReplaceLetterAt,

    ## injectHardMask.R:
    injectHardMask,

    ## padAndClip.R:
    padAndClip, stackStrings,

    ## strsplit-methods.R:
    strsplit,

    ## misc.R:
    N50
)

exportMethods(
    length, names, "[", "[[", rep,
    show,
    "==", "!=", duplicated, is.unsorted, order, sort, rank,
    coerce, as.character, as.matrix, as.list, toString, toComplex,
    letter,
    substr, substring,
    letterFrequency,
    letterFrequencyInSlidingView,
    alphabetFrequency, hasOnlyBaseLetters, uniqueLetters,
    consensusMatrix, consensusString,
    oligonucleotideFrequency,
    nucleotideFrequencyAt,
    dinucleotideFrequencyTest,
    chartr,
    reverse, complement, reverseComplement,
    codons, translate,
    extractAt, replaceAt,
    replaceLetterAt,
    injectHardMask,
    strsplit, unstrsplit
)


### ==========================================================================
### STRING MATCHING
### --------------------------------------------------------------------------
###   SparseList-class.R
###   MIndex-class.R
###   lowlevel-matching.R
###   match-utils.R
###   matchPattern.R
###   matchLRPatterns.R
###   trimLRPatterns.R
###   matchProbePair.R
###   matchPWM.R
###   findPalindromes.R
###   PDict-class.R
###   matchPDict.R

exportClasses(
    #SparseList,
    MIndex, ByPos_MIndex,
    PreprocessedTB, Twobit, ACtree2,
    PDict3Parts,
    PDict, TB_PDict, MTB_PDict, Expanded_TB_PDict
)

export(
    ## MIndex-class.R
    width0, startIndex, endIndex,
    extractAllMatches,

    ## lowlevel-matching.R
    neditStartingAt, neditEndingAt, neditAt,
    isMatchingStartingAt, isMatchingEndingAt, isMatchingAt,
    which.isMatchingStartingAt, which.isMatchingEndingAt, which.isMatchingAt,
    hasLetterAt,

    ## match-utils.R
    mismatch, nmatch, nmismatch,

    ## matchPattern.R
    gregexpr2, matchPattern, countPattern, vmatchPattern, vcountPattern,

    ## maskMotif.R
    maskMotif, mask,

    ## matchLRPatterns.R
    matchLRPatterns,

    ## trimLRPatterns.R
    trimLRPatterns,

    ## matchProbePair.R
    matchProbePair,

    ## matchPWM.R
    maxWeights, minWeights, maxScore, minScore, unitScale,
    PWM, PWMscoreStartingAt, matchPWM, countPWM,

    ## findPalindromes.R
    findPalindromes, palindromeArmLength,
    palindromeLeftArm, palindromeRightArm,

    ## PDict-class.R + matchPDict.R
    tb, tb.width, nnodes, hasAllFlinks, computeAllFlinks,
    patternFrequency, PDict,
    matchPDict, countPDict, whichPDict,
    vmatchPDict, vcountPDict, vwhichPDict
)

exportMethods(
    initialize,
    length, names, "names<-", show, "[[",
    startIndex, endIndex, unlist,
    neditStartingAt, neditEndingAt,
    isMatchingStartingAt, isMatchingEndingAt,
    mismatch, nmatch, nmismatch,
    coverage,
    matchPattern, countPattern, vcountPattern,
    maskMotif,
    matchLRPatterns, trimLRPatterns,
    matchProbePair,
    maxWeights, minWeights, maxScore, minScore,
    PWM, matchPWM, countPWM,
    findPalindromes,
    palindromeArmLength, palindromeLeftArm, palindromeRightArm,

    tb, tb.width, nnodes, hasAllFlinks, computeAllFlinks,
    head, tail,
    patternFrequency, PDict,
    matchPDict, countPDict, whichPDict,
    vmatchPDict, vcountPDict, vwhichPDict
)


### ==========================================================================
### STRING ALIGNMENT
### --------------------------------------------------------------------------
###   XStringPartialMatches-class.R
###   XStringQuality-class.R
###   QualityScaledXStringSet.R
###   InDel-class.R
###   AlignedXStringSet-class.R
###   PairwiseAlignments-class.R
###   PairwiseAlignmentsSingleSubject-class.R
###   PairwiseAlignments-io.R
###   align-utils.R
###   pmatchPattern.R
###   pairwiseAlignment.R
###   stringDist.R
###   needwunsQS.R
###   MultipleAlignment.R

exportClasses(
    XStringPartialMatches,
    XStringQuality, PhredQuality, SolexaQuality, IlluminaQuality,
    QualityScaledXStringSet,
    QualityScaledBStringSet, QualityScaledDNAStringSet,
    QualityScaledRNAStringSet, QualityScaledAAStringSet,
    InDel,
    AlignedXStringSet0, AlignedXStringSet, QualityAlignedXStringSet,
    PairwiseAlignments,
    PairwiseAlignmentsSingleSubject,
    PairwiseAlignmentsSingleSubjectSummary,
    MultipleAlignment,
    DNAMultipleAlignment, RNAMultipleAlignment, AAMultipleAlignment
)

export(
    ## XStringPartialMatches-class.R:
    subpatterns, pattern,

    ## XStringQuality-class.R:
    PhredQuality, SolexaQuality, IlluminaQuality,
    encoding,

    ## QualityScaledXStringSet.R:
    quality,
    QualityScaledBStringSet, QualityScaledDNAStringSet,
    QualityScaledRNAStringSet, QualityScaledAAStringSet,
    readQualityScaledDNAStringSet, writeQualityScaledXStringSet,

    ## InDel-class.R:
    insertion, deletion,

    ## AlignedXStringSet-class.R:
    unaligned, aligned, indel, nindel,

    ## PairwiseAlignments-class.R:
    PairwiseAlignments, alignedPattern, alignedSubject, pid,

    ## PairwiseAlignmentsSingleSubject-class.R:
    PairwiseAlignmentsSingleSubject,

    ## PairwiseAlignments-io.R:
    writePairwiseAlignments,

    ## align-utils.R:
    nedit,
    mismatchTable, mismatchSummary,
    compareStrings,

    ## pmatchPattern.R:
    lcprefix, lcsuffix, pmatchPattern, lcsubstr,

    ## pairwiseAlignment.R:
    nucleotideSubstitutionMatrix,
    errorSubstitutionMatrices,
    qualitySubstitutionMatrices,
    pairwiseAlignment,

    ## stringDist.R:
    stringDist,

    ## MultipleAlignment.R:
    DNAMultipleAlignment,
    RNAMultipleAlignment,
    AAMultipleAlignment,
    rowmask, "rowmask<-",
    colmask, "colmask<-",
    maskGaps,
    maskednrow, maskedncol, maskeddim,
    readDNAMultipleAlignment,
    readRNAMultipleAlignment,
    readAAMultipleAlignment,
    consensusViews,
    write.phylip,
    detail,

    ## Old stuff (Deprecated or Defunct):
    needwunsQS
)

exportMethods(
    length, "[", rep,
    coerce, as.vector, as.character, as.matrix, toString,
    show, summary,
    start, end, width,
    Views,
    subpatterns, pattern,
    quality, encoding,
    insertion, deletion,
    parallel_slot_names,
    unaligned, aligned, indel, nindel,
    parallelVectorNames,
    subject, type, alignedPattern, alignedSubject, score, pid,
    PairwiseAlignments, PairwiseAlignmentsSingleSubject,
    mismatch, nmatch, nmismatch, nedit,
    mismatchTable, mismatchSummary, coverage,
    compareStrings,
    lcprefix, lcsuffix, pmatchPattern, lcsubstr,
    pairwiseAlignment, stringDist,
    nchar, names, "names<-", "[[", windows,
    consensusMatrix, consensusString,
    alphabetFrequency, as.list,

    rowmask, "rowmask<-",
    colmask, "colmask<-",
    maskGaps,
    maskednrow, maskedncol, maskeddim,
    consensusViews,

    ## Old stuff (Deprecated or Defunct):
    needwunsQS
)


### ==========================================================================
### STUFF THAT BELONGED ORIGINALLY TO OLD matchprobes PACKAGE AND IS NOW
### SUPERSEDED BY SOME NATIVE Biostrings FUNCTIONALITY
### --------------------------------------------------------------------------
###   matchprobes.R

export(
    longestConsecutive,
    matchprobes
)

