com.compomics.util.experiment.massspectrometry
Class SpectrumFactory

java.lang.Object
  extended by com.compomics.util.experiment.massspectrometry.SpectrumFactory

public class SpectrumFactory
extends Object

This factory will provide the spectra when needed.

Author:
Marc Vaudel, Harald Barsnes

Method Summary
 void addIdNameMapping(String idName, File spectrumFile)
          Adds an id to spectrum name in the mapping.
 void addSpectra(File spectrumFile)
          Add spectra to the factory.
 void addSpectra(File spectrumFile, WaitingHandler waitingHandler)
          Add spectra to the factory.
 void clearFactory()
          Clears the factory getInstance() needs to be called afterwards.
 void closeFiles()
          Closes all opened files.
 boolean fileLoaded(String fileName)
          Returns a boolean indicating whether the spectrum file has been loaded.
 int getCacheSize()
          Returns the spectrum cache size.
 MgfIndex getIndex(File mgfIndex)
          Deserializes the index of an mgf file.
static SpectrumFactory getInstance()
          Static method returning the instance of the factory.
static SpectrumFactory getInstance(int nCache)
          Static method returning the instance of the factory with a new cache size.
 Double getMaxIntensity()
          Returns the maximum precursor intensity for the whole project.
 Double getMaxIntensity(String fileName)
          Returns the maximum precursor intensity for the desired file.
 Double getMaxMz()
          Returns the maximum m/z for the whole project.
 Double getMaxMz(String fileName)
          Returns the maximum m/z for the desired file.
 Double getMaxRT()
          Returns the maximum RT for the whole project.
 Double getMaxRT(String fileName)
          Returns the maximum RT for the desired file.
 ArrayList<String> getMgfFileNames()
          Returns a list of loaded mgf files.
 Double getMinRT()
          Returns the minimum RT for the whole project.
 Double getMinRT(String fileName)
          Returns the minimum RT for the desired file.
 ArrayList<String> getMzMLFileNames()
          Returns a list of loaded mzML files.
 int getNSpectra()
          Returns the total number of spectra in all files.
 int getNSpectra(String fileName)
          Returns the number of spectra in the desired file.
 Precursor getPrecursor(String spectrumKey)
          Returns the precursor of the desired spectrum.
 Precursor getPrecursor(String spectrumKey, boolean save)
          Returns the precursor of the desired spectrum.
 Precursor getPrecursor(String fileName, String spectrumTitle)
          Returns the precursor of the desired spectrum.
 Spectrum getSpectrum(String spectrumKey)
          Returns the desired spectrum.
 Spectrum getSpectrum(String spectrumFile, String spectrumTitle)
          Returns the desired spectrum.
 File getSpectrumFileFromIdName(String idName)
          Returns the spectrum file corresponding to the name of the file used for identification
 ArrayList<String> getSpectrumTitles(String mgfFile)
          Returns a list of titles from indexed spectra in the given file.
 void setCacheSize(int nCache)
          Sets the spectrum cache size.
 boolean spectrumLoaded(String spectrumKey)
          A boolean indicating whether the spectrum is loaded in the factory.
 boolean spectrumLoaded(String fileName, String spectrumTitle)
          Returns a boolean indicating whether the spectrum is contained in the given spectrum file.
 void writeIndex(MgfIndex mgfIndex, File directory)
          Writes the given mgf file index in the given directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static SpectrumFactory getInstance()
Static method returning the instance of the factory.

Returns:
the instance of the factory

getInstance

public static SpectrumFactory getInstance(int nCache)
Static method returning the instance of the factory with a new cache size.

Parameters:
nCache -
Returns:
the instance of the factory with a new cache size

clearFactory

public void clearFactory()
Clears the factory getInstance() needs to be called afterwards.


setCacheSize

public void setCacheSize(int nCache)
Sets the spectrum cache size.

Parameters:
nCache - the new cache size

getCacheSize

public int getCacheSize()
Returns the spectrum cache size.

Returns:
the cache size

addSpectra

public void addSpectra(File spectrumFile)
                throws FileNotFoundException,
                       IOException,
                       ClassNotFoundException
Add spectra to the factory.

Parameters:
spectrumFile - The spectrum file, can be mgf or mzML
Throws:
FileNotFoundException - Exception thrown whenever the file was not found
IOException - Exception thrown whenever an error occurred while reading the file
ClassNotFoundException - Exception thrown whenever an error occurred while deserializing the index .cui file.

addSpectra

public void addSpectra(File spectrumFile,
                       WaitingHandler waitingHandler)
                throws FileNotFoundException,
                       IOException,
                       IllegalArgumentException
Add spectra to the factory.

Parameters:
spectrumFile - The spectrum file, can be mgf or mzML
waitingHandler - the waiting handler
Throws:
FileNotFoundException - Exception thrown whenever the file was not found
IOException - Exception thrown whenever an error occurred while reading the file
IllegalArgumentException - Exception thrown if an unknown format was detected.

getPrecursor

public Precursor getPrecursor(String fileName,
                              String spectrumTitle)
                       throws IOException,
                              uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException
Returns the precursor of the desired spectrum.

Parameters:
fileName - the name of the spectrum file
spectrumTitle - the title of the spectrum
Returns:
the corresponding precursor
Throws:
IOException - exception thrown whenever the file was not parsed correctly
uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException - exception thrown whenever the file was not parsed correctly

getPrecursor

public Precursor getPrecursor(String spectrumKey)
                       throws IOException,
                              uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException,
                              IllegalArgumentException
Returns the precursor of the desired spectrum.

Parameters:
spectrumKey - the key of the spectrum
Returns:
the corresponding precursor
Throws:
IOException - exception thrown whenever the file was not parsed correctly
uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException - exception thrown whenever the file was not parsed correctly
IllegalArgumentException - exception thrown whenever the file was not parsed correctly

getMaxMz

public Double getMaxMz(String fileName)
Returns the maximum m/z for the desired file.

Parameters:
fileName - the file of interest
Returns:
the max m/z

getMaxMz

public Double getMaxMz()
Returns the maximum m/z for the whole project.

Returns:
the max m/z

getMaxIntensity

public Double getMaxIntensity(String fileName)
Returns the maximum precursor intensity for the desired file.

Parameters:
fileName - the file of interest
Returns:
the max precursor intensity

getMaxIntensity

public Double getMaxIntensity()
Returns the maximum precursor intensity for the whole project.

Returns:
the max precursor intensity

getMaxRT

public Double getMaxRT(String fileName)
Returns the maximum RT for the desired file.

Parameters:
fileName - the file of interest
Returns:
the max RT

getMinRT

public Double getMinRT(String fileName)
Returns the minimum RT for the desired file.

Parameters:
fileName - the file of interest
Returns:
the min RT

getMaxRT

public Double getMaxRT()
Returns the maximum RT for the whole project.

Returns:
the max RT

getMinRT

public Double getMinRT()
Returns the minimum RT for the whole project.

Returns:
the min RT

getNSpectra

public int getNSpectra(String fileName)
Returns the number of spectra in the desired file.

Parameters:
fileName - the file of interest
Returns:
the number of spectra

getNSpectra

public int getNSpectra()
Returns the total number of spectra in all files.

Returns:
the total number of spectra in all files

getPrecursor

public Precursor getPrecursor(String spectrumKey,
                              boolean save)
                       throws IOException,
                              uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException,
                              IllegalArgumentException
Returns the precursor of the desired spectrum.

Parameters:
spectrumKey - the key of the spectrum
save - boolean indicating whether the loaded precursor should be stored in the factory
Returns:
the corresponding precursor
Throws:
IOException - exception thrown whenever the file was not parsed correctly
uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException - exception thrown whenever the file was not parsed correctly
IllegalArgumentException - exception thrown whenever the file was not parsed correctly

fileLoaded

public boolean fileLoaded(String fileName)
Returns a boolean indicating whether the spectrum file has been loaded.

Parameters:
fileName - the file name
Returns:
a boolean indicating whether the spectrum file has been loaded

spectrumLoaded

public boolean spectrumLoaded(String fileName,
                              String spectrumTitle)
Returns a boolean indicating whether the spectrum is contained in the given spectrum file.

Parameters:
fileName - the name of the spectrum file
spectrumTitle - the title of the spectrum
Returns:
a boolean indicating whether the spectrum is contained in the given spectrum file

spectrumLoaded

public boolean spectrumLoaded(String spectrumKey)
A boolean indicating whether the spectrum is loaded in the factory.

Parameters:
spectrumKey - the spectrum key
Returns:
a boolean indicating whether the spectrum is loaded in the factory

getSpectrum

public Spectrum getSpectrum(String spectrumFile,
                            String spectrumTitle)
                     throws IOException,
                            uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException
Returns the desired spectrum.

Parameters:
spectrumFile - name of the spectrum file
spectrumTitle - title of the spectrum
Returns:
the desired spectrum
Throws:
IOException - exception thrown whenever an error occurred while reading the file
uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException - exception thrown whenever an error occurred while parsing the mzML file

getSpectrum

public Spectrum getSpectrum(String spectrumKey)
                     throws IOException,
                            IllegalArgumentException,
                            uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException
Returns the desired spectrum.

Parameters:
spectrumKey - key of the spectrum
Returns:
the desired spectrum
Throws:
IOException - exception thrown whenever an error occurred while reading the file
IllegalArgumentException - exception thrown whenever an error occurred while parsing the file
uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException - exception thrown whenever an error occurred while parsing the file

writeIndex

public void writeIndex(MgfIndex mgfIndex,
                       File directory)
                throws IOException
Writes the given mgf file index in the given directory.

Parameters:
mgfIndex - the mgf file index
directory - the destination directory
Throws:
IOException - exception thrown whenever an error is encountered while writing the file

getIndex

public MgfIndex getIndex(File mgfIndex)
                  throws FileNotFoundException,
                         IOException,
                         ClassNotFoundException
Deserializes the index of an mgf file.

Parameters:
mgfIndex - the mgf index cuifile
Returns:
the corresponding mgf index object
Throws:
FileNotFoundException - exception thrown whenever the file was not found
IOException - exception thrown whenever an error was encountered while reading the file
ClassNotFoundException - exception thrown whenever an error occurred while deserializing the object

closeFiles

public void closeFiles()
                throws IOException
Closes all opened files.

Throws:
IOException - exception thrown whenever an error occurred while closing the files

getMgfFileNames

public ArrayList<String> getMgfFileNames()
Returns a list of loaded mgf files.

Returns:
a list of loaded mgf files

getMzMLFileNames

public ArrayList<String> getMzMLFileNames()
Returns a list of loaded mzML files.

Returns:
a list of loaded mzML files

getSpectrumTitles

public ArrayList<String> getSpectrumTitles(String mgfFile)
Returns a list of titles from indexed spectra in the given file.

Parameters:
mgfFile - the name of the mgf file
Returns:
a list of titles from indexed spectra in the given file

addIdNameMapping

public void addIdNameMapping(String idName,
                             File spectrumFile)
Adds an id to spectrum name in the mapping.

Parameters:
idName - name according to the id file
spectrumFile - the spectrum file

getSpectrumFileFromIdName

public File getSpectrumFileFromIdName(String idName)
Returns the spectrum file corresponding to the name of the file used for identification

Parameters:
idName - the name of the spectrum file according to the identification file
Returns:
the spectrum file


Copyright © 2012. All Rights Reserved.