useDynLib(MSnbase)
importFrom(Rcpp, sourceCpp)

import(grid)
import(BiocGenerics)
import(ProtGenerics)
import(BiocParallel)
import(Biobase)
import(mzR)
import(impute)

import(scales)
import(lattice)
import(methods)

importFrom(XML, xmlInternalTreeParse, getDefaultNamespace, xpathApply,
           xmlAttrs)
importFrom(graphics, abline, axis, grid, legend, lines, points, text,
           barplot, layout, par, matplot, mtext)
importFrom(stats, ave, median, medpolish, quantile, reorder, setNames,
           weighted.mean, dist, model.matrix, .lm.fit)
importFrom(utils, combn, head, ls.str, object.size,
           packageDescription, packageVersion, read.csv, read.delim,
           read.table, select.list, setTxtProgressBar, tail,
           txtProgressBar, write.table)
importFrom(ggplot2, geom_histogram, geom_text, geom_line, geom_point,
           geom_bar, geom_freqpoly, geom_vline, geom_rect, geom_segment,
           geom_raster, theme, theme_gray, element_text,
           element_blank, element_rect, ggplot, ggtitle, xlab, ylab,
           labs, aes, annotate, scale_colour_hue,
           scale_fill_gradient2, scale_fill_gradient,
           scale_x_continuous, scale_x_log10, coord_cartesian,
           facet_grid)

importFrom(MALDIquant, binPeaks, match.closest) ## only using ::: functions
importFrom(S4Vectors, isEmpty, metadata, DataFrame, replaceROWS, SimpleList,
           endoapply)
importMethodsFrom(S4Vectors, showAsCell, "mcols<-", mcols, split)
importClassesFrom(S4Vectors, SimpleList)
importFrom(MASS, rlm)

## importFrom(rols, olsQuery, term)
## importClassesFrom(rols, CVParam)
importFrom(pcaMethods, pca, completeObs)
importFrom(plyr, ddply, llply, summarise)
importFrom(stats4, plot)
importFrom(preprocessCore, normalize.quantiles)
importFrom(vsn, vsn2, meanSdPlot)
importFrom(IRanges, IRanges, end, extractList, findOverlaps, start, width,
           reduce)
importClassesFrom(IRanges, IRanges)
importFrom(affy, MAplot, ma.plot, mva.pairs)
importFrom(mzID, mzID, flatten)
importClassesFrom(mzID, mzID, mzIDCollection)
importFrom(digest, digest)
importFrom(grDevices, topo.colors)

export(MSnSet,
       abstract,
       compareMSnSets,
       defaultNeutralLoss,
       readMgfData,
       readMSData,
       readMSData2,
       readMSnSet,
       readMSnSet2,
       readMzIdData,
       getEcols, grepEcols,
       formatRt,
       fillUp,
       naplot,
       makeNaData, makeNaData2, whichNA,
       ## extractSpectra, defunct in v 1.5.3
       extractPrecSpectra,
       as.matrix.FoICollection,
       as.data.frame.mzRident,
       as.data.frame.Spectrum,
       as.data.frame.MSnSet, ms2df,
       as.ExpressionSet.MSnSet,
       as.MSnSet.ExpressionSet,
       as.MIAME.MIAPE,
       as.MSnExp.OnDiskMSnExp,
       as.data.frame.MSnExp,
       is.na.MSnSet,
       droplevels.MSnSet,
       combineFeatures,
       nFeatures,
       aggvar,
       nQuants,
       featureCV,
       getRatios,
       makeImpuritiesMatrix,
       precSelection,
       precSelectionTable,
       t.MSnSet,
       updateFvarLabels,
       updateFeatureNames,
       updateSampleNames,
       normalise, ## for normalize method
       imputeMethods,
       get.amino.acids,
       get.atomic.mass,
       listOf,
       npcv,
       selectFeatureData,
       ## comparing MSnSets
       averageMSnSet,
       commonFeatureNames,
       MSmap,
       ## MSnSetList
       MSnSetList,
       msnsets, objlog,
       image2,
       ## MzTab
       MzTab,
       smallMolecules,
       comments,
       mzTabMode,
       mzTabType,
       readMzTabData,
       ## old - defunct
       writeMzTabData,
       readMzTabData_v0.9,
       makeMTD,
       makePEP,
       makePRT,
       ## OnDiskMSnExp
       ProcessingStep,
       validateOnDiskMSnExp,
       ##options
       MSnbaseOptions,
       isMSnbaseVerbose,
       setMSnbaseVerbose,
       setMSnbaseParallelThresh,
       isMSnbaseFastLoad,
       setMSnbaseFastLoad,
       ## ProcessingStep
       executeProcessingStep,
       aggregationFun,
       Chromatogram,
       Chromatograms,
       factorsAsStrings,
       makeCamelCase,
       filterIdentificationDataFrame,
       isCentroidedFromFile,
       requiredFvarLabels,
       addMSnSetMetadata,
       readSRMData,
       meanMzInts,
       consensusSpectrum,
       combineSpectraMovingWindow,
       estimateMzScattering,
       hasSpectra, hasChromatograms,
       mergeFeatureVars, expandFeatureVars,
       Spectra
       )

exportClasses(pSet,
              MIAPE,
              MSnExp,
              MSnProcess,
              MSnSet,
              MSnSetList,
              Spectrum, Spectrum1, Spectrum2,
              ReporterIons,
              FeaturesOfInterest,
              FoICollection,
              FeatComp,
              MSmap,
              MzTab,
              OnDiskMSnExp,
              ProcessingStep,
              Chromatogram,
              Chromatograms,
	      Spectra
	      )

exportMethods(updateObject,
              exprs,
              assayData,
              "assayData<-",
              coerce,
              show,"[","[[", "[<-",
              fvarLabels,
              fData,
              "fData<-",
              featureNames,
              "featureNames<-",
              sampleNames,
              "sampleNames<-",
              fileNames,
              msInfo,
              expemail, exptitle,
              ionSource, ionSourceDetails,
              analyser, analyzer,
              analyserDetails, analyzerDetails,
              detectorType,
              instrumentModel, instrumentManufacturer,
              instrumentCustomisations,
              qual,
              length,
              lengths,
              all.equal,
              image,
              plot,
              plot2d,
              plotDensity,
              plotMzDelta,
              plotNA,
              MAplot,
              spectra,
              processingData,
              peaksCount,
              isEmpty,
              bin,
              calculateFragments,
              clean,
              compareSpectra,
              estimateNoise,
              pickPeaks,
              removePeaks,
              removeReporters,
              smooth,
              addIdentificationData,
              removeNoId,
              removeMultipleAssignment,
              idSummary,
              intensity,
              mz,
              tic,
              bpi,
              ionCount,
              fromFile,
              centroided, "centroided<-",
              isCentroided,
              smoothed, "smoothed<-",
              precursorMz,
              precursorIntensity,
              precursorCharge,
              precScanNum,
              acquisitionNum,
              scanIndex,
              rtime,
              peaksCount,
              msLevel,
              collisionEnergy,
              polarity,
              trimMz,
              quantify,
              purityCorrect,
              header,
              dim,
              multiplex,
              multiLabels,
              width,
              reporterColours, reporterColors,
              reporterNames, "reporterNames<-",
              writeMgfData,
              write.exprs,
              combine, ## for classes MIAPE, MSnProcess and MSnSet
              "experimentData<-", ## signature("MSnSet", "MIAPE")
              normalize,
              scale,
              log,
              trimws,
              exprsToRatios,
              impute,
              topN,
              filterNA, filterZero,
              filterMsLevel,
              filterMz,
              filterPolarity,
              filterRt,
              filterFile,
              filterAcquisitionNum,
              filterEmptySpectra,
              filterPrecursorScan,
              spectrapply,
              splitByFile,
              ## Features of interest
              FeaturesOfInterest,
              foi,
              description,
              FoICollection,
              addFeaturesOfInterest,
              rmFeaturesOfInterest,
              fnamesIn,
              ## comparing MSnSets
              compfnames,
              common,
              unique1,
              unique2,
              names, "names<-",
              ## MSmap
              mzRes, plot3D, msMap,
              fileName, t,
              ## MSnSetList
              split,
              ## MzTab
              fileName,
              metadata,
              psms,
              pData, "pData<-",
              "$",
              "$<-",
              phenoData, "phenoData<-",
              chromatogram,
              "colnames<-",
              reduce,
              writeMSData,
              productMz,
              estimateMzResolution,
	      combineSpectra,
              "isolationWindowLowerMz",
              "isolationWindowUpperMz",
              "filterPrecursorMz",
              "filterIsolationWindow"
              )

## methods NOT exported
## curveStats
## "precursorCharge<-"
