com.compomics.util.experiment.massspectrometry
Class SpectrumFactory

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

public class SpectrumFactory
extends java.lang.Object

This factory will provide the spectra when needed

Author:
marc

Method Summary
 void addSpectra(java.io.File spectrumFile)
          Add spectra to the factory
 void closeFiles()
          Closes all opened files
 int getCacheSize()
          returns the cache size
 MgfIndex getIndex(java.io.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
 java.util.ArrayList<java.lang.String> getMgfFileNames()
          Returns a list of loaded mgf files
 java.util.ArrayList<java.lang.String> getMzMLFileNames()
          Returns a list of loaded mzML files
 Precursor getPrecursor(java.lang.String spectrumKey)
          Returns the precursor of the desired spectrum
 Precursor getPrecursor(java.lang.String fileName, java.lang.String spectrumTitle)
          Returns the precursor of the desired spectrum
 Spectrum getSpectrum(java.lang.String spectrumKey)
          Returns the spectrum desired
 Spectrum getSpectrum(java.lang.String SpectrumFile, java.lang.String SpectrumTitle)
          Returns the spectrum desired
 java.util.ArrayList<java.lang.String> getSpectrumTitles(java.lang.String mgfFile)
          Returns a list of titles from indexed spectra in the given file
 void setCacheSize(int nCache)
          Sets the cache size
 void writeIndex(MgfIndex mgfIndex, java.io.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:

setCacheSize

public void setCacheSize(int nCache)
Sets the cache size

Parameters:
nCache - the new cache size

getCacheSize

public int getCacheSize()
returns the cache size

Returns:
the cache size

addSpectra

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

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

getPrecursor

public Precursor getPrecursor(java.lang.String fileName,
                              java.lang.String spectrumTitle)
                       throws java.lang.Exception
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:
java.lang.Exception - exception thrown whenever the file was not parsed correctly

getPrecursor

public Precursor getPrecursor(java.lang.String spectrumKey)
                       throws java.lang.Exception
Returns the precursor of the desired spectrum

Parameters:
spectrumKey - the key of the spectrum
Returns:
the corresponding precursor
Throws:
java.lang.Exception - exception thrown whenever the file was not parsed correctly

getSpectrum

public Spectrum getSpectrum(java.lang.String SpectrumFile,
                            java.lang.String SpectrumTitle)
                     throws java.io.IOException,
                            java.lang.Exception
Returns the spectrum desired

Parameters:
fileName - name of the spectrum file
spectrumTitle - title of the spectrum
Returns:
the desired spectrum
Throws:
java.io.IOException - exception thrown whenever an error occurred while reading the file
java.lang.Exception - exception thrown whenever an error occurred while parsing the file

getSpectrum

public Spectrum getSpectrum(java.lang.String spectrumKey)
                     throws java.io.IOException,
                            java.lang.Exception
Returns the spectrum desired

Parameters:
spectrumKey - key of the spectrum
Returns:
the desired spectrum
Throws:
java.io.IOException - exception thrown whenever an error occurred while reading the file
java.lang.Exception - exception thrown whenever an error occurred while parsing the file

writeIndex

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

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

getIndex

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

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

closeFiles

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

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

getMgfFileNames

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

Returns:
a list of loaded mgf files

getMzMLFileNames

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

Returns:
a list of loaded mzML files

getSpectrumTitles

public java.util.ArrayList<java.lang.String> getSpectrumTitles(java.lang.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


Copyright © 2011. All Rights Reserved.