useDynLib(CNEr, .registration = TRUE)
import(BiocGenerics)

### -----------------------------------------------------------------
### Import S4 classes defined in other packages
###
importClassesFrom(methods, ANY, character, integer, missing)
importClassesFrom(S4Vectors, List, character_OR_NULL, DataFrame, Pairs)
importClassesFrom(GenomicRanges, GRanges)
importClassesFrom(Biostrings, DNAStringSet)

### -----------------------------------------------------------------
### Import S4 methods defined in other packages
###
importMethodsFrom(rtracklayer, import.bed, export.bedGraph, export.bed,
                  export.bw)
importMethodsFrom(Seqinfo, seqnames, seqlengths, seqinfo, as.data.frame,
                  genome, "genome<-", "seqlengths<-")
importMethodsFrom(GenomicRanges, reduce, "strand<-", strand, start, end,
                                 findOverlaps, coverage, grglist)
importMethodsFrom(XVector, subseq)
importMethodsFrom(DBI, dbGetQuery)
importMethodsFrom(RSQLite, dbConnect, dbDisconnect, dbWriteTable)
importMethodsFrom(methods, initialize, show)
importMethodsFrom(pwalign, compareStrings)
importMethodsFrom(S4Vectors, Rle, isConstant, runmean, elementNROWS, first,
                  showAsCell, extractROWS, mcols, "mcols<-", split, runValue,
                  as.factor, "%in%", second, "first<-", "second<-",
                  runLength)
importMethodsFrom(IRanges, slice, ranges, "ranges<-")
importMethodsFrom(GenomicAlignments, last)

### -----------------------------------------------------------------
### Import ordinary functions, variables in other packages
###
importFrom(GenomeInfoDb, Seqinfo)
importFrom(GenomicRanges, GRanges)
importFrom(GenomicAlignments, explodeCigarOps, CIGAR_OPS, explodeCigarOpLengths)
importFrom(Biostrings, DNAStringSet, DNA_BASES, fasta.seqlengths,
           readBStringSet)
importFrom(RSQLite, SQLite)
importFrom(methods, is, new, "as", "extends", "validObject")
importFrom(rtracklayer, TwoBitFile)
importFrom(readr, read_tsv)
importFrom(IRanges, IRanges, IntegerList, RleViewsList)
importFrom(S4Vectors, .Call2, queryHits, subjectHits, DataFrame,
           normalizeSingleBracketSubscript, normalizeDoubleBracketSubscript,
           isTRUEorFALSE, isSingleString, queryLength, subjectLength)
importFrom(tools, file_ext)
importFrom(parallel, mcmapply)
importFrom(utils, download.file, read.table, write.table, read.delim)
importFrom("stats", "setNames")
importFrom(reshape2, melt)
importFrom(ggplot2, ggplot, aes, aes_q, aes_string, geom_tile, theme_bw, 
    xlab, ylab, ggtitle, geom_point, scale_colour_manual, 
    scale_fill_continuous, geom_text, scale_x_continuous, scale_y_continuous,
    geom_segment, facet_wrap)
importFrom(poweRlaw, estimate_pars, estimate_xmin)
importFrom("graphics", "lines", "par", "plot", "text")
importFrom(annotate, getGOTerm)
importFrom(GO.db, GOCCANCESTOR, GOCCOFFSPRING, GOCCCHILDREN,
                  GOBPANCESTOR, GOBPOFFSPRING, GOBPCHILDREN,
                  GOMFANCESTOR, GOMFOFFSPRING, GOMFCHILDREN)
importFrom("grDevices", "jpeg", "pdf", "png", "postscript")
importFrom(R.utils, gunzip, gzip)
importFrom(KEGGREST, keggGet)

### -----------------------------------------------------------------
### Export S4 classes defined in CNEr
###
exportClasses(Axt,
              CNE,
              GRangePairs)

### -----------------------------------------------------------------
### Export S4 methods for generics not defined in CNEr
###
exportMethods(
#"[", 
 c,
  
  ## AllClasses.r
  score,
  seqnames, strand,
  
  ## GRangePairs-class.R
  first, last, second, grglist, seqinfo, unique,
  
  ## GRangePairs-methods.R
  syntenicDotplot,

  ## Axt-methods.R
  summary
)

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

export(
  ## utils.r
  reverseCigar,
  binFromCoordRange,
  binRangesFromCoordRange,
  binRestrictionString,
  readCNERangesFromSQLite,
  fetchChromSizes,

  ## Axt-class.R
  Axt,
  
  ## Axt-methods.R
  makeAxtTracks,
  
  ## subAxt-methods.R
  psubAxt,
  
  ## CNE-class.R
  CNE,
  
  ## GRangePairs-class.R
  GRangePairs,

  # IO-methods.R
  readBed,
  readAxt,
  axtInfo,
  writeAxt,
  read.rmMask.GRanges,
  saveCNEToSQLite,
  read.rmskFasta,

  ## ceScan.R
  blatCNE,

  ## WholeGenomeAlignment.R
  lastz,
  lavToPsl,
  scoringMatrix,
  axtChain,
  chainMergeSort,
  chainPreNet,
  chainNetSyntenic,
  netToAxt,
  lastal,

  ## GRB.R
  makeGRBs,
  
  ## Ancora.R
  readAncora, readAncoraIntoSQLite, makeCNEDensity, makeAncoraFiles,
  
  ## plot.R
  CNEDensity,
  
  # CNE-utils.R
  plotCNEWidth, plotCNEDistribution,
  
  # GO.R
  ## addAncestorGO,
  
  ## AssemblyStats.R
  N50, N90
)

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

exportMethods(
  ## Axt-class.R
  targetRanges, queryRanges,
  targetSeqs, querySeqs,
  symCount,
  subAxt,

  ## Axt-methods.R
  matchDistribution, fixCoordinates,
  
  # CNE-class.R
  CNE12, CNE21,
  thresholds,
  CNEMerged, CNEFinal,
  
  # GRangePairs-class.R
  swap,
  
  ## ceScan.R
  ceScan, 
  cneMerge
)
