### 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(tximeta)
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("stats", "as.formula", "model.matrix")
importFrom("stats", "binom.test")
importFrom('stats', 'fisher.test')
importFrom("utils", "read.table", "setTxtProgressBar", "txtProgressBar", "untar","file_test", "capture.output")
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("edgeR", "calcNormFactors")
importFrom("futile.logger","flog.threshold")
importFrom('grid', 'plotViewport')
importFrom('grid', 'grid.draw')
importFrom('grid', 'popViewport')
importFrom('limma', 'topTable')
importFrom('BiocGenerics', 'start','end')
importFrom('RCurl','url.exists')

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

# tidyverse
importFrom("dplyr","left_join")
importFrom("dplyr","select")
importFrom("dplyr","group_by")
importFrom("dplyr","summarise_all")
importFrom("dplyr","filter")
importFrom("dplyr","summarise")
importFrom("dplyr", "n_distinct", "as_tibble", "mutate", "any_of", "distinct")
importFrom("tibble", "rownames_to_column")
importFrom("stringr","str_c", "str_split", "str_replace_na", "str_remove")
importFrom("magrittr","%>%")
importFrom('readr', 'read_tsv', 'read_csv', 'fwf_empty','read_fwf','cols_only','col_character','col_integer','col_double', 'cols')


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

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

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

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

# Sequence analysis
#export('CDSSet')
#export('getCDS')
export('extractSequence')
export('analyzeORF')
export('addORFfromGTF')
export('analyzeNovelIsoformORF')

# incooperation of external preditions
export('analyzeCPAT')
export('analyzeCPC2')
export('analyzePFAM')
export('analyzeSignalP')
export('analyzeNetSurfP2')
export('analyzeIUPred2A')

# 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('extractGeneExpression')
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)
