useDynLib(xcms, .registration = TRUE)

import("methods")
importMethodsFrom("ProtGenerics", "peaks", "chromatogram", "writeMSData",
    "polarity<-", "centroided", "isCentroided", "peaks<-",
    "isolationWindowTargetMz", "quantify", "bin", "spectrapply",
    "filterFeatures", "filterMzRange", "filterRt", "filterMz", "filterMsLevel",
    "estimatePrecursorIntensity")
importClassesFrom("ProtGenerics", "Param")
importFrom("BiocGenerics", "updateObject", "fileName", "subset",
    "dirname", "dirname<-")
## import("Biobase")
importFrom("Biobase", "AnnotatedDataFrame")
importClassesFrom("Biobase", "AnnotatedDataFrame")
importMethodsFrom("Biobase", "phenoData",
                  "phenoData<-", "pData", "rowMedians", "varLabels",
                  "fvarLabels", "annotatedDataFrameFrom", "pData<-")
importFrom("IRanges", "CharacterList", "NumericList")
importClassesFrom("IRanges", "CharacterList", "NumericList")

importFrom("mzR", "peaks", "close", "openMSfile", "header")
importFrom("lattice", "levelplot", "panel.rect", "panel.levelplot",
           "level.colors", "do.breaks")
importFrom("BiocParallel", "bpparam", "SerialParam")
importMethodsFrom("BiocParallel", "bplapply", "bpmapply")

importClassesFrom("S4Vectors", "Rle", "DataFrame", "Hits")
importFrom("S4Vectors", "split", "Rle", "DataFrame", "SimpleList", "List",
           "as.matrix")
importMethodsFrom("S4Vectors", "as.matrix", "mcols", "mcols<-",
                  "extractROWS", "findMatches", "to")
importFrom("SummarizedExperiment", "SummarizedExperiment")
importFrom("SummarizedExperiment", "rowData")
importFrom("SummarizedExperiment", "rowData<-")
importFrom("SummarizedExperiment", "assay")
importFrom("MsCoreUtils", "rbindFill", "closest", "i2index", "sumi", "between",
           "maxi", "breaks_ppm", "force_sorted", "reduce")
importFrom("RColorBrewer", "brewer.pal")

importFrom("graphics", "image", "boxplot", "matplot", "rect", "axis",
           "grid", "mtext", "polygon", "box", "plot.xy", "abline",
           "barplot", "close.screen", "hist", "identify", "layout",
           "legend", "lines", "par", "plot.new", "plot.window", "points",
           "screen", "split.screen", "strwidth", "text", "title")
importFrom("grDevices", "col2rgb", "colorRampPalette", "dev.cur",
           "dev.list", "dev.off", "dev.set", "palette", "pdf", "png",
           "rainbow", "rgb", "terrain.colors", "n2mfrow", "dev.flush",
	   "dev.hold", "xy.coords")
importFrom("stats", "aov", "approx", "convolve", "cor", "deriv3",
           "dist", "fft", "fitted", "lm", "loess", "lsfit", "median",
           "na.omit", "nextn", "nls", "predict", "pt", "quantile",
           "runmed", "sd", "stepfun", "weighted.mean", "density", "approxfun",
           "rnorm", "runif", "dbeta", "resid")
importFrom("utils", "flush.console", "head", "object.size",
           "packageVersion", "read.csv", "tail", "write.csv",
           "write.table", "capture.output", "data")

importFrom("MassSpecWavelet", "peakDetectionCWT", "tuneInPeakInfo")

importFrom("data.table", "rbindlist")

## MSnbase:
importClassesFrom("MSnbase", "MSnExp", "pSet", "OnDiskMSnExp", "Chromatogram",
                  "MChromatograms", "MSpectra")
importMethodsFrom("MSnbase", "intensity", "mz", "rtime", "fileNames", "fromFile",
                  "filterFile", "filterMsLevel", "msLevel", "scanIndex",
                  "spectra", "impute", "isCentroided", "polarity", "[",
                  "clean", "featureNames", "filterAcquisitionNum", "filterMz",
                  "filterRt", "normalize", "pickPeaks", "removePeaks",
                  "removeReporters", "smooth", "trimMz", "splitByFile", "[[",
                  "spectrapply", "peaksCount", "precursorMz", "chromatogram",
                  "plot", "fData", "fData<-", "writeMSData",
                  "filterIsolationWindow", "filterIntensity",
		  "alignRt", "compareChromatograms", "transformIntensity")
importMethodsFrom("MSnbase", "sampleNames")
importFrom("MSnbase", "as.data.frame.Spectrum", "Chromatogram",
    "MChromatograms", "MSpectra", "requiredFvarLabels", "selectFeatureData")


export(
    "etg",
    "medianFilter",
    "plotQC",
    "retexp",
    "specNoise",
    "specPeaks",
    "SSgauss",
    "msn2xcmsRaw",
    "verify.mzQuantML",
    "xcmsRaw",
    "xcmsSet",
    "xcmsFragments",
    "phenoDataFromPaths"
)

S3method(plot, xcmsEIC)

S3method(split, xcmsSet)
S3method(c, xcmsSet)
S3method(c, XCMSnExp)
S3method(c, XcmsExperiment)
S3method(split, xcmsRaw)

exportClasses(
    "xcmsEIC",
    "xcmsPeaks",
    "xcmsRaw",
    "xcmsSet",
    "xcmsFragments",
    "xcmsSource",
    "xcmsFileSource"
)

exportMethods(
    "[",
    "$",
    "[[",
    "split",
    "absent",
    "AutoLockMass",
    "calibrate",
    "collect",
    "deepCopy",
    "filepaths",
    "filepaths<-",
    "diffreport",
    "findMZ",
    "findneutral",
    "fillPeaks",
    "fillPeaks.MSW",
    "fillPeaks.chrom",
    "findPeaks.centWave",
    "findPeaks.addPredictedIsotopeFeatures",
    "findPeaks.centWaveWithPredictedIsotopeROIs",
    "findPeaks.massifquant",
    "findPeaks.matchedFilter",
    "findPeaks.MSW",
    "findPeaks",
    "getEIC",
    "getPeaks",
    "getScan",
    "getMsnScan",
    "getSpec",
    "getXcmsRaw",
    "group",
    "group.density",
    "group.mzClust",
    "group.nearest",
    "groupidx",
    "groupidx<-",
    "groupnames",
    "groups",
    "groups<-",
    "groupval",
    "image",
    "levelplot",
    "mslevel",
    "mzrange",
    "peaks",
    "peaks<-",
    "peakTable",
    "phenoData",
    "phenoData<-",
    "plotChrom",
    "plotEIC",
    "plotPeaks",
    "plotRaw",
    "plotrt",
    "plotScan",
    "plotSpec",
    "plotSurf",
    "plotTIC",
    "plotTree",
    "present",
    "profinfo",
    "profinfo<-",
    "profMat",
    "profMedFilt",
    "profMethod",
    "profMethod<-",
    "profMz",
    "profRange",
    "profStep",
    "profStep<-",
    "progressCallback",
    "progressCallback<-",
    "rawEIC",
    "rawMat",
    "retcor",
    "retcor.peakgroups",
    "retcor.obiwarp",
    "revMz",
    "rtrange",
    "sampclass",
    "sampclass<-",
    "sampnames",
    "sampnames<-",
    "scanrange",
    "specDist",
    "specDist.cosine",
    "specDist.meanMZmatch",
    "specDist.peakCount",
    "show",
    "sortMz",
    "stitch",
    "updateObject",
    "write.cdf",
    "write.mzdata",
    "write.mzQuantML",
    "xcmsSource",
    "loadRaw",
    "isolationWindowTargetMz",
    "quantify",
    "findmzROI"
)

## New functions
export(
    "binYonX",
    "breaks_on_binSize",
    "breaks_on_nBins",
    "do_findChromPeaks_centWave",
    "do_findChromPeaks_massifquant",
    "do_findChromPeaks_matchedFilter",
    "do_findPeaks_MSW",
    "do_findChromPeaks_centWaveWithPredIsoROIs",
    "do_findChromPeaks_addPredIsoROIs",
    "imputeLinInterpol",
    "useOriginalCode",
    "setAs",
    "do_groupChromPeaks_density",
    "do_groupPeaks_mzClust",
    "do_groupChromPeaks_nearest",
    "do_adjustRtime_peakGroups",
    "processHistoryTypes",
    "highlightChromPeaks",
    "plotChromPeaks",
    "plotChromPeakImage",
    "isCalibrated",
    "plotMsData",
    "applyAdjustedRtime",
    "peaksWithMatchedFilter",
    "peaksWithCentWave",
    "rla",
    "rowRla",
    "featureSummary",
    "overlappingFeatures",
    "fixedMz",
    "fixedRt",
    "exportMetaboAnalyst",
    "imputeRowMin",
    "imputeRowMinRand",
    "hasFilledChromPeaks",
    "plotAdjustedRtime",
    "groupOverlaps",
    "loadXcmsData",
    "matchLamasChromPeaks",
    "summarizeLamaMatch",
    "matchedRtimes",
    "XcmsExperiment",
    "toXcmsExperiment",
    "toXcmsExperimentHdf5"
)

## New analysis methods
exportMethods(
    "showError",
    "findChromPeaks",
    "estimatePrecursorIntensity",
    "groupChromPeaks",
    "adjustRtime",
    "findChromPeaksIsolationWindow",
    "reconstructChromPeakSpectra"
)

## New Param classes
exportClasses(
    "CentWaveParam",
    "MatchedFilterParam",
    "MassifquantParam",
    "MSWParam",
    "CentWavePredIsoParam",
    "PeakDensityParam",
    "MzClustParam",
    "NearestPeaksParam",
    "PeakGroupsParam",
    "LamaParama",
    "ObiwarpParam",
    "GenericParam",
    "FillChromPeaksParam",
    "CalibrantMassParam",
    "CleanPeaksParam",
    "MergeNeighboringPeaksParam",
    "FilterIntensityParam",
    "ChromPeakAreaParam"
)
## Param class functions
export("CentWaveParam",
       "MatchedFilterParam",
       "MassifquantParam",
       "MSWParam",
       "CentWavePredIsoParam",
       "PeakDensityParam",
       "MzClustParam",
       "NearestPeaksParam",
       "PeakGroupsParam",
       "LamaParama",
       "ObiwarpParam",
       "GenericParam",
       "FillChromPeaksParam",
       "CalibrantMassParam",
       "XChromatogram",
       "XChromatograms",
       "CleanPeaksParam",
       "MergeNeighboringPeaksParam",
       "FilterIntensityParam",
       "ChromPeakAreaParam",
       "BetaDistributionParam")
## Param class methods.

## New Classes
exportClasses("XCMSnExp",
	      "ProcessHistory",
	      "XProcessHistory",
	      "XChromatogram",
              "XChromatograms")

## New methods for these classes
exportMethods("hasChromPeaks",
              "hasFilledChromPeaks",
              "hasFeatures",
              "hasAdjustedRtime",
              "adjustedRtime",
              "adjustedRtime<-",
              "adjustRtimePeakGroups",
              "featureArea",
              "featureDefinitions",
              "featureDefinitions<-",
              "featureValues",
              "chromPeaks",
              "chromPeaks<-",
              "chromPeakData",
              "chromPeakData<-",
              "processHistory",
              "fileIndex",
              "processDate",
              "processInfo",
              "processParam",
              "processType",
              "bin",
              "clean",
              "filterAcquisitionNum",
              "filterFile",
              "filterMsLevel",
              "filterMz",
              "filterRt",
              "pickPeaks",
              "removePeaks",
              "smooth",
              "dropAdjustedRtime",
              "dropFeatureDefinitions",
              "dropChromPeaks",
              "spectra",
              "rtime",
              "mz",
              "intensity",
              "fillChromPeaks",
              "dropFilledChromPeaks",
              "extractMsData",
              "chromatogram",
              "spectrapply",
	      "writeMSData",
              "plotChromPeakDensity",
              "correlate",
              "plot",
              "refineChromPeaks",
              "removeIntensity",
              "filterColumnsIntensityAbove",
              "filterColumnsKeepTop",
	      "plotChromatogramsOverlay",
	      "transformIntensity",
              "filterChromPeaks",
              "filterFeatureDefinitions",
              "manualChromPeaks",
              "manualFeatures",
              "featureSpectra",
              "chromPeakSpectra",
              "chromPeakChromatograms",
              "featureChromatograms",
              "chromPeakSummary"
              )

## feature grouping functions and methods.
importFrom("MsCoreUtils",
           "group")
importMethodsFrom("MsFeatures",
                  "featureGroups",
		  "featureGroups<-",
		  "groupFeatures")
importClassesFrom("MsFeatures",
                  "SimilarRtimeParam",
		  "AbundanceSimilarityParam")
importFrom("MsFeatures",
           "SimilarRtimeParam",
	   "AbundanceSimilarityParam",
	   "groupSimilarityMatrix")
exportMethods("featureGroups",
              "featureGroups<-")
export("plotFeatureGroups", "EicSimilarityParam")
exportClasses("EicSimilarityParam")

## Spectra things
importClassesFrom("Spectra", "Spectra")
importMethodsFrom("Spectra", "Spectra")
importMethodsFrom("Spectra", "spectrapply")
importMethodsFrom("Spectra", "peaksData")
importMethodsFrom("Spectra", "uniqueMsLevels")
importMethodsFrom("Spectra", "selectSpectraVariables")
importMethodsFrom("Spectra", "setBackend")
importMethodsFrom("Spectra", "dataOrigin")
importMethodsFrom("Spectra", "dataStorage")
importMethodsFrom("Spectra", "spectraVariables")
importMethodsFrom("Spectra", "rtime<-")
importMethodsFrom("Spectra", "ionCount")
importMethodsFrom("Spectra", "precursorMz")
importMethodsFrom("Spectra", "$")
importMethodsFrom("Spectra", "uniqueMsLevels")
importMethodsFrom("Spectra", "backendBpparam")
importMethodsFrom("Spectra", "estimatePrecursorIntensity")
importMethodsFrom("Spectra", "filterRanges")
importFrom("Spectra", "MsBackendMemory", "filterEmptySpectra",
           "concatenateSpectra")

## MsExperiment things
importClassesFrom("MsExperiment", "MsExperiment")
importMethodsFrom("MsExperiment", "spectra")
importMethodsFrom("MsExperiment", "filterSpectra")
importMethodsFrom("BiocGenerics", "do.call")
importMethodsFrom("BiocGenerics", "rbind")
importFrom("MsExperiment", "MsExperiment")
importFrom("MsExperiment", "linkSampleData")
importFrom("MsExperiment", "sampleData<-")
importFrom("MsExperiment", "sampleData")
importFrom("MsExperiment", "readMsExperiment")
importMethodsFrom("MsExperiment", "spectra<-")
importFrom("MsExperiment", "spectraSampleIndex")
export("plotPrecursorIons")

importFrom("progress", "progress_bar")

exportClasses("XcmsExperiment")
exportMethods("uniqueMsLevels")
exportMethods("filterMzRange")
exportMethods("fromFile")
exportMethods("fileNames")

## filtering features things
importFrom("MetaboCoreUtils", "rowRsd", "rowDratio", "rowPercentMissing",
           "rowBlank", "mclosest")
export("RsdFilter")
export("DratioFilter")
export("PercentMissingFilter")
export("BlankFlag")

## HDF5 storage mode
exportClasses("XcmsExperimentHdf5")
