r-cran-maldiquantforeign/0000755000175000017500000000000012221047255015675 5ustar rusconirusconir-cran-maldiquantforeign/man/0000755000175000017500000000000012221046771016452 5ustar rusconirusconir-cran-maldiquantforeign/man/composeFilename-methods.Rd0000644000175000017500000000107012221046771023506 0ustar rusconirusconi\name{.composeFilename,AbstractMassObject-method} \alias{.composeFilename,AbstractMassObject-method} \alias{.composeFilename,list-method} \title{This method creates a filename for a \code{\linkS4class{AbstractMassObject}} object.} \arguments{ \item{x}{a \code{\linkS4class{AbstractMassObject}} object} \item{fileExtension}{file type (e.g. "txt", "pdf", ...)} } \value{ filename } \description{ This method creates a filename for a \code{\linkS4class{AbstractMassObject}} object. } \seealso{ \code{\linkS4class{AbstractMassObject}} } \keyword{internal} r-cran-maldiquantforeign/man/MALDIquantForeign-package.Rd0000644000175000017500000000115312221046771023543 0ustar rusconirusconi\docType{package} \name{MALDIquantForeign-package} \alias{MALDIquantForeign-package} \title{Import/Export routines for MALDIquant} \description{ This package allows to read and write different file formats of mass spectrometry data into/from MALDIquant objects. } \details{ \tabular{ll}{ Package: \tab MALDIquantForeign \cr Version: \tab 0.5.1\cr Date: \tab 2013-09-18\cr License: \tab GPL (>= 3)\cr URL: \tab http://strimmerlab.org/software/maldiquant/\cr } } \author{ Sebastian Gibb \email{mail@sebastiangibb.de} } \references{ \url{http://strimmerlab.org/software/maldiquant/} } \keyword{package} r-cran-maldiquantforeign/man/importBrukerFlex-functions.Rd0000644000175000017500000000201312221046771024247 0ustar rusconirusconi\name{importBrukerFlex} \alias{importBrukerFlex} \title{Import Bruker Daltonics *flex files} \usage{ importBrukerFlex(path, ...) } \arguments{ \item{path}{\code{character}, path to directory or file which should be read in.} \item{\ldots}{arguments to be passed to \code{\link[readBrukerFlexData]{readBrukerFlexFile}}.} } \value{ a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \description{ This function imports files in Bruker Daltonics *flex-series file format into \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \examples{ library("MALDIquant") library("MALDIquantForeign") ## get example directory exampleDirectory <- system.file(file.path("tests", "data"), package="MALDIquantForeign") s <- importBrukerFlex(exampleDirectory) } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/} } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}}, \code{\link[readBrukerFlexData]{readBrukerFlexFile}} } r-cran-maldiquantforeign/man/parseCiphergenXml.Rd0000644000175000017500000000067712221046771022373 0ustar rusconirusconi\name{.parseCiphergenXml} \alias{.parseCiphergenXml} \title{Parse Ciphergen XML files.} \usage{ .parseCiphergenXml(file, ...) } \arguments{ \item{file}{\code{character}, path to Ciphergen XML file} \item{verbose}{\code{logical}, verbose output?} } \value{ Returns a list with metadata and spectra. } \description{ This function parses Ciphergen XML files. } \author{ Sebastian Gibb \email{mail@sebastiangibb.de} } \keyword{internal} r-cran-maldiquantforeign/man/export-methods.Rd0000644000175000017500000000417012221046771021725 0ustar rusconirusconi\name{export,AbstractMassObject-method} \alias{export} \alias{export,AbstractMassObject-method} \alias{export,list-method} \title{Export files} \usage{ \S4method{export}{AbstractMassObject}(x, file, type="auto", force=FALSE, \ldots) \S4method{export}{list}(x, path, type, force=FALSE, \ldots) } \arguments{ \item{x}{a \code{\link[MALDIquant]{AbstractMassObject-class}} object or a \code{list} of \code{\link[MALDIquant]{AbstractMassObject-class}} objects.} \item{file}{\code{character}, file name.} \item{path}{\code{character}, path to directory in which the \code{list} of \code{\link[MALDIquant]{AbstractMassObject-class}} would be exported.} \item{type}{\code{character}, file format. If \code{type} is set to \dQuote{auto} the file extension is used.} \item{force}{\code{logical}, If \code{TRUE} the \code{file} would be overwritten or \code{path} would be created.} \item{\ldots}{arguments to be passed to specific export functions.} } \description{ This function provides a general interface to export \code{\link[MALDIquant]{AbstractMassObject-class}} objects (e.g. \code{\link[MALDIquant]{MassSpectrum-class}}, \code{\link[MALDIquant]{MassPeaks-class}}) into different file formats. } \details{ Specific export functions: \tabular{ll}{ tab \tab \code{\link[MALDIquantForeign]{exportTab}} \cr csv \tab \code{\link[MALDIquantForeign]{exportCsv}} \cr msd \tab \code{\link[MALDIquantForeign]{exportMsd}} \cr mzML \tab \code{\link[MALDIquantForeign]{exportMzMl}} \cr } } \examples{ \dontrun{ library("MALDIquant") library("MALDIquantForeign") s <- list(createMassSpectrum(mass=1:5, intensity=1:5), createMassSpectrum(mass=1:5, intensity=1:5)) ## export a single spectrum export(s[[1]], file="spectrum.csv") ## identical to exportCsv(s[[1]], file="spectrum.csv") ## export a list of spectra export(s, path="spectra", type="csv") ## identical to exportCsv(s, path="spectra") } } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/} } \seealso{ \code{\link[MALDIquant]{MassPeaks-class}}, \code{\link[MALDIquant]{MassSpectrum-class}} } r-cran-maldiquantforeign/man/importMzMl-functions.Rd0000644000175000017500000000174212221046771023065 0ustar rusconirusconi\name{importMzMl} \alias{importMzMl} \title{Import mzML files} \usage{ importMzMl(path, ...) } \arguments{ \item{path}{\code{character}, path to directory or file which should be read in.} \item{\ldots}{arguments to be passed to \code{\link[MALDIquantForeign]{import}}.} } \value{ a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \description{ This function imports files in mzML file format into \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \examples{ library("MALDIquant") library("MALDIquantForeign") ## get example directory exampleDirectory <- system.file(file.path("tests", "data"), package="MALDIquantForeign") ## import s <- importMzMl(exampleDirectory) } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/}, \cr Definition of \code{mzML} format: \url{http://www.psidev.info/mzml_1_0_0\%20} } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}} } r-cran-maldiquantforeign/man/fileExtension.Rd0000644000175000017500000000071412221046771021557 0ustar rusconirusconi\name{.fileExtension} \alias{.fileExtension} \title{Determine file extension} \usage{ .fileExtension(x) } \arguments{ \item{x}{\code{character}, filename.} } \value{ \code{character}, file extension. } \description{ Determine file extension } \examples{ library("MALDIquantForeign") files <- c("/home/foo/bar.txt", "foobar.pdf") MALDIquantForeign:::.fileExtension(files) } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}} } \keyword{internal} r-cran-maldiquantforeign/man/exportMsd-methods.Rd0000644000175000017500000000403312221046771022367 0ustar rusconirusconi\name{exportMsd,MassSpectrum-method} \alias{exportMsd} \alias{exportMsd,list-method} \alias{exportMsd,MassSpectrum-method} \title{Export to MSD files} \usage{ \S4method{exportMsd}{MassSpectrum}(x, file, force=FALSE, peaks, \ldots) \S4method{exportMsd}{list}(x, path, force=FALSE, peaks, \ldots) } \arguments{ \item{x}{a \code{\link[MALDIquant]{MassSpectrum-class}} object or a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects.} \item{file}{\code{character}, file name.} \item{path}{\code{character}, path to directory in which the \code{list} of \code{\link[MALDIquant]{AbstractMassObject-class}} would be exported.} \item{peaks}{a \code{\link[MALDIquant]{MassPeaks-class}} object or a \code{list} of \code{\link[MALDIquant]{MassPeaks-class}} objects.} \item{force}{\code{logical}, If \code{TRUE} the \code{file} would be overwritten or \code{path} would be created.} \item{\ldots}{arguments to be passed to \code{\link[utils]{write.table}}.} } \description{ This function exports \code{\link[MALDIquant]{AbstractMassObject-class}} objects (e.g. \code{\link[MALDIquant]{MassSpectrum-class}}, \code{\link[MALDIquant]{MassPeaks-class}}) into mMass MSD files. } \examples{ \dontrun{ library("MALDIquant") library("MALDIquantForeign") s <- list(createMassSpectrum(mass=1:5, intensity=1:5), createMassSpectrum(mass=1:5, intensity=1:5)) p <- list(createMassPeaks(mass=4:5, intensity=4:5, snr=1:2), createMassPeaks(mass=4:5, intensity=4:5, snr=1:2)) ## export a single spectrum exportMsd(s[[1]], file="spectrum.msd") ## export a single spectrum with corresponding peaks exportMsd(s[[1]], file="spectrum.msd", peaks=p[[1]]) ## export a list of spectra with corresponding peaks exportMsd(s, path="spectra", peaks=p, force=TRUE) } } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/}, \cr mMass homepage: \url{http://mmass.org/} } \seealso{ \code{\link[MALDIquant]{MassPeaks-class}}, \code{\link[MALDIquant]{MassSpectrum-class}} } r-cran-maldiquantforeign/man/importAnalyze-functions.Rd0000644000175000017500000000143612221046771023611 0ustar rusconirusconi\name{importAnalyze} \alias{importAnalyze} \title{Import Analyze 7.5 files} \usage{ importAnalyze(path, ...) } \arguments{ \item{path}{\code{character}, path to directory or file which should be read in.} \item{\ldots}{arguments to be passed to \code{\link[MALDIquantForeign]{import}}.} } \value{ a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \description{ This function imports files in Analyze 7.5 file format into \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/} \cr \url{http://www.grahamwideman.com/gw/brain/analyze/formatdoc.htm}, \url{http://eeg.sourceforge.net/ANALYZE75.pdf} } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}} } r-cran-maldiquantforeign/man/exportMzMl-methods.Rd0000644000175000017500000000331412221046771022524 0ustar rusconirusconi\name{exportMzMl,MassSpectrum-method} \alias{exportMzMl} \alias{exportMzMl,list-method} \alias{exportMzMl,MassSpectrum-method} \title{Export to mzML files} \usage{ \S4method{exportMzMl}{MassSpectrum}(x, file, force=FALSE, \ldots) \S4method{exportMzMl}{list}(x, path, force=FALSE, \ldots) } \arguments{ \item{x}{a \code{\link[MALDIquant]{MassSpectrum-class}} object or a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects.} \item{file}{\code{character}, file name.} \item{path}{\code{character}, path to directory in which the \code{list} of \code{\link[MALDIquant]{AbstractMassObject-class}} would be exported.} \item{force}{\code{logical}, If \code{TRUE} the \code{file} would be overwritten or \code{path} would be created.} \item{\ldots}{arguments to be passed to \code{\link[utils]{write.table}}.} } \description{ This function exports \code{\link[MALDIquant]{AbstractMassObject-class}} objects (e.g. \code{\link[MALDIquant]{MassSpectrum-class}}, \code{\link[MALDIquant]{MassPeaks-class}}) into mzML files. } \examples{ \dontrun{ library("MALDIquant") library("MALDIquantForeign") s <- list(createMassSpectrum(mass=1:5, intensity=1:5), createMassSpectrum(mass=1:5, intensity=1:5)) ## export a single spectrum exportMzMl(s[[1]], file="spectrum.mzML") ## export a list of spectra with corresponding peaks exportMzMl(s, path="spectra.mzMl") } } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/}, \cr HUPO Proteomics Standards Inititative mzML 1.1.0 Specification: \url{http://www.psidev.info/mzml_1_0_0} } \seealso{ \code{\link[MALDIquant]{MassPeaks-class}}, \code{\link[MALDIquant]{MassSpectrum-class}} } r-cran-maldiquantforeign/man/importCiphergenXml-functions.Rd0000644000175000017500000000167712221046771024602 0ustar rusconirusconi\name{importCiphergenXml} \alias{importCiphergenXml} \title{Import Ciphergen XML files} \usage{ importCiphergenXml(path, ...) } \arguments{ \item{path}{\code{character}, path to directory or file which should be read in.} \item{\ldots}{arguments to be passed to \code{\link[MALDIquantForeign]{import}}.} } \value{ a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \description{ This function imports files in Ciphergen XML file format into \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \examples{ library("MALDIquant") library("MALDIquantForeign") ## get example directory exampleDirectory <- system.file(file.path("tests", "data"), package="MALDIquantForeign") ## import s <- importCiphergenXml(exampleDirectory) } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/} } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}} } r-cran-maldiquantforeign/man/importMzXml-functions.Rd0000644000175000017500000000204412221046771023251 0ustar rusconirusconi\name{importMzXml} \alias{importMzXml} \title{Import mzXML files} \usage{ importMzXml(path, ...) } \arguments{ \item{path}{\code{character}, path to directory or file which should be read in.} \item{\ldots}{arguments to be passed to \code{\link[readMzXmlData]{readMzXmlFile}}.} } \value{ a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \description{ This function imports files in mzXML file format into \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \examples{ library("MALDIquant") library("MALDIquantForeign") ## get example directory exampleDirectory <- system.file(file.path("tests", "data"), package="MALDIquantForeign") ## import s <- importMzXml(exampleDirectory) } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/}, \cr Definition of \code{mzXML} format: \url{http://tools.proteomecenter.org/mzXMLschema.php} } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}}, \code{\link[readMzXmlData]{readMzXmlFile}} } r-cran-maldiquantforeign/man/supportedFileFormats-functions.Rd0000644000175000017500000000301312221046771025125 0ustar rusconirusconi\name{supportedFileFormats} \alias{supportedFileFormats} \title{Supported file formats} \usage{ supportedFileFormats() } \value{ a \code{list} with two named elements (\code{import} and \code{export}) containing a \code{character} vector of supported file types. } \description{ This function prints all file formats supported by \code{\link{MALDIquantForeign-package}}. } \details{ \subsection{Import}{ \tabular{ll}{ txt \tab \code{\link[MALDIquantForeign]{importTxt}} \cr tab \tab \code{\link[MALDIquantForeign]{importTab}} \cr csv \tab \code{\link[MALDIquantForeign]{importCsv}} \cr fid \tab \code{\link[MALDIquantForeign]{importBrukerFlex}} \cr ciphergen \tab \code{\link[MALDIquantForeign]{importCiphergenXml}} \cr mzXML \tab \code{\link[MALDIquantForeign]{importMzXml}} \cr mzML \tab \code{\link[MALDIquantForeign]{importMzMl}} \cr imzML \tab \code{\link[MALDIquantForeign]{importImzMl}} \cr analyze \tab \code{\link[MALDIquantForeign]{importAnalyze}} \cr } } \subsection{Export}{ \tabular{ll}{ tab \tab \code{\link[MALDIquantForeign]{exportTab}} \cr csv \tab \code{\link[MALDIquantForeign]{exportCsv}} \cr msd \tab \code{\link[MALDIquantForeign]{exportMsd}} \cr mzML \tab \code{\link[MALDIquantForeign]{exportMzMl}} \cr } } } \examples{ library("MALDIquantForeign") supportedFileFormats() } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/} } \seealso{ \code{\link[MALDIquantForeign]{export}}, \code{\link[MALDIquantForeign]{import}} } r-cran-maldiquantforeign/man/base64-encode.Rd0000644000175000017500000000167212221046771021266 0ustar rusconirusconi\name{.base64encode} \alias{.base64encode} \title{Converts double to base64 character.} \usage{ .base64encode(x, size, endian = .Platform$endian, compressionType = c("none", "gzip")) } \arguments{ \item{x}{\code{double}, vector} \item{size}{\code{integer}, number of bytes per element in the byte stream (see \code{size} in \code{\link[base]{writeBin}}).} \item{endian}{\code{character}, the endian-ness (see \code{endian} in \code{\link[base]{writeBin}}).} \item{compressionType}{\code{character}, type of compression to use for compression of \code{x} (see \code{type} in \code{\link[base]{memCompress}}.} } \value{ Vector of type \code{character}. } \description{ This function converts a \code{double} vector to a base64 encoded \code{character} vector. } \author{ Sebastian Gibb \email{mail@sebastiangibb.de} } \seealso{ \code{\link[base64enc]{base64encode}} from \pkg{base64enc} package } \keyword{internal} r-cran-maldiquantforeign/man/cleanFilename.Rd0000644000175000017500000000041412221046771021463 0ustar rusconirusconi\name{.cleanFilename} \alias{.cleanFilename} \title{This function removes spaces and punctuations from filenames.} \usage{ .cleanFilename(x) } \value{ filename } \description{ This function removes spaces and punctuations from filenames. } \keyword{internal} r-cran-maldiquantforeign/man/importImzMl-functions.Rd0000644000175000017500000000173112221046771023234 0ustar rusconirusconi\name{importImzMl} \alias{importImzMl} \title{Import imzML files} \usage{ importImzMl(path, ...) } \arguments{ \item{path}{\code{character}, path to directory or file which should be read in.} \item{\ldots}{arguments to be passed to \code{\link[MALDIquantForeign]{import}}.} } \value{ a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \description{ This function imports files in imzML file format into \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \examples{ library("MALDIquant") library("MALDIquantForeign") ## get example directory exampleDirectory <- system.file(file.path("tests", "data"), package="MALDIquantForeign") ## import s <- importImzMl(exampleDirectory) } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/}, \cr Definition of \code{imzML} format: \url{http://www.imzml.org/} } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}} } r-cran-maldiquantforeign/man/exportTab-methods.Rd0000644000175000017500000000414212221046771022353 0ustar rusconirusconi\name{exportTab,AbstractMassObject-method} \alias{exportCsv} \alias{exportCsv,AbstractMassObject-method} \alias{exportCsv,list-method} \alias{exportTab} \alias{exportTab,AbstractMassObject-method} \alias{exportTab,list-method} \title{Export to text files} \usage{ \S4method{exportTab}{AbstractMassObject}(x, file, force=FALSE, \ldots) \S4method{exportTab}{list}(x, path, force=FALSE, \ldots) \S4method{exportCsv}{AbstractMassObject}(x, file, force=FALSE, \ldots) \S4method{exportCsv}{list}(x, path, force=FALSE, \ldots) } \arguments{ \item{x}{a \code{\link[MALDIquant]{AbstractMassObject-class}} object or a \code{list} of \code{\link[MALDIquant]{AbstractMassObject-class}} objects.} \item{file}{\code{character}, file name.} \item{path}{\code{character}, path to directory in which the \code{list} of \code{\link[MALDIquant]{AbstractMassObject-class}} would be exported.} \item{force}{\code{logical}, If \code{TRUE} the \code{file} would be overwritten or \code{path} would be created.} \item{\ldots}{arguments to be passed to \code{\link[utils]{write.table}}.} } \description{ This function exports \code{\link[MALDIquant]{AbstractMassObject-class}} objects (e.g. \code{\link[MALDIquant]{MassSpectrum-class}}, \code{\link[MALDIquant]{MassPeaks-class}}) into different text file formats. } \details{ \code{exportTab} and \code{exportCsv} use \code{\link[utils]{write.table}} with different defaults (\code{sep="\t"} in \code{exportTab} and \code{sep=","} in \code{exportCsv}). } \examples{ \dontrun{ library("MALDIquant") library("MALDIquantForeign") s <- list(createMassSpectrum(mass=1:5, intensity=1:5), createMassSpectrum(mass=1:5, intensity=1:5)) ## export a single spectrum exportTab(s[[1]], file="spectrum.tab") ## export a list of spectra and use ; as separator exportCsv(s, path="spectra", sep=";", force=TRUE) } } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/} } \seealso{ \code{\link[MALDIquant]{MassPeaks-class}}, \code{\link[MALDIquant]{MassSpectrum-class}}, \code{\link[utils]{write.table}} } r-cran-maldiquantforeign/man/import-functions.Rd0000644000175000017500000000673612221046771022275 0ustar rusconirusconi\name{import} \alias{import} \title{Import files} \usage{ import(path, type = "auto", pattern, excludePattern = NULL, removeEmptySpectra = TRUE, verbose = TRUE, ...) } \arguments{ \item{path}{\code{character}, path to directory or file which should be read in.} \item{type}{\code{character}, file format. If \code{type} is set to \dQuote{auto} MALDIquant tries to detect the correct file type automatically. It often depends on the file extension (if \code{path} is a directory the most represented file extension is used; \code{pattern} argument is ignored).} \item{pattern}{\code{character}, a regular expression to find files in a directory (see details).} \item{excludePattern}{\code{character}, a regular expression to exclude files in a directory (see details).} \item{removeEmptySpectra}{\code{logical}, should empty spectra excluded?} \item{verbose}{\code{logical}, verbose output?} \item{\ldots}{arguments to be passed to specific import functions.} } \value{ a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \description{ This function provides a general interface to import different file formats into \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \details{ Specific import functions: \tabular{ll}{ txt \tab \code{\link[MALDIquantForeign]{importTxt}} \cr tab \tab \code{\link[MALDIquantForeign]{importTab}} \cr csv \tab \code{\link[MALDIquantForeign]{importCsv}} \cr fid \tab \code{\link[MALDIquantForeign]{importBrukerFlex}} \cr ciphergen \tab \code{\link[MALDIquantForeign]{importCiphergenXml}} \cr mzXML \tab \code{\link[MALDIquantForeign]{importMzXml}} \cr mzML \tab \code{\link[MALDIquantForeign]{importMzMl}} \cr imzML \tab \code{\link[MALDIquantForeign]{importImzMl}} \cr analyze \tab \code{\link[MALDIquantForeign]{importAnalyze}} \cr } \code{path}: In addition to the above mentioned file types the following (compressed) archives are supported, too: zip, tar, tar.gz, tar.bz2, tar.xz. The archives are uncompressed in a temporary directory. Afterwards the \code{\link[MALDIquantForeign]{import}} function is called (with \code{type="auto"}). \code{pattern}: Sometimes unusual file extensions are used (e.g. \code{"*.xml"} for mzXML files). In this case a specific \code{pattern} could be defined to import files with an unusual file extension (e.g. \code{pattern="^.*\\.xml$"} to read all \code{*.xml} files in a directory; see \code{\link[base]{regexp}} for details). \code{excludePattern}: Sometimes some files should be excluded. E.g. to ignore additional aquired Bruker LIFT spectra (MALDI-TOF/TOF; which are not support, yet) you could use \code{excludePattern="([[:digit:]\\.]+)LIFT[\\\\/]1SRef"}. } \examples{ library("MALDIquant") library("MALDIquantForeign") ## get example directory exampleDirectory <- system.file(file.path("tests", "data"), package="MALDIquantForeign") ## import mzXML files s <- import(exampleDirectory, type="mzXML") ## import tab delimited file with different file extension (default: *.tab) s <- import(exampleDirectory, type="tab", pattern="^.*\\\\.txt") ## import single mzML file s <- import(file.path(exampleDirectory, "tiny1.mzML1.1.mzML")) ## import gzipped csv file s <- import(file.path(exampleDirectory, "compressed", "csv1.csv.gz")) } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/} } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}} } r-cran-maldiquantforeign/man/parseMzMl.Rd0000644000175000017500000000063512221046771020657 0ustar rusconirusconi\name{.parseMzMl} \alias{.parseMzMl} \title{Parse mzML files.} \usage{ .parseMzMl(file, verbose = FALSE, ...) } \arguments{ \item{file}{\code{character}, path to mzML file} \item{verbose}{\code{logical}, verbose output?} } \value{ Returns a list with metadata and spectra. } \description{ This function parses mzML files. } \author{ Sebastian Gibb \email{mail@sebastiangibb.de} } \keyword{internal} r-cran-maldiquantforeign/man/mzMlHandlers.Rd0000644000175000017500000000111112221046771021333 0ustar rusconirusconi\name{.mzMlHandlers} \alias{.mzMlHandlers} \title{Parse mzML files.} \usage{ .mzMlHandlers(fileName, verbose = FALSE) } \arguments{ \item{fileName}{\code{character}, path to mzML file} \item{verbose}{\code{logical}, verbose output?} } \value{ function closure } \description{ This function is defines handlers for XML SAX parser. Internal use only. } \details{ TODO: fetch obo map file and use it } \author{ Sebastian Gibb \email{mail@sebastiangibb.de} } \references{ Definition of \code{mzML} format: \url{http://www.psidev.info/mzml_1_0_0} } \keyword{internal} r-cran-maldiquantforeign/man/importTab-functions.Rd0000644000175000017500000000227712221046771022720 0ustar rusconirusconi\name{importTxt} \alias{importCsv} \alias{importTab} \alias{importTxt} \title{Import text files} \usage{ importTxt(path, ...) importTab(path, ...) importCsv(path, ...) } \arguments{ \item{path}{\code{character}, path to directory or file which should be read in.} \item{\ldots}{arguments to be passed to \code{\link[utils]{read.table}}.} } \value{ a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \description{ This function imports different text file formats into \code{\link[MALDIquant]{MassSpectrum-class}} objects. } \details{ \code{importTab}, \code{importTxt} and \code{importCsv} use \code{\link[utils]{read.table}} with different defaults. } \examples{ library("MALDIquant") library("MALDIquantForeign") ## get example directory exampleDirectory <- system.file(file.path("tests", "data"), package="MALDIquantForeign") ## import txt files s <- importTxt(exampleDirectory) ## import csv files s <- importCsv(exampleDirectory) } \author{ Sebastian Gibb } \references{ \url{http://strimmerlab.org/software/maldiquant/} } \seealso{ \code{\link[MALDIquant]{MassSpectrum-class}}, \code{\link[utils]{read.table}} } r-cran-maldiquantforeign/inst/0000755000175000017500000000000012221046771016654 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/0000755000175000017500000000000012221046771020016 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/test_download-functions.R0000644000175000017500000000044712221046771025022 0ustar rusconirusconicontext("download") url <- c("http://www.tld.com/", "https://www.tld.com/archive.zip", "ftp://ftp.tld.com", "/data/archive.zip", "/root", "/dev/data.csv") test_that(".isUrl", { expect_identical(MALDIquantForeign:::.isUrl(url), c(rep(TRUE, 3), rep(FALSE, 3))) }) r-cran-maldiquantforeign/inst/tests/test_sanitize-functions.R0000644000175000017500000000031012221046771025026 0ustar rusconirusconicontext("sanitize") test_that("sanitize-functions", { s <- c("ac", "a&o", "abc") r <- c("a<b", "b>c", "a&o", "abc") expect_identical(MALDIquantForeign:::.sanitize(s), r) }) r-cran-maldiquantforeign/inst/tests/test_importMzXml-functions.R0000644000175000017500000000172212221046771025512 0ustar rusconirusconicontext("importMzXml") test_that("importMzXml", { expect_error(MALDIquantForeign:::.importMzXml("tmp.tmp")) path <- file.path("data", "tiny1.mzXML3.0.mzXML") s <- MALDIquantForeign:::.importMzXml(path) expect_equal(s, import(path)) expect_equal(s, importMzXml(path)) expect_equal(s, import(path, type="mzXML")) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "tiny1.mzXML3.0.mzXML") }) test_that("importMzXml compressed", { expect_error(MALDIquantForeign:::.importMzXml("tmp.tmp")) path <- file.path("data", "tiny1-compressed.mzXML3.0.mzXML") s <- MALDIquantForeign:::.importMzXml(path) expect_equal(s, import(path)) expect_equal(s, importMzXml(path)) expect_equal(s, import(path, type="mzXML")) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "tiny1-compressed.mzXML3.0.mzXML") }) r-cran-maldiquantforeign/inst/tests/test_importMzMl-functions.R0000644000175000017500000000237312221046771025325 0ustar rusconirusconicontext("importMzMl") test_that("importMzMl", { expect_error(MALDIquantForeign:::.importMzMl("tmp.tmp")) path <- normalizePath(file.path("data", "tiny1.mzML1.1.mzML")) s <- MALDIquantForeign:::.importMzMl(path) expect_equal(s, import(path)) expect_equal(s, importMzMl(path)) expect_equal(s, import(path, type="mzML")) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "tiny1.mzML1.1.mzML") expect_equal(mass(s[[2]]), 1:5) expect_equal(intensity(s[[2]]), 10:6) expect_equal(basename(metaData(s[[2]])$file), "tiny1.mzML1.1.mzML") }) test_that("importMzMl compressed", { expect_error(MALDIquantForeign:::.importMzMl("tmp.tmp")) path <- normalizePath(file.path("data", "tiny1-compressed.mzML1.1.mzML")) s <- MALDIquantForeign:::.importMzMl(path) expect_equal(s, import(path)) expect_equal(s, importMzMl(path)) expect_equal(s, import(path, type="mzML")) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "tiny1-compressed.mzML1.1.mzML") expect_equal(mass(s[[2]]), 1:5) expect_equal(intensity(s[[2]]), 10:6) expect_equal(basename(metaData(s[[2]])$file), "tiny1-compressed.mzML1.1.mzML") }) r-cran-maldiquantforeign/inst/tests/test_importTab-functions.R0000644000175000017500000000460712221046771025156 0ustar rusconirusconicontext("importTab") test_that("importTab", { ## suppress warnings to avoid creation of Rplots.pdf expect_error(suppressWarnings(MALDIquantForeign:::.importTab("tmp.tmp"))) path <- normalizePath(file.path("data", "ascii.txt")) s <- MALDIquantForeign:::.importTab(path) expect_equal(s, import(path)) expect_equal(s, importTxt(path)) expect_equal(s, import(path, type="txt")) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "ascii.txt") }) test_that("importCsv", { ## suppress warnings to avoid creation of Rplots.pdf expect_error(suppressWarnings(MALDIquantForeign:::.importCsv("tmp.tmp"))) path <- normalizePath(file.path("data", "csv1.csv")) s <- MALDIquantForeign:::.importCsv(path, sep=",", header=TRUE) expect_equal(s, import(path, sep=",", header=TRUE)) expect_equal(s, importCsv(path, sep=",", header=TRUE)) expect_equal(s, import(path, type="csv", sep=",", header=TRUE)) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "csv1.csv") ## auto header s <- MALDIquantForeign:::.importCsv(path) expect_equal(s, import(path)) expect_equal(s, importCsv(path)) expect_equal(s, import(path, type="csv")) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "csv1.csv") s <- MALDIquantForeign:::.importCsv(file.path("data", "csv2.csv"), sep=";", header=FALSE) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "csv2.csv") ## auto header s <- MALDIquantForeign:::.importCsv(file.path("data", "csv2.csv"), sep=";") expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "csv2.csv") }) x <- c("10, 30", "\"foo\", \"bar\"", "foo; bar", "foo\tbar", "1\t 2") sep <- c(",", ",", ";", "\t", "\t") test_that("autoHeader", { result <- c(FALSE, TRUE, TRUE, TRUE, FALSE) for (i in seq(along=x)) { expect_identical(MALDIquantForeign:::.autoHeader(textConnection(x[i]), sep=sep[i]), result[i]) } }) test_that("autoSep", { for (i in seq(along=x)) { expect_identical(MALDIquantForeign:::.autoSep(textConnection(x[i])), sep[i]) } }) r-cran-maldiquantforeign/inst/tests/test_importCiphergenXml-functions.R0000644000175000017500000000115412221046771027027 0ustar rusconirusconicontext("importCiphergenXml") test_that("importCiphergenXml", { expect_error(MALDIquantForeign:::.importCiphergenXml("tmp.tmp")) path <- file.path("data", "ciphergen", "tiny.xml") s <- MALDIquantForeign:::.importCiphergenXml(path) expect_equal(s, import(path)) expect_equal(s, importCiphergenXml(path)) expect_equal(s, import(path, type="ciph")) expect_equal(trunc(mass(s[[1]])), rep(26, 5)) expect_false(all(mass(s[[1]])[1] == mass(s[[1]]))) expect_equal(intensity(s[[1]]), 1:5) expect_equal(basename(metaData(s[[1]])$file), "tiny.xml") expect_equal(metaData(s[[1]])$name, "tiny example") }) r-cran-maldiquantforeign/inst/tests/test_exportTab-methods.R0000644000175000017500000000164512221046771024617 0ustar rusconirusconicontext("exportTab") m <- createMassSpectrum(mass=1:5, intensity=6:10) r <- data.frame(V1=1:5, V2=6:10) test_that("exportTab", { temp <- tempfile() MALDIquantForeign:::.exportTab(m, file=temp) ## didn't work on win-builder.r-project.org ## (but on local linux and windows install (both R 2.15.2) #expect_equivalent(tools::md5sum(temp), tools::md5sum(file.path("data", # "ascii.txt"))) expect_equal(read.table(temp), r) }) test_that("exportCsv", { temp <- tempfile() MALDIquantForeign:::.exportCsv(m, file=temp) ## didn't work on win-builder.r-project.org ## (but on local linux and windows install (both R 2.15.2) #expect_equivalent(tools::md5sum(temp), tools::md5sum(file.path("data", # "csv1.csv"))) colnames(r) <- c("mass", "intensity") expect_equal(read.csv(temp), r) }) r-cran-maldiquantforeign/inst/tests/test_exportMsd-methods.R0000644000175000017500000000403712221046771024632 0ustar rusconirusconicontext("exportMsd") m <- createMassSpectrum(mass=1:5, intensity=6:10, metaData=list(owner="OWNER", institution="INSTITUTION", instrument="INSTRUMENT")) p <- createMassPeaks(mass=4:5, intensity=9:10, snr=1:2) msd <- c( "", "", " ", " tmp.msd", " ", " ", " ", " ", " ", " ", " ", " ", " eJxjYACBD/YMEOAAoTigtACUFnEAADZ/Alw=", " eJxjYAABCQcwxSADpRWgtBKUVnEAAB9MAds=", " ", " ", " ", " ", " ", "") if (.Platform$endian == "big") { msd[13:14] <- c( " eJyz/8AABg4MUJoDSgtAaREIDQBExAJc", " eJxzkGAAAwcZKK0ApZWgtAqEBgArDgHb") } test_that("exportMsd", { tmp <- tempdir() MALDIquantForeign:::.exportMsd(m, file=file.path(tmp, "tmp.msd"), peaks=p) expect_equal(readLines(file.path(tmp, "tmp.msd"))[-c(4, 5)], msd[-c(4, 5)]) }) test_that("exportMsd,list", { tmp <- tempdir() spectra <- list(m, m) peaks <- list(p, p) MALDIquantForeign::exportMsd(spectra, path=tmp, force=TRUE, peaks=peaks) expect_equal(readLines(file.path(tmp, "1.msd"))[-c(4, 5)], msd[-c(4, 5)]) expect_equal(readLines(file.path(tmp, "2.msd"))[-c(4, 5)], msd[-c(4, 5)]) }) test_that(".createMsdTitle", { f <- file(file.path(tempdir(), "test.msd")) expect_true(MALDIquantForeign:::.createMsdTitle(f) == "test") close(f) }) r-cran-maldiquantforeign/inst/tests/test_compression-functions.R0000644000175000017500000000454412221046771025556 0ustar rusconirusconicontext("compression") z <- c("bz2", "bzip2", "gz", "lzma", "xz") e <- c("zip", z, paste("tar", z, sep="."), "tar", "txt", "mzML") f <- paste(letters[1:13], e, sep=".") test_that(".isCompressed", { expect_identical(MALDIquantForeign:::.isCompressed(f), c(rep(TRUE, 11), rep(FALSE, 3))) }) test_that(".isTar", { expect_identical(MALDIquantForeign:::.isTar(f), c(rep(FALSE, 6), rep(TRUE, 6), rep(FALSE, 2))) }) test_that(".isZip", { expect_identical(MALDIquantForeign:::.isZip(f), c(TRUE, rep(FALSE, 13))) }) test_that(".isPackedOrCompressed", { expect_identical(MALDIquantForeign:::.isPackedOrCompressed(f), c(rep(TRUE, 12), rep(FALSE, 2))) }) test_that(".uncompress supports single file compression by gunzip", { u <- MALDIquantForeign:::.uncompress(file.path("data", "compressed", "csv1.csv.gz")) f <- file.path("data", "csv1.csv") expect_identical(readLines(u), readLines(f)) }) test_that(".uncompress supports tar compression by untar", { u <- list.files(MALDIquantForeign:::.uncompress( file.path("data", "compressed", "csv.tar.gz")), recursive=TRUE, pattern="^.*\\.csv$", full.names=TRUE)[1] f <- file.path("data", "csv1.csv") expect_identical(readLines(u), readLines(f)) }) test_that(".uncompress supports zip compression by unzip", { u <- list.files(MALDIquantForeign:::.uncompress( file.path("data", "compressed", "csv.zip")), recursive=TRUE, pattern="^.*\\.csv$", full.names=TRUE)[1] f <- file.path("data", "csv1.csv") expect_identical(readLines(u), readLines(f)) }) test_that(".cleanupUncompressedTmpFiles works", { n <- list.files(file.path(tempdir(), "MALDIquantForeign_uncompress"), recursive=TRUE) expect_true(length(n) > 0) MALDIquantForeign:::.cleanupUncompressedTmpFiles() expect_false(file.exists(file.path(tempdir(), "MALDIquantForeign_uncompress"))) }) test_that("typical auto import", { f <- normalizePath(file.path("data", "compressed", "csv1.csv.gz")) s <- createMassSpectrum(mass=1:5, intensity=6:10) i <- import(f)[[1]] metaData(i) <- list() expect_identical(i, s) expect_false(file.exists(file.path(tempdir(), "MALDIquantForeign_uncompress"))) }) r-cran-maldiquantforeign/inst/tests/data/0000755000175000017500000000000012221046771020727 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/data/tiny1.mzML1.1.mzML0000644000175000017500000000673012221046771023700 0ustar rusconirusconi AAAAAAAA8D8AAAAAAAAAQAAAAAAAAAhAAAAAAAAAEEAAAAAAAAAUQA== AADAQAAA4EAAAABBAAAQQQAAIEE= AAAAAAAA8D8AAAAAAAAAQAAAAAAAAAhAAAAAAAAAEEAAAAAAAAAUQA== AAAAAAAAJEAAAAAAAAAiQAAAAAAAACBAAAAAAAAAHEAAAAAAAAAYQA== r-cran-maldiquantforeign/inst/tests/data/tiny_processed.ibd0000644000175000017500000000026012221046771024437 0ustar rusconirusconi4Vx4444Vx«ð?@@@@@@ @"@$@@@ @"@$@$@"@ @@@r-cran-maldiquantforeign/inst/tests/data/ascii.txt0000644000175000017500000000002512221046771022555 0ustar rusconirusconi1 6 2 7 3 8 4 9 5 10 r-cran-maldiquantforeign/inst/tests/data/compressed/0000755000175000017500000000000012221046771023073 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/data/compressed/csv.zip0000644000175000017500000000031612221046771024412 0ustar rusconirusconiPK ÄbXBîv…¸((csv1.csvUT ß÷)Qß÷)Qux èè"mass","intensity" 1,6 2,7 3,8 4,9 5,10 PK ÄbXBîv…¸((¤csv1.csvUTß÷)Qux èèPKNjr-cran-maldiquantforeign/inst/tests/data/compressed/csv.tar.gz0000644000175000017500000000023512221046771025015 0ustar rusconirusconi‹kŒ/Qíα Â0ÆñÎyŠ’9H®MS}œX:d°ƒ ¾½t§"Âÿ·|ÇÝ ß¤«ì&]› ù*†pOÿšu–ÎGÇu/½ß´~ËRO-éܶÎǤ%§åÃß·ûŸ²§¤jÍK™Íåj¸h:7šÞíMp38ñæ×=ïn­…(r-cran-maldiquantforeign/inst/tests/data/compressed/csv1.csv.gz0000644000175000017500000000010512221046771025077 0ustar rusconirusconi‹¾ö)Qcsv1.csvSÊM,.VÒQÊÌ+IÍ+Î,©Tâ2Ô1ã2Ò1ç2Ö±à2ѱä2Õ14àîv…¸(r-cran-maldiquantforeign/inst/tests/data/tiny1.mzXML3.0.mzXML0000644000175000017500000000313412221046771024154 0ustar rusconirusconi P/AAAAAAAABAGAAAAAAAAEAAAAAAAAAAQBwAAAAAAABACAAAAAAAAEAgAAAAAAAAQBAAAAAAAABAIgAAAAAAAEAUAAAAAAAAQCQAAAAAAAA= 0 0 b87b09a4f34561d5572f9a6d30056106f819bc69 r-cran-maldiquantforeign/inst/tests/data/tiny1-compressed.mzML1.1.mzML0000644000175000017500000000665412221046771026047 0ustar rusconirusconi eJxjYACBD/YMEOAAoTigtACUFnEAADZ/Alw= eJxjYDjgwMDwAIgZHBkYBIBYwREAJcMDFA== eJxjYACBD/YMEOAAoTigtACUFnEAADZ/Alw= eJxjYAABFQcwxaAEpRWgtAyUlnAAACEsAds= r-cran-maldiquantforeign/inst/tests/data/tiny_processed.imzML0000644000175000017500000001235412221046771024740 0ustar rusconirusconi r-cran-maldiquantforeign/inst/tests/data/ciphergen/0000755000175000017500000000000012221046771022673 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/data/ciphergen/tiny.xml0000644000175000017500000000153512221046771024404 0ustar rusconirusconi tiny example 20000 2.5e+008 Quadratic 24000000 0.0013 0 20000 hand made 1 false 1 2 3 4 5 r-cran-maldiquantforeign/inst/tests/data/tiny_continuous.imzML0000644000175000017500000001235412221046771025157 0ustar rusconirusconi r-cran-maldiquantforeign/inst/tests/data/tiny_continuous.ibd0000644000175000017500000000021012221046771024651 0ustar rusconirusconi4Vx4444Vx«ð?@@@@@@ @"@$@$@"@ @@@r-cran-maldiquantforeign/inst/tests/data/csv2.csv0000644000175000017500000000002512221046771022316 0ustar rusconirusconi1;6 2;7 3;8 4;9 5;10 r-cran-maldiquantforeign/inst/tests/data/brukerflex/0000755000175000017500000000000012221046771023100 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/data/brukerflex/0_A1/0000755000175000017500000000000012221046771023560 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/data/brukerflex/0_A1/1/0000755000175000017500000000000012221046771023720 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/data/brukerflex/0_A1/1/1SLin/0000755000175000017500000000000012221046771024646 5ustar rusconirusconir-cran-maldiquantforeign/inst/tests/data/brukerflex/0_A1/1/1SLin/acqu0000644000175000017500000000071112221046771025521 0ustar rusconirusconi##.SPECTROMETER TYPE= TOF ##.IONIZATION MODE= LD+ ##$AQOP_m= 0 ##$BYTORDA= 0 ##$CMT1= TESTSAMPLE1 ##$CMT2= TESTSAMPLE2 ##$CMT3= TESTSAMPLE3 ##$CMT4= TESTSAMPLE4 ##$DELAY= 10000 ##$DW= 20 ##$HPClBHi= 0 ##$HPClBLo= 0 ##$HPClOrd= 0 ##$HPClUse= no ##$Lift1= 0 ##$Lift2= 0 ##$ML1= 2400000 ##$ML1_raw= 2400000 ##$ML2= 280 ##$ML2_raw= 280 ##$ML3= -0.0013 ##$ML3_raw= -0.0013 ##$NoSHOTS= 100 ##$SPType= 0 ##$TD= 5 ##$TLift= 0 r-cran-maldiquantforeign/inst/tests/data/brukerflex/0_A1/1/1SLin/fid0000644000175000017500000000002412221046771025327 0ustar rusconirusconir-cran-maldiquantforeign/inst/tests/data/tiny1-compressed.mzXML3.0.mzXML0000644000175000017500000000304412221046771026316 0ustar rusconirusconi eJyz/8AABg4SUJoBSstAaQ4orQClBaC0EpQWgdIqEBoA0joENg== 0 0 7e7ef0ea030f6a56d34a4ebd446e22b22844d432 r-cran-maldiquantforeign/inst/tests/data/csv1.csv0000644000175000017500000000005012221046771022313 0ustar rusconirusconi"mass","intensity" 1,6 2,7 3,8 4,9 5,10 r-cran-maldiquantforeign/inst/tests/test_exportMzMl-methods.R0000644000175000017500000001067512221046771024773 0ustar rusconirusconicontext("exportMzMl") m <- createMassSpectrum(mass=1:5, intensity=6:10, metaData=list(name="TEST", file="TESTS/fid")) mzML <- c( "", "", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", paste0(" "), " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " eJxjYACBD/YMEOAAoTigtACUFnEAADZ/Alw=", " ", " ", " ", " ", " ", " eJxjYAABCQcwxSADpRWgtBKUVnEAAB9MAds=", " ", " ", " ", " ", " ", "") test_that("exportMzMl", { tmp <- tempdir() MALDIquantForeign:::.exportMzMl(m, file=file.path(tmp, "tmp.mzML")) expect_equal(readLines(file.path(tmp, "tmp.mzML")), mzML) g <- readLines(file.path(tmp, "tmp.mzML")) }) test_that("exportMzMl,list", { tmp <- tempdir() spectra <- list(m, m) MALDIquantForeign::exportMzMl(spectra, path=tmp, force=TRUE) expect_equal(readLines(file.path(tmp, "TESTS_1.mzML")), sub(pattern="id=\"tmp\"", replacement="id=\"TESTS_1\"", x=mzML)) expect_equal(readLines(file.path(tmp, "TESTS_2.mzML")), sub(pattern="id=\"tmp\"", replacement="id=\"TESTS_2\"", x=mzML)) }) r-cran-maldiquantforeign/inst/tests/test_importImzMl-functions.R0000644000175000017500000000230112221046771025465 0ustar rusconirusconicontext("importImzMl") test_that("importImzMl continuous", { expect_error(MALDIquantForeign:::.importImzMl("tmp.tmp")) path <- normalizePath(file.path("data", "tiny_continuous.imzML")) s <- MALDIquantForeign:::.importImzMl(path) expect_equal(s, import(path)) expect_equal(s, importImzMl(path)) expect_equal(s, import(path, type="imzML")) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "tiny_continuous.imzML") expect_equal(mass(s[[2]]), 1:5) expect_equal(intensity(s[[2]]), 10:6) expect_equal(basename(metaData(s[[2]])$file), "tiny_continuous.imzML") }) test_that("importMzMl processed", { path <- normalizePath(file.path("data", "tiny_processed.imzML")) s <- MALDIquantForeign:::.importImzMl(path) expect_equal(s, import(path)) expect_equal(s, importImzMl(path)) expect_equal(s, import(path, type="imzML")) expect_equal(mass(s[[1]]), 1:5) expect_equal(intensity(s[[1]]), 6:10) expect_equal(basename(metaData(s[[1]])$file), "tiny_processed.imzML") expect_equal(mass(s[[2]]), 6:10) expect_equal(intensity(s[[2]]), 10:6) expect_equal(basename(metaData(s[[2]])$file), "tiny_processed.imzML") }) r-cran-maldiquantforeign/inst/tests/test_filename-functions.R0000644000175000017500000000346312221046771024774 0ustar rusconirusconicontext("filename") test_that(".cleanFilename", { expect_identical(MALDIquantForeign:::.cleanFilename( "/home/a:/\"foo&bar\"/g.\\23!/ foo-bar?.txt"), "_home_a_foo_bar_g_23_foo_bar_txt") }) test_that("file extension is returned", { expect_identical(MALDIquantForeign:::.fileExtension("~/foo.txt"), "txt") expect_identical(MALDIquantForeign:::.fileExtension( c("/etc/a.conf", "b.pdf")), c("conf", "pdf")) }) test_that("file name is returned", { expect_identical(MALDIquantForeign:::.fileExtension("~/foo"), "foo") }) test_that("path without extension is returned", { expect_identical(MALDIquantForeign:::.withoutFileExtension( c("~/foo", "/home/user/xyz.tar.gz", "/tmp/bar.txt")), c("~", "/home/user/xyz", "/tmp/bar")) }) test_that(".cutFilenames", { expect_identical(MALDIquantForeign:::.cutFilenames( c("/home/user/foo.bar", "/home/user/xyz.tar.gz")), c("foo.bar", "xyz.tar.gz")) expect_identical(MALDIquantForeign:::.cutFilenames( c("/home/user/foo.bar", "/home/user/foo.bar")), c("foo.bar", "foo.bar")) }) test_that(".uniqueBaseFilenames", { expect_identical(MALDIquantForeign:::.uniqueBaseFilenames( c("/home/user/foo.bar", "/home/user/foo.bar"), fileExtension="txt"), c("foo_1.txt", "foo_2.txt")) }) test_that(".make.unique", { expect_equal(MALDIquantForeign:::.make.unique(LETTERS[1:5]), LETTERS[1:5]) expect_equal(MALDIquantForeign:::.make.unique(rep(LETTERS[1:5], each=2)), paste(rep(LETTERS[1:5], each=2), 1:2, sep="_")) expect_equal(MALDIquantForeign:::.make.unique(rep(LETTERS[1:2], each=10)), sprintf("%s_%02d", rep(LETTERS[1:2], each=10), 1:10)) }) r-cran-maldiquantforeign/inst/tests/test_importBrukerFlex-functions.R0000644000175000017500000000116612221046771026516 0ustar rusconirusconicontext("importBrukerFlex") test_that("importBrukerFlex", { expect_error(MALDIquantForeign:::.importBrukerFlex("tmp.tmp")) path <- file.path("data", "brukerflex", "0_A1", "1", "1SLin", "fid") s <- MALDIquantForeign:::.importBrukerFlex(path) expect_equal(s, import(path)) expect_equal(s, importBrukerFlex(path)) expect_equal(s, import(path, type="fid")) expect_equal(trunc(mass(s[[1]])), 226:230) expect_equal(intensity(s[[1]]), 1:5) expect_equal(basename(metaData(s[[1]])$file), "fid") expect_equal(metaData(s[[1]])$laserShots, 100) expect_equal(metaData(s[[1]])$comments, paste0("TESTSAMPLE", 1:4)) }) r-cran-maldiquantforeign/MD50000644000175000017500000001226412221046771016214 0ustar rusconirusconi40c54c0e29bb462ca28ab40f257be6f0 *DESCRIPTION 03cabecfa0de4530d9b83ddca18e68ec *NAMESPACE 5bc8da30470fd184bee918bb78ae67b0 *NEWS 2909cdfd48e0a659215fb823fb4ee6a0 *R/AllGenerics.R d0d6f8ccc25d5156fe35335bbf2d040d *R/analyze-functions.R d8112fff8aa9c294f320fe85a5f16a1e *R/base64encode-functions.R 56ff0561b408289ff72ba9159627c70e *R/compression-functions.R 963126ae68feaf16644682cd5b754ac4 *R/download-function.R 9dd9d7d23b59bce7b233cc787b191768 *R/export-functions.R dee86942840b3298f84f50e0fa8606b1 *R/export-methods.R 199f16e5d272ac2d60c571389e64cb7c *R/exportMsd-methods.R f73f4cc76e62d9a94c75196d9c51a32b *R/exportMzMl-methods.R 7240fda493581d8f8bf10ea95b236862 *R/exportTab-methods.R 4c72c9f3c7e68f5f51cfbcb68b7a4933 *R/fileFormats.R 8f6abf32d257b78dc7152fe0e8f5f9c8 *R/filename-functions.R d8ebaf9ac00edb4643516b10369d55be *R/filename-methods.R 8b2e446d25b63cd1f7f762c9c49f4a6d *R/import-functions.R d45c1cb2067a02fb07bbb9f2279ccfde *R/importAnalyze-functions.R 97db31a06d6b538d23dcc8432d240f48 *R/importAuto-functions.R 4e5417378792e5b6ea0406de3449b6f6 *R/importBrukerFlex-functions.R 30b685e855e6682e2c9c7253f33e2731 *R/importCiphergenXml-functions.R e0325b54b340dd8f6cba2ae1ece84665 *R/importImzMl-functions.R 97aae20bf09e4cd6144ad6f640316a8b *R/importMzMl-functions.R 80c6b7389bc61f4e74f8bae14aaaeb91 *R/importMzXml-functions.R bf4e141a771aad69c271df41ce48ea9c *R/importTab-functions.R e1461b5fbb9c7883b89f813b6e343968 *R/list.files-functions.R 48dbf06d13cd3fc87442cb82561364f8 *R/msd-functions.R 267c9b630c734ef3aa1dfb8bb4e9e0b4 *R/mzMl-functions.R f31c1f71601be8c111c74b5dcf9229a4 *R/package.R 6a89ddd05095a15d0965b39aae05cdbd *R/parseCiphergenXml.R a9568321bb384d3105b34dd16d5465e9 *R/parseMzMl.R b5189169e03a3ae8150047e0215f40a7 *R/sanitize-functions.R a4b92b6f309e60be3af2363e2066f47c *R/xml-functions.R 9274dd34d675950326a222a952309a17 *inst/tests/data/ascii.txt 85077ca13692b5a2469af51d18cffd64 *inst/tests/data/brukerflex/0_A1/1/1SLin/acqu fe054ad2e7b98bee673f9ff22d50f00c *inst/tests/data/brukerflex/0_A1/1/1SLin/fid 10e9d68aa23b1d7b85688a969be41897 *inst/tests/data/ciphergen/tiny.xml 9f3dad6df2b7d1b0e7484d56efb135b1 *inst/tests/data/compressed/csv.tar.gz 5e7f66c3581914b38f2510a5cb81b817 *inst/tests/data/compressed/csv.zip c967aa9538fd9d26a4463503a0d5ca0e *inst/tests/data/compressed/csv1.csv.gz 5101c57f3848a853326e4aac514ee494 *inst/tests/data/csv1.csv 4b2a03f6bbe5747bd50273be357533c1 *inst/tests/data/csv2.csv 4cabaefc8fe6d8f1bd0f55a9ba06e763 *inst/tests/data/tiny1-compressed.mzML1.1.mzML 09be2b7fff0d1834938d4aebaab4761c *inst/tests/data/tiny1-compressed.mzXML3.0.mzXML 489b1be67d30d175969dbb66f8bcb9b7 *inst/tests/data/tiny1.mzML1.1.mzML 3b8bd26f7fc636e57388d52b3f9f3eb7 *inst/tests/data/tiny1.mzXML3.0.mzXML 5e796bc727641cf2be616176940d3644 *inst/tests/data/tiny_continuous.ibd c7dc5215856e426a59c5b49a3480371c *inst/tests/data/tiny_continuous.imzML 065ae1dbeb21aada540e6a5436fd6e55 *inst/tests/data/tiny_processed.ibd 5e119389bbd61d7143989d94253d7771 *inst/tests/data/tiny_processed.imzML 2d789503655e48983981146c041d304e *inst/tests/test_compression-functions.R 45d987b436aed14db6070090560e48b2 *inst/tests/test_download-functions.R 365f33d698bc51d4805a20f4aa6c1bf2 *inst/tests/test_exportMsd-methods.R 5f2bf75a41afc12a65e213e5d6e2088c *inst/tests/test_exportMzMl-methods.R 5dbbcb5c4bde39a27e7f4da831a41ca2 *inst/tests/test_exportTab-methods.R 78922514cb74d182e1f5d2eb32795b32 *inst/tests/test_filename-functions.R 587b600f50b462d5bbe4a8e7ecc53b09 *inst/tests/test_importBrukerFlex-functions.R a26358000373b01eee4df9d69645c9ec *inst/tests/test_importCiphergenXml-functions.R 5955b9a5514991eb0dd7a7fde191704b *inst/tests/test_importImzMl-functions.R 364645b250bce09eb83fada362fc2245 *inst/tests/test_importMzMl-functions.R b31747da6cd4096dcb1a2087fd8722b8 *inst/tests/test_importMzXml-functions.R 3d7ae86c319b0e7c557ab88050c9cb7c *inst/tests/test_importTab-functions.R 2b2a91c03508aefeb1b2c31a851a2640 *inst/tests/test_sanitize-functions.R 4b5e2b35fd0d7914601a918fa0397c35 *man/MALDIquantForeign-package.Rd 8c24c4b353c2a734038dfe678dae0cda *man/base64-encode.Rd c398b71a075deb170448411197161b4c *man/cleanFilename.Rd efceb95477aacf2c5742f51292324216 *man/composeFilename-methods.Rd 2ae2661d625b11c154995ed85b653082 *man/export-methods.Rd 45befd15c3a645941f97dc468dc987f9 *man/exportMsd-methods.Rd 9d599961b055e8397395898b3b4f158a *man/exportMzMl-methods.Rd 4881deff5152200ee21c7e3d5a8961e6 *man/exportTab-methods.Rd 8d7adbfb3c6ddf7116b2a9b7b55a73c3 *man/fileExtension.Rd 4260e6dd2a31976780bcc0f8b56a8187 *man/import-functions.Rd 962343a3056870ff29fd21365ad5fb9c *man/importAnalyze-functions.Rd 02abd2b65447a323e50b8483e1e3b468 *man/importBrukerFlex-functions.Rd 70d6827e4bf4827b966195949a1801eb *man/importCiphergenXml-functions.Rd 225d2238a125ca03839ab1d58345c8f1 *man/importImzMl-functions.Rd ab68f18808b02b50b8437b0c4064448f *man/importMzMl-functions.Rd 02ee26ef62a0ff1ddf8eaf270ca07134 *man/importMzXml-functions.Rd 21ec20b7cff72653706b058d9399a351 *man/importTab-functions.Rd bc1ba144e4c677b4d398e4743f8ab6bc *man/mzMlHandlers.Rd d284929803bc96de3ea0da4d4ae538ca *man/parseCiphergenXml.Rd 16fcffd8f94ed61b51d8032a94e9ff53 *man/parseMzMl.Rd 808dce57a33cb0153b642f839ff1fb63 *man/supportedFileFormats-functions.Rd badb2c09c2c1c042bc7e9799ed963624 *tests/test_all.R r-cran-maldiquantforeign/tests/0000755000175000017500000000000012221046771017041 5ustar rusconirusconir-cran-maldiquantforeign/tests/test_all.R0000644000175000017500000000006612221046771020775 0ustar rusconirusconilibrary("testthat") test_package("MALDIquantForeign") r-cran-maldiquantforeign/NEWS0000644000175000017500000000403312221046771016376 0ustar rusconirusconiRELEASE HISTORY OF THE "MALDIquantForeign" PACKAGE ================================================== Version 0.5.1 [2013-09-18]: - Replace MALDIquant:::isMassSpectrum by MALDIquant::isMassSpectrum. - Replace deprecated function isMassObjectList. Version 0.5 [2013-09-08]: - import*: add "excludePattern" argument to avoid import of specific files; closes #8. - Fix totalIonCurrent test case. - Add import("methods") to NAMESPACE (fixes #9). - Update dependencies; now MALDIquantForeign depends on R 3.0.0. - Replace all paste(..., sep="") by paste0. Version 0.4 [2013-04-28]: - Add basic import support for imzML files and Analyze 7.5 files. - import: add removeEmptySpectra argument; closes #7. - import: change default argument verbose to TRUE. - .download: respects "verbose" argument now (fixes #6). - Remove LICENSE file. Version 0.3 [2013-03-01]: - Add basic support for mzML export. - Add basic import support for Ciphergen XML files. - Add missing "usage" section in export methods manual pages. - import: add http(s):// and ftp:// support. - import: add uncompression support to allow import of zip/tar.{gz,bz2,xz}-archives. - .files: returns only unique file names; affected functions: all import functions. - .make.unique: generates c("a1", "a2") instead of c("a", "a1") and c("a001", ..., "a099", "a100") instead of c("a", ..., "a98", "a99"); affected method: export,list. - DESCRIPTION: move base64enc, digest, readBrukerFlexData, readMzXmlData and XML to "Imports". - DESCRIPTION: remove MALDIquant from the "Imports" field. Version 0.2 [2013-01-14]: - export: fix empty filenames. - export,list: stop if directory doesn't exist. - exportMsd: complete rewrite, write xml files manually instead of using the XML package (increasing speed). - exportMsd: fix peaks argument. - exportMsd tests: respect endianness. - import: respect verbose argument in import(type=auto). Version 0.1 [2012-12-10]: - First public release. - Supported file formats: - Import: tab, txt, csv, Bruker Daltonics *flex files, mzXML, mzML - Export: tab, csv, msd r-cran-maldiquantforeign/NAMESPACE0000644000175000017500000000126112221046771017116 0ustar rusconirusconiexport(import) export(importAnalyze) export(importBrukerFlex) export(importCiphergenXml) export(importCsv) export(importImzMl) export(importMzMl) export(importMzXml) export(importTab) export(importTxt) export(supportedFileFormats) exportMethods(export) exportMethods(exportCsv) exportMethods(exportMsd) exportMethods(exportMzMl) exportMethods(exportTab) import(MALDIquant) import(methods) import(readMzXmlData) importFrom(XML,xmlEventParse) importFrom(XML,xmlParse) importFrom(XML,xmlValue) importFrom(XML,xpathApply) importFrom(XML,xpathSApply) importFrom(base64enc,base64encode) importFrom(digest,digest) importFrom(downloader,download) importFrom(readBrukerFlexData,readBrukerFlexFile) r-cran-maldiquantforeign/DESCRIPTION0000644000175000017500000000337512221046771017415 0ustar rusconirusconiPackage: MALDIquantForeign Version: 0.5.1 Date: 2013-09-18 Title: Import/Export routines for MALDIquant Authors@R: c(person("Sebastian", "Gibb", role=c("aut", "cre"), email="mail@sebastiangibb.de")) Depends: R (>= 3.0.0), methods, MALDIquant (>= 1.8) Imports: base64enc, digest, downloader, readBrukerFlexData (>= 1.7), readMzXmlData (>= 2.7), XML Suggests: testthat Description: This package allows to read (tab, csv, Bruker fid, Ciphergen XML, mzXML, mzML, imzML, Analyze 7.5) and write (tab, csv, msd, mzML) different file formats of mass spectrometry data into/from MALDIquant objects. License: GPL (>= 3) URL: http://strimmerlab.org/software/maldiquant/ https://github.com/sgibb/MALDIquantForeign/ BugReports: https://github.com/sgibb/MALDIquantForeign/issues/ LazyLoad: yes Collate: 'package.R' 'AllGenerics.R' 'base64encode-functions.R' 'export-methods.R' 'exportMsd-methods.R' 'exportTab-methods.R' 'fileFormats.R' 'filename-functions.R' 'filename-methods.R' 'importAuto-functions.R' 'importBrukerFlex-functions.R' 'import-functions.R' 'importMzMl-functions.R' 'importMzXml-functions.R' 'importTab-functions.R' 'list.files-functions.R' 'msd-functions.R' 'parseMzMl.R' 'sanitize-functions.R' 'xml-functions.R' 'mzMl-functions.R' 'export-functions.R' 'exportMzMl-methods.R' 'importCiphergenXml-functions.R' 'parseCiphergenXml.R' 'compression-functions.R' 'download-function.R' 'importImzMl-functions.R' 'analyze-functions.R' 'importAnalyze-functions.R' Packaged: 2013-09-18 16:50:16 UTC; sebastian Author: Sebastian Gibb [aut, cre] Maintainer: Sebastian Gibb NeedsCompilation: no Repository: CRAN Date/Publication: 2013-09-18 19:55:07 r-cran-maldiquantforeign/R/0000755000175000017500000000000012221046771016100 5ustar rusconirusconir-cran-maldiquantforeign/R/importTab-functions.R0000644000175000017500000000351212221046771022173 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .importTab <- function(file, verbose=FALSE, ...) { ## load ms file s <- read.table(file=file, ...) return(list(createMassSpectrum(mass=s[, 1], intensity=s[, 2], metaData=list(file=file)))) } #' @keywords internal .importCsv <- function(file, verbose=FALSE, sep=.autoSep(file), header=.autoHeader(file, sep), ...) { return(.importTab(file=file, verbose=verbose, sep=sep, header=header, ...)) } #' @keywords internal .autoHeader <- function(file, sep="\t") { l <- readLines(file, n=1) l <- gsub(pattern='[\\\\"]*', replacement="", x=l) l <- strsplit(l, split=sep)[[1]][1] return(!is.numeric(type.convert(l, as.is=TRUE))) } #' @keywords internal .autoSep <- function(file, sep=c(",", ";", "\t")) { l <- readLines(file, n=1) pattern <- paste0(".+", sep, ".+") i <- vapply(pattern, function(x) { g <- gregexpr(pattern=x, text=l)[[1]] return(all(g > 0) & length(g) == 1) }, logical(1)) if (any(i)) { return(sep[i]) } else { return(sep[1]) } } r-cran-maldiquantforeign/R/filename-functions.R0000644000175000017500000000632712221046771022021 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' This function removes spaces and punctuations from filenames. #' #' @return filename #' #' @keywords internal #' @rdname cleanFilename .cleanFilename <- function(x) { return(gsub(pattern="([[:punct:]]|[[:space:]])+", replacement="_", x=x)) } #' Determine file extension #' #' @param x \code{character}, filename. #' #' @return \code{character}, file extension. #' #' @seealso \code{\link[MALDIquant]{MassSpectrum-class}} #' @keywords internal #' @rdname fileExtension #' @examples #' library("MALDIquantForeign") #' files <- c("/home/foo/bar.txt", "foobar.pdf") #' MALDIquantForeign:::.fileExtension(files) #' .fileExtension <- function(x) { pos <- regexpr(pattern="(\\.tar)?\\.([[:alnum:]]+)$|(/|\\\\)+[^.\\\\/]+$", text=x) return(ifelse(pos > -1L, substring(x, pos+1L), x)) } #' @keywords internal .withoutFileExtension <- function(x) { return(sub(pattern="\\.[[:alnum:]]+?$|(/|\\\\)+[^.\\\\/]+$", replacement="", x=.withoutCompressionExtension(x))) } #' @keywords internal .withoutCompressionExtension <- function(x) { return(sub(pattern="\\.(zip|gz|bz2|bzip2|xz|lzma)+$", replacement="", x=x)) } #' @keywords internal .cutFilenames <- function(x) { l <- strsplit(x, split=.Platform$file.sep, fixed=TRUE) nCol <- unlist(lapply(l, length)) mCol <- max(nCol) m <- matrix(NA, nrow=length(x), ncol=mCol) for (i in seq(along=l)) { cols <- 1:nCol[i] m[i, cols] <- l[[i]] } isIdentical <- apply(m, 2, function(co)all(co[1] == co)) isIdentical[is.na(isIdentical)] <- FALSE m <- as.matrix(m[, !isIdentical]) if (length(m)) { filenames <- apply(m, 1, function(r) { do.call(file.path, as.list(na.omit(r))) }) } else { filenames <- basename(x) } return(filenames) } #' @keywords internal .uniqueBaseFilenames <- function(x, fileExtension="csv", sep="_") { filenames <- .cutFilenames(.withoutFileExtension(x)) filenames <- .cleanFilename(filenames) empty <- nchar(filenames) <= 0 filenames[empty] <- seq_along(empty) filenames <- .make.unique(filenames, sep=sep) return(paste(filenames, fileExtension, sep=".")) } #' @keywords internal ## let make unique start by 1 .make.unique <- function(x, sep="_") { tmp <- lapply(split(x, x), function(y) { n <- length(y) if (n > 1) { fmt <- paste0("%s%s%0", floor(log10(n))+1, "d") y <- sprintf(fmt=fmt, y, sep, 1:n) } return(y) }) return(unsplit(tmp, x)) } r-cran-maldiquantforeign/R/export-methods.R0000644000175000017500000002711412221046771021212 0ustar rusconirusconi## Copyright 2012-2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' Export files #' #' This function provides a general interface to export #' \code{\link[MALDIquant]{AbstractMassObject-class}} objects (e.g. #' \code{\link[MALDIquant]{MassSpectrum-class}}, #' \code{\link[MALDIquant]{MassPeaks-class}}) #' into different file formats. #' #' @details #' Specific export functions: #' \tabular{ll}{ #' tab \tab \code{\link[MALDIquantForeign]{exportTab}} \cr #' csv \tab \code{\link[MALDIquantForeign]{exportCsv}} \cr #' msd \tab \code{\link[MALDIquantForeign]{exportMsd}} \cr #' mzML \tab \code{\link[MALDIquantForeign]{exportMzMl}} \cr #' } #' #' @usage #' \S4method{export}{AbstractMassObject}(x, file, type="auto", force=FALSE, \ldots) #' #' @param x a \code{\link[MALDIquant]{AbstractMassObject-class}} object or a #' \code{list} of \code{\link[MALDIquant]{AbstractMassObject-class}} objects. #' @param file \code{character}, file name. #' @param path \code{character}, path to directory in which the \code{list} of #' \code{\link[MALDIquant]{AbstractMassObject-class}} would be exported. #' @param type \code{character}, file format. If \code{type} is set to #' \dQuote{auto} the file extension is used. #' @param force \code{logical}, If \code{TRUE} the \code{file} would be #' overwritten or \code{path} would be created. #' @param \ldots arguments to be passed to specific export functions. #' #' @seealso #' \code{\link[MALDIquant]{MassPeaks-class}}, #' \code{\link[MALDIquant]{MassSpectrum-class}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/} #' @examples #' #' \dontrun{ #' library("MALDIquant") #' library("MALDIquantForeign") #' #' s <- list(createMassSpectrum(mass=1:5, intensity=1:5), #' createMassSpectrum(mass=1:5, intensity=1:5)) #' #' ## export a single spectrum #' export(s[[1]], file="spectrum.csv") #' ## identical to exportCsv(s[[1]], file="spectrum.csv") #' #' ## export a list of spectra #' export(s, path="spectra", type="csv") #' ## identical to exportCsv(s, path="spectra") #' } #' #' @aliases export export,AbstractMassObject-method export,list-method #' @rdname export-methods #' @docType methods #' @export setMethod(f="export", signature=signature(x="AbstractMassObject"), definition=function(x, file, type="auto", force=FALSE, ...) { return(.exportToFile(x=x, file=file, type=type, force=force, ...)) }) #' @usage #' \S4method{export}{list}(x, path, type, force=FALSE, \ldots) #' @rdname export-methods #' @export setMethod(f="export", signature=signature(x="list"), definition=function(x, path, type, force=FALSE, ...) { stopifnot(MALDIquant:::.isMassObjectList(x)) onefileSupport <- exportFormats$type[exportFormats$onefile] isFile <- (missing(type) && tolower(.fileExtension(path)) %in% onefileSupport) if (isFile) { return(.exportToFile(x=x, file=path, type=type, force=force, ...)) } else { return(.exportToDir(x=x, path=path, type=type, force=force, ...)) } }) #' Export to text files #' #' This function exports #' \code{\link[MALDIquant]{AbstractMassObject-class}} objects (e.g. #' \code{\link[MALDIquant]{MassSpectrum-class}}, #' \code{\link[MALDIquant]{MassPeaks-class}}) #' into different text file formats. #' #' @details #' \code{exportTab} and \code{exportCsv} use \code{\link[utils]{write.table}} #' with different defaults (\code{sep="\t"} in \code{exportTab} and #' \code{sep=","} in \code{exportCsv}). #' #' @usage #' \S4method{exportTab}{AbstractMassObject}(x, file, force=FALSE, \ldots) #' #' @param x a \code{\link[MALDIquant]{AbstractMassObject-class}} object or a #' \code{list} of \code{\link[MALDIquant]{AbstractMassObject-class}} objects. #' @param file \code{character}, file name. #' @param path \code{character}, path to directory in which the \code{list} of #' \code{\link[MALDIquant]{AbstractMassObject-class}} would be exported. #' @param force \code{logical}, If \code{TRUE} the \code{file} would be #' overwritten or \code{path} would be created. #' @param \ldots arguments to be passed to \code{\link[utils]{write.table}}. #' #' @seealso #' \code{\link[MALDIquant]{MassPeaks-class}}, #' \code{\link[MALDIquant]{MassSpectrum-class}}, #' \code{\link[utils]{write.table}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/} #' @examples #' #' \dontrun{ #' library("MALDIquant") #' library("MALDIquantForeign") #' #' s <- list(createMassSpectrum(mass=1:5, intensity=1:5), #' createMassSpectrum(mass=1:5, intensity=1:5)) #' #' ## export a single spectrum #' exportTab(s[[1]], file="spectrum.tab") #' #' ## export a list of spectra and use ; as separator #' exportCsv(s, path="spectra", sep=";", force=TRUE) #' } #' #' @aliases exportTab exportTab,AbstractMassObject-method exportTab,list-method #' exportCsv exportCsv,AbstractMassObject-method exportCsv,list-method #' @rdname exportTab-methods #' @docType methods #' @export setMethod(f="exportTab", signature=signature(x="AbstractMassObject"), definition=function(x, file, force=FALSE, ...) { export(x, file=file, type="tab", force=force, ...) }) #' @usage #' \S4method{exportTab}{list}(x, path, force=FALSE, \ldots) #' @rdname exportTab-methods #' @export setMethod(f="exportTab", signature=signature(x="list"), definition=function(x, path, force=FALSE, ...) { export(x, path=path, type="tab", force=force, ...) }) #' @usage #' \S4method{exportCsv}{AbstractMassObject}(x, file, force=FALSE, \ldots) #' @rdname exportTab-methods #' @export setMethod(f="exportCsv", signature=signature(x="AbstractMassObject"), definition=function(x, file, force=FALSE, ...) { export(x, file=file, type="csv", force=force, ...) }) #' @usage #' \S4method{exportCsv}{list}(x, path, force=FALSE, \ldots) #' @rdname exportTab-methods #' @export setMethod(f="exportCsv", signature=signature(x="list"), definition=function(x, path, force=FALSE, ...) { export(x, path=path, type="csv", force=force, ...) }) #' Export to MSD files #' #' This function exports #' \code{\link[MALDIquant]{AbstractMassObject-class}} objects (e.g. #' \code{\link[MALDIquant]{MassSpectrum-class}}, #' \code{\link[MALDIquant]{MassPeaks-class}}) #' into mMass MSD files. #' #' @usage #' \S4method{exportMsd}{MassSpectrum}(x, file, force=FALSE, peaks, \ldots) #' #' @param x a \code{\link[MALDIquant]{MassSpectrum-class}} object or a #' \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' @param file \code{character}, file name. #' @param path \code{character}, path to directory in which the \code{list} of #' \code{\link[MALDIquant]{AbstractMassObject-class}} would be exported. #' @param peaks a \code{\link[MALDIquant]{MassPeaks-class}} object or a #' \code{list} of \code{\link[MALDIquant]{MassPeaks-class}} objects. #' @param force \code{logical}, If \code{TRUE} the \code{file} would be #' overwritten or \code{path} would be created. #' @param \ldots arguments to be passed to \code{\link[utils]{write.table}}. #' #' @seealso #' \code{\link[MALDIquant]{MassPeaks-class}}, #' \code{\link[MALDIquant]{MassSpectrum-class}} #' #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/}, \cr #' mMass homepage: \url{http://mmass.org/} #' @examples #' #' \dontrun{ #' library("MALDIquant") #' library("MALDIquantForeign") #' #' s <- list(createMassSpectrum(mass=1:5, intensity=1:5), #' createMassSpectrum(mass=1:5, intensity=1:5)) #' p <- list(createMassPeaks(mass=4:5, intensity=4:5, snr=1:2), #' createMassPeaks(mass=4:5, intensity=4:5, snr=1:2)) #' #' ## export a single spectrum #' exportMsd(s[[1]], file="spectrum.msd") #' #' ## export a single spectrum with corresponding peaks #' exportMsd(s[[1]], file="spectrum.msd", peaks=p[[1]]) #' #' ## export a list of spectra with corresponding peaks #' exportMsd(s, path="spectra", peaks=p, force=TRUE) #' } #' #' @aliases exportMsd exportMsd,MassSpectrum-method exportMsd,list-method #' @rdname exportMsd-methods #' @docType methods #' @export setMethod(f="exportMsd", signature=signature(x="MassSpectrum"), definition=function(x, file, force=FALSE, peaks, ...) { if (!missing(peaks)) { stopifnot(isMassPeaks(peaks)) export(x, file=file, type="msd", force=force, peaks=peaks, ...) } else { export(x, file=file, type="msd", force=force, ...) } }) #' @usage #' \S4method{exportMsd}{list}(x, path, force=FALSE, peaks, \ldots) #' @rdname exportMsd-methods #' @export setMethod(f="exportMsd", signature=signature(x="list"), definition=function(x, path, force=FALSE, peaks, ...) { stopifnot(isMassSpectrumList(x)) if (!missing(peaks)) { stopifnot(isMassPeaksList(peaks)) export(x, path=path, type="msd", force=force, peaks=peaks, ...) } else { export(x, path=path, type="msd", force=force, ...) } }) #' Export to mzML files #' #' This function exports #' \code{\link[MALDIquant]{AbstractMassObject-class}} objects (e.g. #' \code{\link[MALDIquant]{MassSpectrum-class}}, #' \code{\link[MALDIquant]{MassPeaks-class}}) #' into mzML files. #' #' @usage #' \S4method{exportMzMl}{MassSpectrum}(x, file, force=FALSE, \ldots) #' #' @param x a \code{\link[MALDIquant]{MassSpectrum-class}} object or a #' \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' @param file \code{character}, file name. #' @param path \code{character}, path to directory in which the \code{list} of #' \code{\link[MALDIquant]{AbstractMassObject-class}} would be exported. #' @param force \code{logical}, If \code{TRUE} the \code{file} would be #' overwritten or \code{path} would be created. #' @param \ldots arguments to be passed to \code{\link[utils]{write.table}}. #' #' @seealso #' \code{\link[MALDIquant]{MassPeaks-class}}, #' \code{\link[MALDIquant]{MassSpectrum-class}} #' #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/}, \cr #' HUPO Proteomics Standards Inititative mzML 1.1.0 Specification: #' \url{http://www.psidev.info/mzml_1_0_0} #' @examples #' #' \dontrun{ #' library("MALDIquant") #' library("MALDIquantForeign") #' #' s <- list(createMassSpectrum(mass=1:5, intensity=1:5), #' createMassSpectrum(mass=1:5, intensity=1:5)) #' #' ## export a single spectrum #' exportMzMl(s[[1]], file="spectrum.mzML") #' #' ## export a list of spectra with corresponding peaks #' exportMzMl(s, path="spectra.mzMl") #' } #' #' @aliases exportMzMl exportMzMl,MassSpectrum-method exportMzMl,list-method #' @rdname exportMzMl-methods #' @docType methods #' @export setMethod(f="exportMzMl", signature=signature(x="MassSpectrum"), definition=function(x, file, force=FALSE, ...) { export(x, file=file, type="mzml", force=force, ...) }) #' @usage #' \S4method{exportMzMl}{list}(x, path, force=FALSE, \ldots) #' @rdname exportMzMl-methods #' @export setMethod(f="exportMzMl", signature=signature(x="list"), definition=function(x, path, force=FALSE, ...) { export(x, path=path, type="mzml", force=force, ...) }) r-cran-maldiquantforeign/R/export-functions.R0000644000175000017500000000504012221046771021551 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see .exportToFile <- function(x, file, type="auto", force=FALSE, ...) { if (file.exists(file) && !force) { stop("File already exists! Use ", sQuote("force=TRUE"), " to overwrite it.") } if (missing(type) || pmatch(tolower(type), "auto", nomatch=0, duplicates.ok=FALSE)) { type <- .fileExtension(file) } i <- pmatch(tolower(type), exportFormats$type, nomatch=0, duplicates.ok=FALSE) if (i) { handler <- exportFormats$handler[i] return(do.call(handler, list(x=x, file=file, ...))) } else { stop("File type ", sQuote(type), " is not supported!") } } .exportToDir <- function(x, path, type, force=FALSE, ...) { if (!file.exists(path) && force) { dir.create(path, showWarnings=FALSE, recursive=TRUE) } if (!file.exists(path)) { stop("Directory ", sQuote(path), " doesn't exist!") } if (!file.info(path)$isdir) { stop(sQuote(path), " is no directory!") } ## stop if directory isn't writeable if (file.access(path, 2) != 0) { stop("No permissions to write into ", sQuote(path), "!") } i <- pmatch(tolower(type), exportFormats$type, nomatch=0, duplicates.ok=FALSE) if (i) { filenames <- .composeFilename(x, fileExtension=exportFormats$extension[i]) filenames <- file.path(path, filenames) optArgs <- list(...) peaks <- list() if (hasArg(peaks)) { peaks <- optArgs$peaks optArgs$peaks <- NULL } for (i in seq(along=x)) { arguments <- list(x=x[[i]], file=filenames[i], type=type, force=force) arguments <- modifyList(arguments, optArgs) if (length(peaks)) { arguments$peaks <- peaks[[i]] } do.call(export, arguments) } } else { stop("File type ", sQuote(type), " is not supported!") } invisible() } r-cran-maldiquantforeign/R/importMzXml-functions.R0000644000175000017500000000230112221046771022527 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .importMzXml <- function(file, verbose=FALSE, ...) { s <- readMzXmlData:::.readMzXmlFile(mzXmlFile=file, verbose=verbose, ...) return(lapply(s, function(x)createMassSpectrum(mass=x$spectrum$mass, intensity=x$spectrum$intensity, metaData=x$metaData))) } r-cran-maldiquantforeign/R/exportMzMl-methods.R0000644000175000017500000000227712221046771022015 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see setMethod(f=".exportMzMl", signature=signature(x="MassSpectrum"), definition=function(x, file, id=.withoutFileExtension(basename(file)), ...) { return(.writeMzMlDocument(x=list(x), file=file, id=id, ...)) }) setMethod(f=".exportMzMl", signature=signature(x="list"), definition=function(x, file, id=.withoutFileExtension(basename(file)), ...) { return(.writeMzMlDocument(x=x, file=file, id=id, ...)) }) r-cran-maldiquantforeign/R/package.R0000644000175000017500000000322612221046771017621 0ustar rusconirusconi## Copyright 2012-2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' Import/Export routines for MALDIquant #' #' This package allows to read and write different file formats of mass #' spectrometry data into/from MALDIquant objects. #' #' \tabular{ll}{ #' Package: \tab MALDIquantForeign \cr #' Version: \tab 0.5.1\cr #' Date: \tab 2013-09-18\cr #' License: \tab GPL (>= 3)\cr #' URL: \tab http://strimmerlab.org/software/maldiquant/\cr #' } #' #' @docType package #' @name MALDIquantForeign-package #' @author Sebastian Gibb \email{mail@@sebastiangibb.de} #' @references \url{http://strimmerlab.org/software/maldiquant/} #' @keywords package #' #' @import MALDIquant #' @import readMzXmlData #' @import methods #' @importFrom base64enc base64encode #' @importFrom digest digest #' @importFrom downloader download #' @importFrom readBrukerFlexData readBrukerFlexFile #' @importFrom XML xmlEventParse xmlParse xmlValue xpathApply xpathSApply #' NULL r-cran-maldiquantforeign/R/fileFormats.R0000644000175000017500000000724212221046771020503 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' Supported file formats #' #' This function prints all file formats supported by #' \code{\link{MALDIquantForeign-package}}. #' #' \subsection{Import}{ #' #' \tabular{ll}{ #' txt \tab \code{\link[MALDIquantForeign]{importTxt}} \cr #' tab \tab \code{\link[MALDIquantForeign]{importTab}} \cr #' csv \tab \code{\link[MALDIquantForeign]{importCsv}} \cr #' fid \tab \code{\link[MALDIquantForeign]{importBrukerFlex}} \cr #' ciphergen \tab \code{\link[MALDIquantForeign]{importCiphergenXml}} \cr #' mzXML \tab \code{\link[MALDIquantForeign]{importMzXml}} \cr #' mzML \tab \code{\link[MALDIquantForeign]{importMzMl}} \cr #' imzML \tab \code{\link[MALDIquantForeign]{importImzMl}} \cr #' analyze \tab \code{\link[MALDIquantForeign]{importAnalyze}} \cr #' } #' } #' #' \subsection{Export}{ #' #' \tabular{ll}{ #' tab \tab \code{\link[MALDIquantForeign]{exportTab}} \cr #' csv \tab \code{\link[MALDIquantForeign]{exportCsv}} \cr #' msd \tab \code{\link[MALDIquantForeign]{exportMsd}} \cr #' mzML \tab \code{\link[MALDIquantForeign]{exportMzMl}} \cr #' } #' } #' #' @return a \code{list} with two named elements (\code{import} and #' \code{export}) containing a \code{character} vector of supported file types. #' #' @seealso #' \code{\link[MALDIquantForeign]{export}}, #' \code{\link[MALDIquantForeign]{import}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/} #' @examples #' library("MALDIquantForeign") #' #' supportedFileFormats() #' #' @rdname supportedFileFormats-functions #' @export supportedFileFormats <- function() { return(list(import=importFormats$type, export=exportFormats$type)) } #' @keywords internal importFormats <- data.frame(type=c("txt", "tab", "csv", "fid", "ciphergen", "mzxml", "mzml", "imzml", "analyze"), pattern=c("^.*\\.txt$", "^.*\\.tab$", "^.*\\.csv$", "^fid$", "^.*\\.xml$", "^.*\\.mzXML$", "^.*\\.mzML$", "^.*\\.imzML$", "^.*\\.hdr$"), handler=c(rep(".importTab", 2), ".importCsv", ".importBrukerFlex", ".importCiphergenXml", ".importMzXml", ".importMzMl", ".importImzMl", ".importAnalyze"), stringsAsFactors=FALSE) #' @keywords internal exportFormats <- data.frame(type=c("tab", "csv", "msd", "mzml"), extension=c("tab", "csv", "msd", "mzML"), onefile=c(FALSE, FALSE, FALSE, TRUE), handler=c(".exportTab", ".exportCsv", ".exportMsd", ".exportMzMl"), stringsAsFactors=FALSE) r-cran-maldiquantforeign/R/importAuto-functions.R0000644000175000017500000000367512221046771022407 0ustar rusconirusconi## Copyright 2012-2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .importAuto <- function(path, excludePattern=NULL, removeEmptySpectra=TRUE, verbose=FALSE, ...) { files <- lapply(importFormats$pattern, .files, path=path, excludePattern=excludePattern) names(files) <- importFormats$type ## test xml files for ciphergen format files$ciphergen <- .testCiphergenXml(files$ciphergen) n <- vapply(files, length, integer(1)) if (all(n)) { stop("Could not detect any supported file type.") } m <- which.max(n) if (verbose) { message(n[m], " files of type=", sQuote(importFormats$type[m]), " found.") } return(import(path=files[[m]], type=importFormats$type[m], pattern=importFormats$pattern[m], removeEmptySpectra=removeEmptySpectra, verbose=verbose, ...)) } #' @keywords internal # test xml for ciphergen format # returns files in ciphergen xml format .testCiphergenXml <- function(files) { ## read first 4 lines of each file l <- lapply(files, readLines, n=4) p <- lapply(l, grepl, pattern="||") s <- vapply(p, sum, integer(1)) isCiphergen <- s >= 2 return(files[isCiphergen]) } r-cran-maldiquantforeign/R/parseMzMl.R0000644000175000017500000003111612221046771020137 0ustar rusconirusconi## Copyright 2012-2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' Parse mzML files. #' #' This function parses mzML files. #' #' @param file \code{character}, path to mzML file #' @param verbose \code{logical}, verbose output? #' #' @return Returns a list with metadata and spectra. #' #' @author Sebastian Gibb \email{mail@@sebastiangibb.de} #' @rdname parseMzMl #' @keywords internal #' .parseMzMl <- function(file, verbose=FALSE, ...) { return(XML::xmlEventParse(file=file, handlers=.mzMlHandlers(fileName=file, verbose=verbose), addContext=FALSE, useTagName=TRUE, useDotNames=TRUE, ...)$getData()) } #' Parse mzML files. #' #' This function is defines handlers for XML SAX parser. Internal use only. #' #' TODO: fetch obo map file and use it #' #' @param fileName \code{character}, path to mzML file #' @param verbose \code{logical}, verbose output? #' #' @return function closure #' #' @author Sebastian Gibb \email{mail@@sebastiangibb.de} #' @references #' Definition of \code{mzML} format: #' \url{http://www.psidev.info/mzml_1_0_0} #' @rdname mzMlHandlers #' @keywords internal #' .mzMlHandlers <- function(fileName, verbose=FALSE) { ## define local variables ## handle different mzXML versions mzMlVersion <- 0 ## save last opened tag (needed for .text()-processing) openTag <- "" ## store current scan values nSpectra <- 0L curSpecIdx <- 0L curRefId <- character() currentArrayContent <- character() fileCheckSum <- character() ## supported? supported <- TRUE ## build final list xml <- list() xml$metaData <- list() xml$spectra <- list() ## imzML information xml$ims <- list() ## reference values references <- new.env(parent=emptyenv()) ## handlers for specific tags ## mzML mzML <- function(name, attrs) { ## fetch version information mzMlVersion <<- readMzXmlData:::.grepDouble(attrs["xsi:schemaLocation"]) if (verbose) { message("Found mzML document (version: ", mzMlVersion, ").") } } ## mzML/referenceableParamGroupList/referenceableParamGroup referenceableParamGroup <- function(name, attrs) { openTag <<- name curRefId <<- readMzXmlData:::.attributeToString(attrs, "id", required=TRUE) } referenceableParamGroupRef <- function(name, attrs) { if (!is.null(references[[attrs["ref"]]])) { xml$spectra[[curSpecIdx]]$metaData <<- modifyList(xml$spectra[[curSpecIdx]]$metaData, references[[attrs["ref"]]]) } } ## mzML/run/spectrumList spectrumList <- function(name, attrs) { ## fetch number of spectra nSpectra <<- readMzXmlData:::.attributeToDouble(attrs, "count", required=TRUE) if (verbose) { message("Found ", nSpectra, " ", ifelse(nSpectra == 1, "spectrum", "spectra"), ".") } } ## mzML/run/spectrumList/spectrum spectrum <- function(name, attrs) { openTag <- name curSpecIdx <<- curSpecIdx + 1 supported <<- TRUE xml$spectra[[curSpecIdx]] <<- list() xml$spectra[[curSpecIdx]]$metaData <<- list() xml$spectra[[curSpecIdx]]$metaData[["id"]] <<- readMzXmlData:::.attributeToString(attrs, "id", required=TRUE) xml$spectra[[curSpecIdx]]$metaData[["numberInFile"]] <<- curSpecIdx ## IMS extension if (length(xml$ims)) { xml$ims$ibd[[curSpecIdx]] <<- matrix(NA, nrow=2, ncol=3, dimnames=list(c("mass", "intensity"), c("offset", "length", "encodedLength"))) xml$spectra[[curSpecIdx]]$metaData$imaging <<- list() } if (verbose) { message("Processing spectrum ", curSpecIdx, "/", nSpectra, " (id: ", attrs["id"], ") ...") } } chromatogram <- function(name, attrs) { warning(" tag is not supported!") supported <<- FALSE } ## *cvParam cvParam <- function(name, attrs) { ## polarity if (.isAttrSet(attrs, "MS:1000129", "negative scan")) { .setCvValue("negative", "polarity") return() } else if (.isAttrSet(attrs, "MS:1000130", "positive scan")) { .setCvValue("positive", "polarity") return() } ## ms level if (.isAttrSet(attrs, "MS:1000511", "ms level")) { .setCvValue( readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE), "msLevel") return() } ## centroid data if (.isAttrSet(attrs, "MS:1000127", "centroid spectrum")) { warning("centroid data are not supported!") return() } ## precision if (.isAttrSet(attrs, "MS:1000521", "32-bit float")) { .setCvValue(32, "precision") return() } else if (.isAttrSet(attrs, "MS:1000523", "64-bit float")) { .setCvValue(64, "precision") return() } ## compression if (.isAttrSet(attrs, "MS:1000576", "no compression")) { .setCvValue("none", "compressionType") return() } else if (.isAttrSet(attrs, "MS:1000574", "zlib compression")) { .setCvValue("gzip", "compressionType") return() } ## data arrays if (.isAttrSet(attrs, "MS:1000514", "m/z array")) { .setCvValue("mass", "currentArray") return() } else if (.isAttrSet(attrs, "MS:1000515", "intensity array")) { .setCvValue("intensity", "currentArray") return() } ## IMS extensions if (.isAttrSet(attrs, "IMS:1000080", "universally unique identifier")) { xml$ims$uuid <<- gsub(pattern="[[:punct:]]", replacement="", x=readMzXmlData:::.attributeToString(attrs, "value", required=TRUE)) return() } if (.isAttrSet(attrs, "IMS:1000091", "ibd SHA-1")) { xml$ims$sha1 <<- readMzXmlData:::.attributeToString(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000030", "continuous")) { xml$ims$type <<- "continuous" return() } if (.isAttrSet(attrs, "IMS:1000032", "processed")) { xml$ims$type <<- "processed" return() } if (.isAttrSet(attrs, "IMS:1000042", "max count of pixel x")) { xml$metaData$imaging$size["x"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000043", "max count of pixel y")) { xml$metaData$imaging$size["y"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000044", "max dimension x")) { xml$metaData$imaging$dim["x"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000045", "max dimension y")) { xml$metaData$imaging$dim["y"]<<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000046", "pixel size x")) { xml$metaData$imaging$pixelSize["x"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000047", "pixel size y")) { xml$metaData$imaging$pixelSize["y"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000050", "position x")) { xml$spectra[[curSpecIdx]]$metaData$imaging$pos["x"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000051", "position y")) { xml$spectra[[curSpecIdx]]$metaData$imaging$pos["y"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000102", "external offset")) { xml$ims$ibd[[curSpecIdx]][xml$spectra[[curSpecIdx]]$metaData$currentArray, "offset"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000103", "external array length")) { xml$ims$ibd[[curSpecIdx]][xml$spectra[[curSpecIdx]]$metaData$currentArray, "length"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } if (.isAttrSet(attrs, "IMS:1000104", "external encoded length")) { xml$ims$ibd[[curSpecIdx]][xml$spectra[[curSpecIdx]]$metaData$currentArray, "encodedLength"] <<- readMzXmlData:::.attributeToDouble(attrs, "value", required=TRUE) return() } } ## default functions to catch tags without a handler .startElement <- function(name, attrs) { openTag <<- name } .endElement <- function(name, attrs) { if (name == "binary" && supported) { .decodeArray() } else if (name == "fileChecksum") { .calculateFileChecksum() } if (openTag == name) { openTag <<- "" } } .text <- function(x) { if (openTag == "binary" && supported) { currentArrayContent <<- paste0(currentArrayContent, x) } else if (openTag == "fileChecksum") { fileCheckSum <<- paste0(fileCheckSum, x) } } ## helper functions .isAttrSet <- function(attrs, id, name) { return(attrs["accession"] == id || attrs["name"] == name) } .setCvValue <- function(x, name) { if (openTag == "referenceableParamGroup") { if (is.null(references[[curRefId]])) { references[[curRefId]] <<- list() } references[[curRefId]][[name]] <<- x } else if (openTag == "spectrum" || openTag == "binaryDataArray") { xml$spectra[[curSpecIdx]]$metaData[[name]] <<- x } else { xml$metaData[[name]] <<- x } } .decodeArray <- function() { if (length(currentArrayContent)) { ## read base64 encoded array content (endian must be "little") content <- readMzXmlData:::.base64decode(x=currentArrayContent, endian="little", size=round(xml$spectra[[curSpecIdx]]$metaData$precision/8), compressionType=xml$spectra[[curSpecIdx]]$metaData$compressionType) xml$spectra[[curSpecIdx]][[xml$spectra[[curSpecIdx]]$metaData$currentArray]] <<- content ## clear array content currentArrayContent <<- character() } ## clear metaData xml$spectra[[curSpecIdx]]$metaData[c("precision", "compressionType", "currentArray")] <<- NULL } .calculateFileChecksum <- function() { n <- nchar(fileCheckSum) if (n <= 0) { return() } ## sha1 sum for this file (from the beginning of the file up to (and ## including) the opening tag if (verbose) { message("Look for '' position ...") } ## 14 == nchar("") checkSumPos <- readMzXmlData:::.revfregexpr("", fileName) + 14 if (verbose) { message("Calculating sha1-sum for ", sQuote(fileName), ": ", appendLF=FALSE) } sha1Calc <- digest::digest(fileName, algo="sha1", file=TRUE, length=checkSumPos-1) if (verbose) { message(sha1Calc) } if (fileCheckSum != sha1Calc) { warning("Stored and calculated Sha-1 sums do not match ", "(stored ", sQuote(fileCheckSum), " calculated ", sQuote(sha1Calc), ")!") } } ## return statement (please call getData()) return(list(getData=function() {return(xml)}, mzML=mzML, referenceableParamGroup=referenceableParamGroup, referenceableParamGroupRef=referenceableParamGroupRef, spectrumList=spectrumList, spectrum=spectrum, chromatogram=chromatogram, cvParam=cvParam, .startElement=.startElement, .endElement=.endElement, .text=.text)) } r-cran-maldiquantforeign/R/import-functions.R0000644000175000017500000003311312221046771021544 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' Import files #' #' This function provides a general interface to import different file formats #' into \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' #' @details #' Specific import functions: #' \tabular{ll}{ #' txt \tab \code{\link[MALDIquantForeign]{importTxt}} \cr #' tab \tab \code{\link[MALDIquantForeign]{importTab}} \cr #' csv \tab \code{\link[MALDIquantForeign]{importCsv}} \cr #' fid \tab \code{\link[MALDIquantForeign]{importBrukerFlex}} \cr #' ciphergen \tab \code{\link[MALDIquantForeign]{importCiphergenXml}} \cr #' mzXML \tab \code{\link[MALDIquantForeign]{importMzXml}} \cr #' mzML \tab \code{\link[MALDIquantForeign]{importMzMl}} \cr #' imzML \tab \code{\link[MALDIquantForeign]{importImzMl}} \cr #' analyze \tab \code{\link[MALDIquantForeign]{importAnalyze}} \cr #' } #' #' \code{path}: In addition to the above mentioned file types the #' following (compressed) archives are supported, too: #' zip, tar, tar.gz, tar.bz2, tar.xz. The archives are uncompressed in a #' temporary directory. Afterwards the \code{\link[MALDIquantForeign]{import}} #' function is called (with \code{type="auto"}). #' #' \code{pattern}: Sometimes unusual file extensions are used (e.g. #' \code{"*.xml"} for mzXML files). In this case a specific #' \code{pattern} could be defined to import files with an unusual file #' extension (e.g. \code{pattern="^.*\\.xml$"} to read all \code{*.xml} #' files in a directory; see \code{\link[base]{regexp}} for details). #' #' \code{excludePattern}: Sometimes some files should be excluded. E.g. #' to ignore additional aquired Bruker LIFT spectra #' (MALDI-TOF/TOF; which are not support, yet) you could use #' \code{excludePattern="([[:digit:]\\.]+)LIFT[\\\\/]1SRef"}. #' #' @param path \code{character}, path to directory or file which should be read #' in. #' @param type \code{character}, file format. If \code{type} is set to #' \dQuote{auto} MALDIquant tries to detect the correct file type #' automatically. It often depends on the file extension #' (if \code{path} is a directory the most represented file extension is used; #' \code{pattern} argument is ignored). #' @param pattern \code{character}, a regular expression to find files in a #' directory (see details). #' @param excludePattern \code{character}, a regular expression to exclude #' files in a directory (see details). #' @param removeEmptySpectra \code{logical}, should empty spectra excluded? #' @param verbose \code{logical}, verbose output? #' @param \ldots arguments to be passed to specific import functions. #' #' @return a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} #' objects. #' @seealso #' \code{\link[MALDIquant]{MassSpectrum-class}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/} #' @examples #' #' library("MALDIquant") #' library("MALDIquantForeign") #' #' ## get example directory #' exampleDirectory <- system.file(file.path("tests", "data"), #' package="MALDIquantForeign") #' #' ## import mzXML files #' s <- import(exampleDirectory, type="mzXML") #' #' ## import tab delimited file with different file extension (default: *.tab) #' s <- import(exampleDirectory, type="tab", pattern="^.*\\.txt") #' #' ## import single mzML file #' s <- import(file.path(exampleDirectory, "tiny1.mzML1.1.mzML")) #' #' ## import gzipped csv file #' s <- import(file.path(exampleDirectory, "compressed", "csv1.csv.gz")) #' #' @rdname import-functions #' @export import <- function(path, type="auto", pattern, excludePattern=NULL, removeEmptySpectra=TRUE, verbose=TRUE, ...) { ## download file if needed isUrl <- .isUrl(path) if (any(isUrl)) { path[isUrl] <- .download(path[isUrl], verbose=verbose) on.exit(.cleanupDownloadedTmpFiles()) } ## file exists? isReadable <- file.exists(path) & file.access(path, mode=4) == 0 if (any(!isReadable)) { stop(sQuote(path[!isReadable]), " doesn't exist or isn't readable!") } ## uncompress/unpack file if needed isCompressed <- .isPackedOrCompressed(path) if (any(isCompressed)) { path[isCompressed] <- .uncompress(path[isCompressed], verbose=verbose) on.exit(.cleanupUncompressedTmpFiles(), add=TRUE) } ## handle given file type i <- pmatch(tolower(type), c("auto", importFormats$type), nomatch=0, duplicates.ok=FALSE)-1 if (i == -1) { stop("File type ", sQuote(type), " is not supported!") } else if (i == 0) { ## auto detect file type if (!missing(pattern)) { warning("User defined ", sQuote("pattern"), " is ignored in auto-mode.") } return(.importAuto(path=path, excludePattern=excludePattern, removeEmptySpectra=removeEmptySpectra, verbose=verbose, ...)) } else { ## user-defined file type if (missing(pattern)) { pattern <- importFormats$pattern[i] } handler <- importFormats$handler[i] s <- unlist(lapply(.files(path=path, pattern=pattern, excludePattern=excludePattern), handler, verbose=verbose, ...)) if (is.null(s)) { stop("Import failed! Unsupported file type?") } if (removeEmptySpectra) { emptyIdx <- MALDIquant::findEmptyMassObjects(s) if (length(emptyIdx)) { if (verbose) { message("Remove ", length(emptyIdx), " empty spectra.") } return(s[-emptyIdx]) } } return(s) } } #' Import text files #' #' This function imports different text file formats #' into \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' #' \code{importTab}, \code{importTxt} and \code{importCsv} use #' \code{\link[utils]{read.table}} with different defaults. #' #' @param path \code{character}, path to directory or file which should be read #' in. #' @param \ldots arguments to be passed to \code{\link[utils]{read.table}}. #' #' @return a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} #' objects. #' @seealso #' \code{\link[MALDIquant]{MassSpectrum-class}}, #' \code{\link[utils]{read.table}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/} #' @examples #' #' library("MALDIquant") #' library("MALDIquantForeign") #' #' ## get example directory #' exampleDirectory <- system.file(file.path("tests", "data"), #' package="MALDIquantForeign") #' #' ## import txt files #' s <- importTxt(exampleDirectory) #' #' ## import csv files #' s <- importCsv(exampleDirectory) #' #' @rdname importTab-functions #' @export importTxt <- function(path, ...) { return(import(path=path, type="txt", ...)) } #' @rdname importTab-functions #' @export importTab <- function(path, ...) { return(import(path=path, type="tab", ...)) } #' @rdname importTab-functions #' @export importCsv <- function(path, ...) { return(import(path=path, type="csv", ...)) } #' Import Bruker Daltonics *flex files #' #' This function imports files in Bruker Daltonics *flex-series file format #' into \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' #' @param path \code{character}, path to directory or file which should be read #' in. #' @param \ldots arguments to be passed to #' \code{\link[readBrukerFlexData]{readBrukerFlexFile}}. #' #' @return a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} #' objects. #' @seealso #' \code{\link[MALDIquant]{MassSpectrum-class}}, #' \code{\link[readBrukerFlexData]{readBrukerFlexFile}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/} #' @examples #' #' library("MALDIquant") #' library("MALDIquantForeign") #' #' ## get example directory #' exampleDirectory <- system.file(file.path("tests", "data"), #' package="MALDIquantForeign") #' #' s <- importBrukerFlex(exampleDirectory) #' #' @rdname importBrukerFlex-functions #' @export importBrukerFlex <- function(path, ...) { return(import(path=path, type="fid", ...)) } #' Import mzXML files #' #' This function imports files in mzXML file format #' into \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' #' @param path \code{character}, path to directory or file which should be read #' in. #' @param \ldots arguments to be passed to #' \code{\link[readMzXmlData]{readMzXmlFile}}. #' #' @return a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} #' objects. #' @seealso #' \code{\link[MALDIquant]{MassSpectrum-class}}, #' \code{\link[readMzXmlData]{readMzXmlFile}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/}, \cr #' Definition of \code{mzXML} format: #' \url{http://tools.proteomecenter.org/mzXMLschema.php} #' @examples #' #' library("MALDIquant") #' library("MALDIquantForeign") #' #' ## get example directory #' exampleDirectory <- system.file(file.path("tests", "data"), #' package="MALDIquantForeign") #' #' ## import #' s <- importMzXml(exampleDirectory) #' #' @rdname importMzXml-functions #' @export importMzXml <- function(path, ...) { return(import(path=path, type="mzxml", ...)) } #' Import mzML files #' #' This function imports files in mzML file format #' into \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' #' @param path \code{character}, path to directory or file which should be read #' in. #' @param \ldots arguments to be passed to #' \code{\link[MALDIquantForeign]{import}}. #' #' @return a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} #' objects. #' @seealso #' \code{\link[MALDIquant]{MassSpectrum-class}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/}, \cr #' Definition of \code{mzML} format: #' \url{http://www.psidev.info/mzml_1_0_0\%20} #' @examples #' #' library("MALDIquant") #' library("MALDIquantForeign") #' #' ## get example directory #' exampleDirectory <- system.file(file.path("tests", "data"), #' package="MALDIquantForeign") #' #' ## import #' s <- importMzMl(exampleDirectory) #' #' @rdname importMzMl-functions #' @export importMzMl <- function(path, ...) { return(import(path=path, type="mzml", ...)) } #' Import imzML files #' #' This function imports files in imzML file format #' into \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' #' @param path \code{character}, path to directory or file which should be read #' in. #' @param \ldots arguments to be passed to #' \code{\link[MALDIquantForeign]{import}}. #' #' @return a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} #' objects. #' @seealso #' \code{\link[MALDIquant]{MassSpectrum-class}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/}, \cr #' Definition of \code{imzML} format: #' \url{http://www.imzml.org/} #' @examples #' #' library("MALDIquant") #' library("MALDIquantForeign") #' #' ## get example directory #' exampleDirectory <- system.file(file.path("tests", "data"), #' package="MALDIquantForeign") #' #' ## import #' s <- importImzMl(exampleDirectory) #' #' @rdname importImzMl-functions #' @export importImzMl <- function(path, ...) { return(import(path=path, type="imzml", ...)) } #' Import Ciphergen XML files #' #' This function imports files in Ciphergen XML file format #' into \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' #' @param path \code{character}, path to directory or file which should be read #' in. #' @param \ldots arguments to be passed to #' \code{\link[MALDIquantForeign]{import}}. #' #' @return a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} #' objects. #' @seealso #' \code{\link[MALDIquant]{MassSpectrum-class}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/} #' @examples #' #' library("MALDIquant") #' library("MALDIquantForeign") #' #' ## get example directory #' exampleDirectory <- system.file(file.path("tests", "data"), #' package="MALDIquantForeign") #' #' ## import #' s <- importCiphergenXml(exampleDirectory) #' #' @rdname importCiphergenXml-functions #' @export importCiphergenXml <- function(path, ...) { return(import(path=path, type="ciphergen", ...)) } #' Import Analyze 7.5 files #' #' This function imports files in Analyze 7.5 file format #' into \code{\link[MALDIquant]{MassSpectrum-class}} objects. #' #' @param path \code{character}, path to directory or file which should be read #' in. #' @param \ldots arguments to be passed to #' \code{\link[MALDIquantForeign]{import}}. #' #' @return a \code{list} of \code{\link[MALDIquant]{MassSpectrum-class}} #' objects. #' @seealso #' \code{\link[MALDIquant]{MassSpectrum-class}} #' @author Sebastian Gibb #' @references \url{http://strimmerlab.org/software/maldiquant/} \cr #' \url{http://www.grahamwideman.com/gw/brain/analyze/formatdoc.htm}, #' \url{http://eeg.sourceforge.net/ANALYZE75.pdf} #' @rdname importAnalyze-functions #' @export importAnalyze <- function(path, ...) { return(import(path=path, type="analyze", ...)) } r-cran-maldiquantforeign/R/parseCiphergenXml.R0000644000175000017500000000551012221046771021644 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' Parse Ciphergen XML files. #' #' This function parses Ciphergen XML files. #' #' @param file \code{character}, path to Ciphergen XML file #' @param verbose \code{logical}, verbose output? #' #' @return Returns a list with metadata and spectra. #' #' @author Sebastian Gibb \email{mail@@sebastiangibb.de} #' @rdname parseCiphergenXml #' @keywords internal #' .parseCiphergenXml <- function(file, ...) { ## metaData listNames <- c("name", "ionSourceVoltage", "digitizerRate", "massCalibrationA", "massCalibrationB", "massCalibrationT0", "massCalibrationInfo", "spotCorrectionFactor") xpath <- paste0("//spectrum/", c("spectrumName", paste0("acquisitionInfo/setting/", listNames[2:3]), paste0("processingParameters/massCalibration/", listNames[-c(1:3)])), "/text()") doc <- xmlParse(file, ...) metaData <- XML::xpathApply(doc=doc, path=xpath, fun=XML::xmlValue) names(metaData) <- listNames metaData[listNames[-c(1, 7)]] <- lapply(metaData[-c(1, 7)], as.double) metaData$file <- normalizePath(file) intensity <- XML::xpathSApply(doc=doc, path="//spectrum/tofData/tofDataSamples/text()", fun=XML::xmlValue) intensity <- as.double(strsplit(intensity, "[[:space:]]+")[[1]]) intensity <- intensity[!is.na(intensity)] ## tof2mass ## mass = U*(A*(tof-t0)^2 + B) ## Calibration formula was taken from: ## http://bioinformatics.mdanderson.org/Supplements/Datasets/KuererQC/scripts.zip ## file: ciphergenXMLreader.pl n <- 0:(length(intensity)-1) time <- metaData$spotCorrectionFactor*n/metaData$digitizerRate tof <- time-metaData$massCalibrationT0 mass <- metaData$ionSourceVoltage * (sign(tof) * metaData$massCalibrationA * tof*tof + metaData$massCalibrationB) return(list(spectrum=list(mass=mass, intensity=intensity), metaData=metaData)) } r-cran-maldiquantforeign/R/importBrukerFlex-functions.R0000644000175000017500000000224112221046771023534 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .importBrukerFlex <- function(file, verbose=FALSE, ...) { s <- readBrukerFlexData::readBrukerFlexFile(fidFile=file, verbose=verbose, ...) return(list(createMassSpectrum(mass=s$spectrum$mass, intensity=s$spectrum$intensity, metaData=s$metaData))) } r-cran-maldiquantforeign/R/list.files-functions.R0000644000175000017500000000346512221046771022315 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .list.files <- function(path, pattern, excludePattern=NULL, recursive=TRUE, ignore.case=TRUE) { files <- list.files(path=path, pattern=pattern, recursive=recursive, ignore.case=ignore.case, full.names=TRUE) if (!is.null(excludePattern)) { isExcluded <- grepl(pattern=excludePattern, x=files, ignore.case=ignore.case) files <- files[!isExcluded] } return(normalizePath(files)) } #' @keywords internal .files <- function(path, pattern, excludePattern=NULL, ignore.case=TRUE, ...) { isDir <- file.info(path)$isdir files <- normalizePath(path[!isDir]) isMatching <- unlist(regexpr(pattern=pattern, text=basename(files), ignore.case=ignore.case)) != -1 files <- files[isMatching] files <- c(files, .list.files(path=path[isDir], pattern=pattern, excludePattern=excludePattern, ignore.case=ignore.case, ...)) return(unique(files)) } r-cran-maldiquantforeign/R/mzMl-functions.R0000644000175000017500000002514212221046771021154 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see .writeMzMlDocument <- function(x, file, id, encoding="utf-8") { ## stop if file isn't writeable if (file.exists(file) && file.access(file, 2) != 0) { stop("No permissions to write into ", sQuote(file), "!") } ## file handle f <- file(file, open="wt", encoding=encoding) .writeXmlHeader(file=f, encoding=encoding) .writeXmlTag("mzML", attrs=c(xmlns="http://psi.hupo.org/ms/mzml", "xmlns:xsi"="http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation"=paste("http://psi.hupo.org/ms/mzml", "http://psidev.info/files/ms/mzML/xsd/mzML1.1.0.xsd"), id=.sanitize(ifelse(missing(id) || is.null(id), deparse(substitute(x)), id)), version="1.1.0"), close=FALSE, file=f) .writeMzMlCvList(file=f) .writeMzMlFileDescription(x, file=f) .writeMzMlSoftwareList(x, file=f) .writeMzMlInstrumentConfigurationList(x, file=f) .writeMzMlDataProcessingList(x, file=f) .writeMzMlRun(x, file=f) .writeCloseXmlTag("mzML", file=f) invisible(close(f)) } .writeMzMlCvList <- function(file) { items <- list( ms=list(id="MS", fullName="Proteomics Standards Initiative Mass Spectrometry Ontology", version="3.44.0", URI="http://psidev.cvs.sourceforge.net/*checkout*/psidev/psi/psi-ms/mzML/controlledVocabulary/psi-ms.obo"), uo=list(id="UO", fullName="Unit Ontology", version="12:10:2012", URI="http://obo.cvs.sourceforge.net/*checkout*/obo/obo/ontology/phenotype/unit.obo")) .writeXmlTag("cvList", attrs=c(count=2), intend=1, close=FALSE, file=file) for (i in seq(along=items)) { .writeXmlTag("cv", attrs=items[[i]], intend=2, file=file) } .writeCloseXmlTag("cvList", intend=1, file=file) } .writeMzMlFileDescription <- function(x, file) { .writeXmlTag("fileDescription", intend=1, close=FALSE, file=file) .writeXmlTag("fileContent", intend=2, close=FALSE, file=file) .writeXmlTag("cvParam", intend=3, attrs=c(cvRef="MS", accession="MS:1000579", name="MS1 spectrum"), file=file) .writeXmlTag("userParam", intend=3, attrs=c(name="MALDIquantForeign", value="MALDIquant object(s) exported to mzML"), file=file) .writeCloseXmlTag("fileContent", intend=2, file=file) .writeMzMlSourceFileList(x, file=file) .writeCloseXmlTag("fileDescription", intend=1, file=file) } .writeMzMlSourceFileList <- function(x, file) { files <- unique(unlist(lapply(x, function(s)metaData(s)$file))) if (length(files)) { dname <- dirname(files) bname <- basename(files) ext <- tolower(.fileExtension(bname)) .writeXmlTag("sourceFileList", attrs=c(count=length(files)), intend=2, close=FALSE, file=file) for (i in seq(along=files)) { .writeXmlTag("sourceFile", intend=3, attrs=c(id=paste0("SF", i), location=dname[i], name=bname[i]), close=FALSE, file=file) if (ext[i] == "fid") { .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000825", name="Bruker FID file"), file=file) .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000773", name="Bruker FID nativeID format"), file=file) } else if (ext[i] == "mzxml") { .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000566", name="ISB mzXML file"), file=file) } else if (ext[i] == "mzml") { .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000584", name="mzML file"), file=file) } if (file.exists(files[i])) { .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000569", name="SHA-1", value=digest::digest(files[i], algo="sha1", file=TRUE)), file=file) } .writeCloseXmlTag("sourceFile", intend=3, file=file) } .writeCloseXmlTag("sourceFileList", intend=2, file=file) } } .writeMzMlSoftwareList <- function(x, file) { .writeXmlTag("softwareList", attrs=c(count=1), intend=1, close=FALSE, file=file) .writeXmlTag("software", intend=2, attrs=c(id="MALDIquantForeign", version=as.character(packageVersion("MALDIquantForeign"))), file=file) .writeCloseXmlTag("softwareList", intend=1, file=file) } .writeMzMlInstrumentConfigurationList <- function(x, file) { .writeXmlTag("instrumentConfigurationList", attrs=c(count=1), intend=1, close=FALSE, file=file) .writeXmlTag("instrumentConfiguration", attrs=c(id="IC0"), intend=2, file=file) .writeCloseXmlTag("instrumentConfigurationList", intend=1, file=file) } .writeMzMlDataProcessingList <- function(x, file) { .writeXmlTag("dataProcessingList", attrs=c(count=1), intend=1, close=FALSE, file=file) .writeXmlTag("dataProcessing", attrs=c(id="export"), intend=2, close=FALSE, file=file) .writeXmlTag("processingMethod", intend=3, attrs=c(order=1, softwareRef="MALDIquantForeign"), close=FALSE, file=file) .writeXmlTag("userParam", intend=4, attrs=c(name="MALDIquant object(s) exported to mzML", value=""), file=file) .writeCloseXmlTag("processingMethod", intend=3, file=file) .writeCloseXmlTag("dataProcessing", intend=2, file=file) .writeCloseXmlTag("dataProcessingList", intend=1, file=file) } .writeMzMlRun <- function(x, file) { .writeXmlTag("run", attrs=c(id="run0", defaultInstrumentConfigurationRef="IC0"), intend=1, close=FALSE, file=file) .writeMzMlSpectrumList(x, file=file) .writeCloseXmlTag("run", intend=1, file=file) } .writeMzMlSpectrumList <- function(x, file) { .writeXmlTag("spectrumList", attrs=c(count=length(x), defaultDataProcessingRef="export"), intend=2, close=FALSE, file=file) for (i in seq(along=x)) { .writeXmlTag("spectrum", intend=3, attrs=c(index=i-1, id=paste0("scan=", i-1), defaultArrayLength=length(x[[i]]), spotID=metaData(x[[i]])$fullName), close=FALSE, file=file) msLevel <- ifelse(is.null(metaData(x[[i]])$msLevel), 1, metaData(x[[i]])$msLevel) .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000511", name="ms level", value=msLevel), file=file) .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000294", name="mass spectrum"), file=file) .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000528", name="lowest observed m/z", value=min(mass(x[[i]])), unitCvRef="MS", unitAccession="MS:1000040", unitName="m/z"), file=file) .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000527", name="highest observed m/z", value=max(mass(x[[i]])), unitCvRef="MS", unitAccession="MS:1000040", unitName="m/z"), file=file) .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000285", name="total ion current", value=totalIonCurrent(x[[i]])), file=file) if (MALDIquant::isMassSpectrum(x[[i]])) { .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000128", name="profile spectrum"), file=file) } else { .writeXmlTag("cvParam", intend=4, attrs=c(cvRef="MS", accession="MS:1000127", name="centroid spectrum"), file=file) } .writeMzMlBinaryDataArrayList(x[[i]], file=file) .writeCloseXmlTag("spectrum", intend=3, file=file) } .writeCloseXmlTag("spectrumList", intend=2, file=file) } .writeMzMlBinaryDataArrayList <- function(x, file) { count <- ifelse(MALDIquant::isMassSpectrum(x), 2, 3) .writeXmlTag("binaryDataArrayList", attrs=c(count=count), intend=4, close=FALSE, file=file) .writeMzMlBinaryData(mass(x), file=file, c(cvRef="MS", accession="MS:1000514", name="m/z array", unitCvRef="MS", unitAccession="MS:1000040", unitName="m/z")) .writeMzMlBinaryData(intensity(x), file=file, c(cvRef="MS", accession="MS:1000515", name="intensity array", unitCvRef="MS", unitAccession="MS:1000131", unitName="number of counts")) if (MALDIquant::isMassPeaks(x)) { .writeMzMlBinaryData(snr(x), file=file, c(cvRef="MS", accession="MS:1000517", name="signal to noise array")) } .writeCloseXmlTag("binaryDataArrayList", intend=4, file=file) } .writeMzMlBinaryData <- function(x, file, additionalAttrs) { binaryData <- .base64encode(x, size=8, endian="little", compressionType="gzip") .writeXmlTag("binaryDataArray", attrs=c(encodedLength=nchar(binaryData)), intend=5, close=FALSE, file=file) .writeXmlTag("cvParam", intend=6, file=file, attrs=c(cvRef="MS", accession="MS:1000574", name="zlib compression")) .writeXmlTag("cvParam", intend=6, file=file, attrs=c(cvRef="MS", accession="MS:1000523", name="64-bit float")) if (!missing(additionalAttrs)) { .writeXmlTag("cvParam", attrs=additionalAttrs, intend=6, file=file) } .writeXmlTag("binary", text=binaryData, intend=6, file=file) .writeCloseXmlTag("binaryDataArray", intend=5, file=file) } r-cran-maldiquantforeign/R/xml-functions.R0000644000175000017500000000307212221046771021033 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see .writeXmlHeader <- function(file, encoding) { cat("\n", file=file, sep="") } .writeCloseXmlTag <- function(tag, intend=0, file) { cat(paste0(rep(" ", times=intend)), "\n", file=file, sep="", append=TRUE) } .writeXmlTag <- function(tag, text=NULL, attrs=NULL, intend=0, close=TRUE, file) { intend <- paste0(rep(" ", times=intend)) if (length(attrs)) { attrs <- paste0(" ", names(attrs), "=\"", attrs, "\"") } if (length(text)) { text <- paste0(">", text) if (close) { text <- paste0(text, "") } } else { text <- ">" if (close) { text <- "/>" } } cat(intend, "<", tag, attrs, text, "\n", file=file, sep="", append=TRUE) } r-cran-maldiquantforeign/R/AllGenerics.R0000644000175000017500000000362612221046771020422 0ustar rusconirusconi## Copyright 2012-2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see if (is.null(getGeneric(".composeFilename"))) setGeneric(".composeFilename", function(x, ...) standardGeneric(".composeFilename")) if (is.null(getGeneric(".exportTab"))) setGeneric(".exportTab", function(x, ...) standardGeneric(".exportTab")) if (is.null(getGeneric(".exportCsv"))) setGeneric(".exportCsv", function(x, ...) standardGeneric(".exportCsv")) if (is.null(getGeneric(".exportMsd"))) setGeneric(".exportMsd", function(x, ...) standardGeneric(".exportMsd")) if (is.null(getGeneric(".exportMzMl"))) setGeneric(".exportMzMl", function(x, ...) standardGeneric(".exportMzMl")) if (is.null(getGeneric("export"))) setGeneric("export", function(x, ...) standardGeneric("export")) if (is.null(getGeneric("exportTab"))) setGeneric("exportTab", function(x, ...) standardGeneric("exportTab")) if (is.null(getGeneric("exportCsv"))) setGeneric("exportCsv", function(x, ...) standardGeneric("exportCsv")) if (is.null(getGeneric("exportMsd"))) setGeneric("exportMsd", function(x, ...) standardGeneric("exportMsd")) if (is.null(getGeneric("exportMzMl"))) setGeneric("exportMzMl", function(x, ...) standardGeneric("exportMzMl")) r-cran-maldiquantforeign/R/filename-methods.R0000644000175000017500000000376712221046771021461 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' This method creates a filename for a \code{\linkS4class{AbstractMassObject}} #' object. #' #' @param x a \code{\linkS4class{AbstractMassObject}} object #' @param fileExtension file type (e.g. "txt", "pdf", ...) #' @return filename #' #' @seealso \code{\linkS4class{AbstractMassObject}} #' @keywords internal #' @aliases .composeFilename,AbstractMassObject-method #' @aliases .composeFilename,list-method #' @docType methods #' @rdname composeFilename-methods setMethod(f=".composeFilename", signature=signature(x="AbstractMassObject"), definition=function(x, fileExtension="csv") { if (!is.null(metaData(x)$fullName)) { if (length(metaData(x)$fullName) > 1) { filename <- paste0(metaData(x)$fullName, collapse="_") } else { filename <- metaData(x)$fullName } } else { filename <- .withoutFileExtension(metaData(x)$file[1]) } filename <- paste(filename, fileExtension, sep=".") return(filename) }) setMethod(f=".composeFilename", signature=signature(x="list"), definition=function(x, fileExtension="csv") { stopifnot(MALDIquant:::.isMassObjectList(x)) filenames <- unlist(lapply(x, .composeFilename, fileExtension=fileExtension)) .uniqueBaseFilenames(filenames, fileExtension) }) r-cran-maldiquantforeign/R/importImzMl-functions.R0000644000175000017500000000553512221046771022524 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .importImzMl <- function(file, verbose=FALSE) { if (verbose) { message("Reading spectrum from ", sQuote(file), " ...") } if (!file.exists(file)) { stop("File ", sQuote(file), " doesn't exists!") } ibdFilename <- paste0(.withoutFileExtension(file), ".ibd") if (!file.exists(ibdFilename)) { stop("File ", sQuote(ibdFilename), " doesn't exists!") } ## read file s <- .parseMzMl(file=file, verbose=verbose) ## test SHA-1 sha1<- digest::digest(ibdFilename, algo="sha1", file=TRUE) if (tolower(sha1) != tolower(s$ims$sha1)) { stop("SHA1 mismatch!") } ibd <- file(ibdFilename, open="rb") on.exit(close(ibd)) ## test UUID uuid <- paste0(readBin(ibd, raw(), n=16, size=1, signed=TRUE, endian="little"), collapse="") if (tolower(uuid) != tolower(s$ims$uuid)) { stop("UUID mismatch!") } n <- length(s$ims$ibd) spectra <- vector(mode="list", length=n) .readValues <- function(file, x, column) { n <- x[column, "length"] e <- x[column, "encodedLength"] return(readBin(file, double(), n=n, size=e/n, signed=TRUE, endian="little")) } ## read mass and intensity values if (s$ims$type == "processed") { for (i in seq(along=spectra)) { if (verbose) { message("Reading binary data for spectrum ", i, "/", n, " ...") } m <- modifyList(s$metaData, s$spectra[[i]]$metaData) m$file <- file mass <- .readValues(ibd, s$ims$ibd[[i]], "mass") intensity <- .readValues(ibd, s$ims$ibd[[i]], "intensity") spectra[[i]] <- createMassSpectrum(mass=mass, intensity=intensity, metaData=m) } } else { mass <- .readValues(ibd, s$ims$ibd[[1]], "mass") for (i in seq(along=spectra)) { if (verbose) { message("Reading binary data for spectrum ", i, "/", n, " ...") } m <- modifyList(s$metaData, s$spectra[[i]]$metaData) m$file <- file intensity <- .readValues(ibd, s$ims$ibd[[i]], "intensity") spectra[[i]] <- createMassSpectrum(mass=mass, intensity=intensity, metaData=m) } } return(spectra) } r-cran-maldiquantforeign/R/exportMsd-methods.R0000644000175000017500000000171712221046771021657 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see setMethod(f=".exportMsd", signature=signature(x="MassSpectrum"), definition=function(x, file, peaks, ...) { return(.writeMsdDocument(x=x, file=file, peaks=peaks, ...)) }) r-cran-maldiquantforeign/R/sanitize-functions.R0000644000175000017500000000176412221046771022067 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .sanitize <- function(x) { x <- gsub(pattern="&", replacement="&", x=x) x <- gsub(pattern="<", replacement="<", x=x) x <- gsub(pattern=">", replacement=">", x=x) return(x) } r-cran-maldiquantforeign/R/msd-functions.R0000644000175000017500000000730412221046771021020 0ustar rusconirusconi## Copyright 2012-2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see .writeMsdDocument <- function(x, file, peaks, encoding="utf-8") { ## stop if file isn't writeable if (file.exists(file) && file.access(file, 2) != 0) { stop("No permissions to write into ", sQuote(file), "!") } ## file handle f <- file(file, open="wt", encoding=encoding) ## header .writeXmlHeader(file=f, encoding=encoding) .writeXmlTag("mSD", attrs=c(version=2.2), close=FALSE, file=f) .writeMsdDescription(x, file=f) .writeMsdSpectrum(x, file=f) if (!missing(peaks)) { .writeMsdPeakList(peaks, file=f) } .writeCloseXmlTag("mSD", file=f) invisible(close(f)) } .writeMsdDescription <- function(x, file) { .writeXmlTag("description", intend=1, close=FALSE, file=file) .writeXmlTag("title", text=.createMsdTitle(file), intend=2, file=file) .writeXmlTag("date", attrs=c(value=.sanitize(date())), intend=2, file=file) .writeXmlTag("operator", attrs=c(value=.sanitize(metaData(x)$owner)), intend=2, file=file) .writeXmlTag("contact", attrs=c(value=.sanitize(metaData(x)$owner)), intend=2, file=file) .writeXmlTag("institution", attrs=c(value=.sanitize(metaData(x)$institution)), intend=2, file=file) .writeXmlTag("instrument", attrs=c(value=.sanitize(metaData(x)$instrument)), intend=2, file=file) .writeXmlTag("notes", .sanitize(paste(metaData(x)$comments, collapse="\n")), intend=2, file=file) .writeCloseXmlTag("description", intend=1, file=file) } .writeMsdSpectrum <- function(x, file) { polarity <- paste(metaData(x)$ionizationMode, metaData(x)$polarity) if (length(polarity)) { polarity <- ifelse(grepl(pattern="+|positive", x=polarity), "1", "-1") } else { polarity <- "" } .writeXmlTag("spectrum", attrs=c(points=length(x), msLevel=ifelse(is.null(metaData(x)$msLevel), 1, metaData(x)$msLevel), polarity=polarity), close=FALSE, intend=1, file=file) .writeMsdArray(mass(x), name="mzArray", file=file) .writeMsdArray(intensity(x), name="intArray", file=file) .writeCloseXmlTag("spectrum", intend=1, file=file) } .writeMsdArray <- function(x, name, file) { .writeXmlTag(name, text=.base64encode(x, size=8, compressionType="gzip"), attrs=c(precision="64", compression="zlib", endian=.Platform$endian), intend=2, file=file) } .writeMsdPeakList <- function(x, file) { .writeXmlTag("peaklist", close=FALSE, intend=1, file=file) cat(paste0(" \n"), file=file, sep="", append=TRUE) .writeCloseXmlTag("peaklist", intend=1, file=file) } .createMsdTitle <- function(file) { return(.sanitize(.withoutFileExtension(basename(summary(file)$description)))) } r-cran-maldiquantforeign/R/analyze-functions.R0000644000175000017500000000664712221046771021711 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see ## Analyze 7.5 header file .readAnalyzeHdr <- function(filename, verbose=FALSE) { if (!file.exists(filename)) { stop(sQuote(filename), " isn't readable.") } if (file.info(filename)$size != 348) { stop(sQuote(filename), " is no ANALYZE header file.") } if (verbose) { message("Extracting header information from ", sQuote(filename), " ...") } f <- file(filename, open="rb") ## first 4 bytes have to be 348 in little endian mode endian <- ifelse(readBin(f, integer(), n=1, size=4, endian="little") == 348, "little", "big") ## skip unused entries seek(f, where=38) regular <- readChar(f, nchars=1, useBytes=TRUE) if (regular != "r") { stop("Wrong file format. Images have to be of equal size (", sQuote("regular"), " must be ", sQuote("r"), ")") } ## skip unused entries seek(f, where=40) ## 2 == number of intesity, 3 == ncol (x), 4, nrow (y) dimensions <- readBin(f, integer(), n=8, size=2, endian=endian) ni <- dimensions[2] nx <- dimensions[3] ny <- dimensions[4] ## skip unused entries seek(f, where=70) datatype <- readBin(f, integer(), n=1, size=2, endian=endian) bitpix <- readBin(f, integer(), n=1, size=2, endian=endian) if (datatype %in% c(2, 4, 8)) { what <- integer() } else if (datatype %in% c(16, 32, 64)) { what <- double() } else { what <- raw() } signed <- datatype == 2 size <- bitpix/8 ## skip unused entries seek(f, where=76) pixdim <- readBin(f, double(), n=8, size=4, endian=endian) ## pixelwidth in mm xd <- pixdim[2] yd <- pixdim[3] close(f) return(list(ni=ni, nx=nx, ny=ny, xd=xd, yd=yd, endian=endian, what=what, signed=signed, size=size)) } ## Analyze 7.5 img file .readAnalyzeIntensity <- function(filename, header, verbose=FALSE) { if (!file.exists(filename)) { stop(sQuote(filename), " isn't readable.") } if (verbose) { message("Reading intensity values from ", sQuote(filename), " ...") } f <- file(filename, open="rb") i <- readBin(f, what=header$what, n=header$ni*header$nx*header$ny*header$size, size=header$size, signed=header$signed, endian=header$endian) dim(i) <- c(header$ni, header$nx, header$ny) close(f) return(i) } ## Analyze 7.5 t2m file .readAnalyzeMass <- function(filename, header, verbose=FALSE) { if (!file.exists(filename)) { stop(sQuote(filename), " isn't readable.") } if (verbose) { message("Reading mass values from ", sQuote(filename), " ...") } f <- file(filename, open="rb") m <- readBin(f, what=double(), n=header$ni*4, size=4, signed=TRUE, endian=header$endian) close(f) return(m) } r-cran-maldiquantforeign/R/importMzMl-functions.R0000644000175000017500000000255112221046771022346 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .importMzMl <- function(file, verbose=FALSE) { if (verbose) { message("Reading spectrum from ", sQuote(file), " ...") } if (!file.exists(file)) { stop("File ", sQuote(file), " doesn't exists!") } ## read file s <- .parseMzMl(file=file, verbose=verbose) spectra <- lapply(s$spectra, function(x, globalS=s) { m <- modifyList(s$metaData, x$metaData) m$file <- file return(createMassSpectrum(mass=x$mass, intensity=x$intensity, metaData=m)) }) return(spectra) } r-cran-maldiquantforeign/R/importAnalyze-functions.R0000644000175000017500000000331412221046771023070 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .importAnalyze <- function(file, verbose=FALSE) { baseFilename <- .withoutFileExtension(file) header <- .readAnalyzeHdr(file, verbose=verbose) intensity <- .readAnalyzeIntensity(paste(baseFilename, "img", sep="."), header, verbose=verbose) mass <- .readAnalyzeMass(paste(baseFilename, "t2m", sep="."), header, verbose=verbose) l <- vector(mode="list", length=header$nx*header$ny) for (x in 1:header$nx) { for (y in 1:header$ny) { l[[(x-1)*header$ny+y]] <- createMassSpectrum(mass=mass, intensity=intensity[, x, y], metaData=list(file=file, imaging=list(pos=c(x=x, y=y), pixelSize=c(x=header$xd, y=header$yd)))) } } return(l) } r-cran-maldiquantforeign/R/download-function.R0000644000175000017500000000355612221046771021666 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .isUrl <- function(x) { return(grepl(pattern="^https?://|^ftp://", x=x)) } #' @keywords internal .download <- function(url, destfile, verbose=FALSE, ...) { if (missing(destfile)) { pattern <- paste0(.withoutFileExtension(basename(url)), "_") fileext <- paste0(".", .fileExtension(url)) tmpdir <- file.path(tempdir(), "MALDIquantForeign_download") if (!file.exists(tmpdir)) { dir.create(tmpdir, showWarnings=FALSE, recursive=TRUE) } destfile <- file.path(tmpdir, tempfile(pattern=pattern, tmpdir="", fileext=fileext)) } if (verbose) { message("Downloading ", url , " to ", destfile, ".") } for (i in seq(along=url)) { r <- downloader::download(url=url[i], destfile=destfile[i], quiet=!verbose, mode="wb", ...) if (r != 0) { warning("Download of ", url[i], " failed!") } } return(destfile) } #' @keywords internal .cleanupDownloadedTmpFiles <- function() { unlink(file.path(tempdir(), "MALDIquantForeign_download"), recursive=TRUE) } r-cran-maldiquantforeign/R/importCiphergenXml-functions.R0000644000175000017500000000237212221046771024055 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .importCiphergenXml <- function(file, verbose=FALSE) { if (verbose) { message("Reading spectrum from ", sQuote(file), " ...") } if (!file.exists(file)) { stop("File ", sQuote(file), " doesn't exists!") } ## read file s <- .parseCiphergenXml(file=file) return(list(createMassSpectrum(mass=s$spectrum$mass, intensity=s$spectrum$intensity, metaData=s$metaData))) } r-cran-maldiquantforeign/R/compression-functions.R0000644000175000017500000000702612221046771022577 0ustar rusconirusconi## Copyright 2013 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' @keywords internal .isCompressed <- function(x) { z <- c("bz2", "bzip2", "gz", "lzma", "xz") return(.fileExtension(x) %in% c("zip", z, paste("tar", z, sep="."))) } #' @keywords internal .isTar <- function(x) { return(grepl(pattern="^tar", x=.fileExtension(x))) } #' @keywords internal .isZip <- function(x) { return(grepl(pattern="^zip$", x=.fileExtension(x))) } #' @keywords internal .isPackedOrCompressed <- function(x) { return(.isCompressed(x) | .isTar(x)) } #' @keywords internal # unpack/uncompress files and return temporary filenames .uncompress <- function(x, verbose=TRUE) { f <- lapply(x, function(path) { if (!.isPackedOrCompressed(path)) { return(x) } else { if (.isTar(path)) { return(.unpacking(x, fun=untar, verbose=verbose)) } else if (.isZip(path)) { return(.unpacking(x, fun=unzip, verbose=verbose)) } else { return(.gunzip(x, verbose=verbose)) } } }) return(unlist(f)) } #' @keywords internal # unpack and return tmp filename .unpacking <- function(filename, destdir, fun, verbose=FALSE, ...) { if (missing(destdir)) { pattern <- paste0(.withoutFileExtension(basename(filename)), "_") destdir <- file.path(tempdir(), "MALDIquantForeign_uncompress", tempfile(pattern=pattern, tmpdir="")) } funName <- deparse(substitute(fun)) fun <- as.function(fun) if (verbose) { message(funName, " ", filename, " to ", destdir, ".") } unpacked <- fun(filename, exdir=destdir, ...) if (length(unpacked)) { return(destdir) } else { stop(funName, " failed!") } } #' @keywords internal # gunzip and return tmp filename .gunzip <- function(filename, destfile, verbose=FALSE) { if (!file.exists(filename)) { stop(sQuote(filename), " doesn't exist!") } if (missing(destfile)) { tmpdir <- file.path(tempdir(), "MALDIquantForeign_uncompress") if (!file.exists(tmpdir)) { dir.create(tmpdir, showWarnings=FALSE, recursive=TRUE) } pattern <- paste0(.withoutFileExtension(basename(filename)), "_") fileext <- paste0(".", .fileExtension(.withoutCompressionExtension(filename))) destfile <- tempfile(pattern=pattern, tmpdir=tmpdir, fileext=fileext) } if (verbose) { message("gunzip ", filename, " to ", destfile, ".") } fi <- gzfile(filename, open="rb") on.exit(close(fi)) fo <- file(destfile, open="wb") on.exit(close(fo), add=TRUE) repeat { b <- readBin(fi, what=raw(), n=1e6) ## n==1e6 => nearly 50Mb if (length(b)) { writeBin(b, con=fo) } else { break } } return(destfile) } #' @keywords internal .cleanupUncompressedTmpFiles <- function() { unlink(file.path(tempdir(), "MALDIquantForeign_uncompress"), recursive=TRUE) } r-cran-maldiquantforeign/R/exportTab-methods.R0000644000175000017500000000251612221046771021640 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see setMethod(f=".exportTab", signature=signature(x="AbstractMassObject"), definition=function(x, file="", row.names=FALSE, col.names=FALSE, ...) { return(write.table(as.matrix(x), file=file, row.names=row.names, col.names=col.names, ... )) }) setMethod(f=".exportCsv", signature=signature(x="AbstractMassObject"), definition=function(x, file="", sep=",", row.names=FALSE, col.names=TRUE, ...) { return(.exportTab(x, file=file, sep=sep, row.names=row.names, col.names=col.names, ...)) }) r-cran-maldiquantforeign/R/base64encode-functions.R0000644000175000017500000000373512221046771022503 0ustar rusconirusconi## Copyright 2012 Sebastian Gibb ## ## ## This file is part of MALDIquantForeign for R and related languages. ## ## MALDIquantForeign is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## MALDIquantForeign is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with MALDIquantForeign. If not, see #' Converts double to base64 character. #' #' This function converts a \code{double} vector to a base64 encoded #' \code{character} vector. #' #' @param x \code{double}, vector #' @param size \code{integer}, number of bytes per element in the byte stream #' (see \code{size} in \code{\link[base]{writeBin}}). #' @param endian \code{character}, the endian-ness #' (see \code{endian} in \code{\link[base]{writeBin}}). #' @param compressionType \code{character}, type of compression to use for #' compression of \code{x} (see \code{type} in #' \code{\link[base]{memCompress}}. #' @return Vector of type \code{character}. #' @rdname base64-encode #' @author Sebastian Gibb \email{mail@@sebastiangibb.de} #' @seealso \code{\link[base64enc]{base64encode}} from \pkg{base64enc} package #' @keywords internal # .base64encode <- function(x, size, endian=.Platform$endian, compressionType=c("none", "gzip")) { x <- writeBin(as.double(x), con=raw(), size=size, endian=endian) compressionType <- match.arg(compressionType, choices=c("none", "gzip"), several.ok=FALSE) x <- memCompress(from=x, type=compressionType) return(base64enc::base64encode(x)) }