### Import libraries functions
import(methods)
import(reshape2)
import(Biostrings)
import(IRanges)
import(GenomicRanges)
import(gridExtra)
import(BSgenome)
import(RColorBrewer)
import(ggplot2)
import(VennDiagram)
import(DBI)
import(tximport)
import(DRIMSeq)
import(DEXSeq)
import(limma, except=c(plotMA))

### Import compiled code
useDynLib(IsoformSwitchAnalyzeR)

### Import specific functions from other packages
importFrom("grDevices", "dev.off", "hcl", "pdf", "png")
importFrom("graphics", "lines", "plot", "text", "title")
importFrom("stats", "p.adjust", 'qnorm', "wilcox.test")
importFrom("stats", "na.omit", "p.adjust", "setNames", "wilcox.test")
importFrom("utils", "read.table", "setTxtProgressBar", "txtProgressBar", "untar","file_test")
importFrom('GenomeInfoDb','seqlevels','seqlevels<-')
importFrom('XVector','subseq')
importFrom('grid','grid.newpage')
importFrom('grid','pushViewport')
importFrom('grid','viewport')
importFrom('grid','grid.layout')
importFrom('DBI','dbGetQuery','dbDriver')
importFrom("stats", "as.formula", "model.matrix")
importFrom("edgeR", "calcNormFactors")
importFrom("stats", "prop.test")
importFrom("futile.logger","flog.threshold")
importFrom("stringr", "str_split")

importFrom('stats', 'fisher.test')
importFrom('stats', 'fisher.test')
importFrom('grid', 'plotViewport')
importFrom('grid', 'grid.draw')
importFrom('grid', 'popViewport')
importFrom('limma', 'topTable')

# plyr
importFrom('plyr', 'ddply','ldply','llply','dlply')

# tidyverse
importFrom("dplyr","left_join")
importFrom("dplyr","select")
importFrom("dplyr","group_by")
importFrom("dplyr","summarise_all")
importFrom("stringr","str_c")
importFrom("magrittr","%>%")
importFrom('readr', 'read_tsv', 'read_csv','cols_only','col_character','col_integer','col_double')


### Export functions from IsoformSwitchAnalyzeR
# Creating list
export('createSwitchAnalyzeRlist')
export('subsetSwitchAnalyzeRlist')

# Import data
export('importCufflinksFiles')
export('importGTF')
export('importIsoformExpression')
export('importRdata')
export('preFilter')

# Test isoform switches
export('isoformSwitchTestDRIMSeq')
export('isoformSwitchTestDEXSeq')

export('extractSwitchSummary')
export('extractSwitchOverlap')
export('extractTopSwitches')

# Analyze functional potential
export('CDSSet')
export('getCDS')
export('extractSequence')
export('analyzeORF')

export('analyzeCPAT')
export('analyzeCPC2')
export('analyzePFAM')
export('analyzeSignalP')
export('analyzeNetSurfP2')

# Splicing analysis
export('analyzeAlternativeSplicing')
export('analyzeIntronRetention')
export('extractSplicingSummary')
export('extractSplicingEnrichment')
export('extractSplicingEnrichmentComparison')
export('extractSplicingGenomeWide')

# Switch consequences analysis
export('analyzeSwitchConsequences')
export('extractConsequenceSummary')
export('extractConsequenceEnrichment')
export('extractConsequenceEnrichmentComparison')
export('extractConsequenceGenomeWide')
export('extractGenomeWideAnalysis') # for backward compatability

# Plotting
export('switchPlotTranscript')

export('switchPlotGeneExp')
export('switchPlotIsoExp')
export('switchPlotIsoUsage')

export('switchPlot')
export('switchPlotTopSwitches')

# High level function
export('isoformSwitchAnalysisPart1')
export('isoformSwitchAnalysisPart2')
export('isoformSwitchAnalysisCombined')

# other tools
export('extractExpressionMatrix')
export('isoformToGeneExp')
export('isoformToIsoformFraction')

### Export classes
exportClasses("switchAnalyzeRlist")

### Overload generic functions to work with my classes
S3method(dim,switchAnalyzeRlist)
S3method(nrow,switchAnalyzeRlist)
S3method(ncol,switchAnalyzeRlist)
S3method(head,switchAnalyzeRlist)
S3method(tail,switchAnalyzeRlist)
S3method(show,switchAnalyzeRlist)

S3method(summary,switchAnalyzeRlist)
