useDynLib(MSnbase)
importFrom(Rcpp, sourceCpp)


import(grid)
import(BiocGenerics)
import(ProtGenerics)
importMethodsFrom(ProtGenerics, bin)
importClassesFrom(ProtGenerics, ProcessingStep)
import(BiocParallel)
import(Biobase)
import(mzR)
import(impute)

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

importFrom(MsCoreUtils, closest, rbindFill,
           impute_matrix, normalize_matrix,
           robustSummary, medianPolish,
           formatRt)
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, approx, cor)
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, extractROWS)
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(vsn, meanSdPlot)
importFrom(IRanges, IRanges, end, extractList, findOverlaps, start, width,
           reduce, NumericList)
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)

S3method(as.data.frame, MSnExp)
S3method(as.data.frame, MSnSet)
S3method(as.data.frame, Spectrum)
S3method(as.data.frame, mzRident)
S3method(as.matrix, FoICollection)
S3method(droplevels, MSnSet)
S3method(is.na, MSnSet)
S3method(t, MSnSet)

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,
       nFeatures,
       aggvar,
       nQuants,
       featureCV,
       makeImpuritiesMatrix,
       precSelection,
       precSelectionTable,
       t.MSnSet,
       updateFvarLabels,
       updateFeatureNames,
       updateSampleNames,
       normalise, ## for normalize method
       get.amino.acids,
       get.atomic.mass,
       listOf,
       npcv,
       selectFeatureData,
       ## comparing MSnSets
       averageMSnSet,
       commonFeatureNames,
       MSmap,
       ## MSnSetList
       MSnSetList,
       msnsets, objlog,
       image2,
       ## MzTab
       MzTab,
       smallMolecules,
       moleculeFeatures,
       moleculeEvidence,
       comments,
       mzTabMode,
       mzTabType,
       readMzTabData,
       writeMzTabData,
       ## old - defunct
       readMzTabData_v0.9,
       makeMTD,
       makePEP,
       makePRT,
       ## OnDiskMSnExp
       validateOnDiskMSnExp,
       ##options
       MSnbaseOptions,
       isMSnbaseVerbose,
       setMSnbaseVerbose,
       setMSnbaseParallelThresh,
       isMSnbaseFastLoad,
       setMSnbaseFastLoad,
       aggregationFun,
       Chromatogram,
       MChromatograms,
       factorsAsStrings,
       makeCamelCase,
       filterIdentificationDataFrame,
       isCentroidedFromFile,
       requiredFvarLabels,
       addMSnSetMetadata,
       readSRMData,
       meanMzInts,
       consensusSpectrum,
       combineSpectraMovingWindow,
       estimateMzScattering,
       hasSpectra, hasChromatograms,
       mergeFeatureVars, expandFeatureVars,
       MSpectra,
       extractSpectraData
       )

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

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,
              impute,
              topN,
              filterNA, filterZero,
              filterMsLevel,
              filterMz,
              filterPolarity,
              filterRt,
              filterFile,
              filterAcquisitionNum,
              filterEmptySpectra,
              filterPrecursorScan,
              spectrapply,
              splitByFile,
              combineFeatures,
              ## 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",
	      "alignRt",
	      "filterIntensity",
	      c,
	      compareChromatograms,
	      transformIntensity
              )

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