### Import libraries functions
import(methods)
import(reshape2)
import(Biostrings, except=c(pairwiseAlignment, alignedPattern, alignedSubject))
import(IRanges)
import(GenomicRanges)
import(gridExtra)
import(BSgenome)
import(RColorBrewer)
import(ggplot2)
import(VennDiagram)
import(DBI)
import(tximport)
import(tximeta)
import(DEXSeq)
import(satuRn)
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','do.call')
importFrom('RCurl','url.exists')
importFrom("sva", "num.sv", 'sva')
importFrom("SummarizedExperiment", "SummarizedExperiment", "assay", "rowData")
importFrom("BiocParallel", "bpparam")
importFrom("S4Vectors", "metadata", "queryHits", "subjectHits")
importFrom("pwalign", "pairwiseAlignment", "alignedPattern", "alignedSubject")

# 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", "n_distinct", "as_tibble", "mutate", "any_of", "distinct", "case_when")
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')
importFrom("tibble","tibble")
importFrom("tidyr","pivot_longer")

# Other
importFrom("pfamAnalyzeR", "augment_pfam")
importFrom("pfamAnalyzeR", "analyse_pfam_isotypes")

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

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

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

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

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

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

# 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

export('extractSubCellShifts')

# 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)
