java.lang.Object
com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler
All Implemented Interfaces:
SpectrumProvider, AutoCloseable

public class MsFileHandler extends Object implements SpectrumProvider
A spectrum provider for mass spectrometry files based on Compomics Mass Spectrometry (cms) files.
Author:
Marc Vaudel, Harald Barsnes
  • Constructor Details

    • MsFileHandler

      public MsFileHandler()
      Constructor.
  • Method Details

    • register

      public void register(File msFile, WaitingHandler waitingHandler) throws IOException
      Registers a mass spectrometry file and enables querying its spectra.If the file is not a cms file, a cms file will be created along with the ms file.
      Parameters:
      msFile - The mass spectrometry file to register.
      waitingHandler - The waiting handler.
      Throws:
      IOException - Exception thrown if an error occurs while reading or writing a file.
    • register

      public void register(File msFile, File cmsFolder, WaitingHandler waitingHandler) throws IOException
      Registers a mass spectrometry file and enables querying its spectra. If the file is not a cms file, a cms file will be created in the cms folder if not null, along the ms file otherwise.
      Parameters:
      msFile - The mass spectrometry file to register.
      cmsFolder - The folder where to save the cms files.
      waitingHandler - The waiting handler.
      Throws:
      IOException - Exception thrown if an error occurs while reading or writing a file.
    • getCmsFilePath

      public static String getCmsFilePath(File msFile, File cmsFolder)
      Returns the path of the cms file expected for the given mass spectrometry file and cms folder.
      Parameters:
      msFile - The mass spectrometry file.
      cmsFolder - The folder where to save the cms files.
      Returns:
      The path of the cms file.
    • getReader

      public CmsFileReader getReader(String fileNameWithoutExtension)
      Returns the cms file reader for the given ms file. Null if not set.
      Parameters:
      fileNameWithoutExtension - The name of the ms file without file extension.
      Returns:
      The cms file reader.
    • getSpectrum

      public Spectrum getSpectrum(String fileNameWithoutExtension, String spectrumTitle)
      Description copied from interface: SpectrumProvider
      Returns the spectrum with the given title in the given file.
      Specified by:
      getSpectrum in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      spectrumTitle - The title of the spectrum.
      Returns:
      The spectrum with the given title in the given file.
    • getPrecursor

      public Precursor getPrecursor(String fileNameWithoutExtension, String spectrumTitle)
      Description copied from interface: SpectrumProvider
      Returns the precursor. Null if none.
      Specified by:
      getPrecursor in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      spectrumTitle - The title of the spectrum.
      Returns:
      The precursor.
    • getPrecursorMz

      public double getPrecursorMz(String fileNameWithoutExtension, String spectrumTitle)
      Description copied from interface: SpectrumProvider
      Returns the measured precursor m/z. NaN if none.
      Specified by:
      getPrecursorMz in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      spectrumTitle - The title of the spectrum.
      Returns:
      The measured precursor m/z.
    • getPrecursorRt

      public double getPrecursorRt(String fileNameWithoutExtension, String spectrumTitle)
      Description copied from interface: SpectrumProvider
      Returns the precursor RT window. NaN if none.
      Specified by:
      getPrecursorRt in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      spectrumTitle - The title of the spectrum.
      Returns:
      The precursor RT.
    • getSpectrumLevel

      public int getSpectrumLevel(String fileNameWithoutExtension, String spectrumTitle)
      Description copied from interface: SpectrumProvider
      Returns the spectrum level.
      Specified by:
      getSpectrumLevel in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      spectrumTitle - The title of the spectrum.
      Returns:
      The spectrum level.
    • getPeaks

      public double[][] getPeaks(String fileNameWithoutExtension, String spectrumTitle)
      Description copied from interface: SpectrumProvider
      Returns the spectrum peaks.
      Specified by:
      getPeaks in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      spectrumTitle - The title of the spectrum.
      Returns:
      The peaks.
    • getMinPrecMz

      public double getMinPrecMz(String fileNameWithoutExtension)
      Description copied from interface: SpectrumProvider
      Returns the minimum precursor m/z in a given file.
      Specified by:
      getMinPrecMz in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      Returns:
      The minimum precursor m/z in a given file.
    • getMaxPrecMz

      public double getMaxPrecMz(String fileNameWithoutExtension)
      Description copied from interface: SpectrumProvider
      Returns the maximum precursor m/z in a given file.
      Specified by:
      getMaxPrecMz in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      Returns:
      The maximum precursor m/z in a given file.
    • getMaxPrecInt

      public double getMaxPrecInt(String fileNameWithoutExtension)
      Description copied from interface: SpectrumProvider
      Returns the maximum precursor intensity in a given file.
      Specified by:
      getMaxPrecInt in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      Returns:
      The maximum precursor intensity in a given file.
    • getMaxPrecRT

      public double getMaxPrecRT(String fileNameWithoutExtension)
      Description copied from interface: SpectrumProvider
      Returns the maximum precursor RT in a given file.
      Specified by:
      getMaxPrecRT in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      Returns:
      The maximum precursor RT in a given file.
    • getMinPrecMz

      public double getMinPrecMz()
      Description copied from interface: SpectrumProvider
      Returns the minimum precursor m/z among all files.
      Specified by:
      getMinPrecMz in interface SpectrumProvider
      Returns:
      The minimum precursor m/z among all files.
    • getMaxPrecMz

      public double getMaxPrecMz()
      Description copied from interface: SpectrumProvider
      Returns the maximum precursor m/z among all files.
      Specified by:
      getMaxPrecMz in interface SpectrumProvider
      Returns:
      The maximum precursor m/z among all files.
    • getMaxPrecInt

      public double getMaxPrecInt()
      Description copied from interface: SpectrumProvider
      Returns the maximum precursor intensity among all files.
      Specified by:
      getMaxPrecInt in interface SpectrumProvider
      Returns:
      The maximum precursor intensity among all files.
    • getMaxPrecRT

      public double getMaxPrecRT()
      Description copied from interface: SpectrumProvider
      Returns the maximum precursor RT among all files.
      Specified by:
      getMaxPrecRT in interface SpectrumProvider
      Returns:
      The maximum precursor RT among all files.
    • getOrderedFileNamesWithoutExtensions

      public String[] getOrderedFileNamesWithoutExtensions()
      Description copied from interface: SpectrumProvider
      Returns the spectrum file names without file extensions.
      Specified by:
      getOrderedFileNamesWithoutExtensions in interface SpectrumProvider
      Returns:
      The spectrum file names without file extensions.
    • getFilePaths

      public HashMap<String,String> getFilePaths()
      Description copied from interface: SpectrumProvider
      Returns the absolute path to the original mass spec file containing the spectra in a map indexed by file name without file extension.
      Specified by:
      getFilePaths in interface SpectrumProvider
      Returns:
      The absolute path to the original mass spec file containing the spectra in a map indexed by file name.
    • getCmsFilePaths

      public HashMap<String,String> getCmsFilePaths()
      Description copied from interface: SpectrumProvider
      Returns the absolute path to the cms file indexed by ms file name without file extension. Null if none.
      Specified by:
      getCmsFilePaths in interface SpectrumProvider
      Returns:
      The absolute path to the cms file indexed by ms file name.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SpectrumProvider
    • getSpectrumTitles

      public String[] getSpectrumTitles(String fileName)
      Description copied from interface: SpectrumProvider
      Returns the spectrum titles for the given mass spectrometry file name.
      Specified by:
      getSpectrumTitles in interface SpectrumProvider
      Parameters:
      fileName - The mass spectrometry file name without file extension.
      Returns:
      The spectrum titles as array.
    • getPostcursorSpectrumTitles

      public ArrayList<String> getPostcursorSpectrumTitles(String fileNameWithoutExtension, String spectrumTitle)
      Description copied from interface: SpectrumProvider
      Returns the postcursor spectrum titles. Null if none.
      Specified by:
      getPostcursorSpectrumTitles in interface SpectrumProvider
      Parameters:
      fileNameWithoutExtension - The name of the spectrum file without file extension.
      spectrumTitle - The title of the spectrum.
      Returns:
      The postcursor spectrum titles. Null if none.