com.compomics.util.experiment.io.massspectrometry
Class MgfReader

java.lang.Object
  extended by com.compomics.util.experiment.io.massspectrometry.MgfReader

public class MgfReader
extends Object

This class will read an MGF file.

Author:
Marc Vaudel, Harald Barsnes

Constructor Summary
MgfReader()
          General constructor for an mgf reader.
 
Method Summary
static void fixDuplicateSpectrumTitles(File mgfFile, WaitingHandler waitingHandler)
          Fix duplicate spectrum titles.
static MgfIndex getIndexMap(File mgfFile)
          Returns the index of all spectra in the given mgf file.
static MgfIndex getIndexMap(File mgfFile, WaitingHandler waitingHandler)
          Returns the index of all spectra in the given MGF file.
static Precursor getPrecursor(uk.ac.ebi.pride.tools.braf.BufferedRandomAccessFile bufferedRandomAccessFile, Long index, String fileName)
          Returns the next precursor starting from the given index.
 ArrayList<MSnSpectrum> getSpectra(File aFile)
          Reads an MGF file and retrieves a list of spectra.
static MSnSpectrum getSpectrum(uk.ac.ebi.pride.tools.braf.BufferedRandomAccessFile bufferedRandomAccessFile, long index, String fileName)
          Returns the next spectrum starting from the given index.
 ArrayList<MgfIndex> splitFile(File mgfFile, int nSpectra, WaitingHandler waitingHandler)
          Splits an mgf file into smaller ones and returns the indexes of the generated files.
static String validateSpectrumTitles(File mgfFile, WaitingHandler waitingHandler)
          Validates the spectrum titles, i.e., check for duplicate titles.
static void writeAplFile(File mgfFile, File aplFile, String fragmentation)
          Writes an apl file from an MGF file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MgfReader

public MgfReader()
General constructor for an mgf reader.

Method Detail

getSpectra

public ArrayList<MSnSpectrum> getSpectra(File aFile)
                                  throws FileNotFoundException,
                                         IOException,
                                         IllegalArgumentException
Reads an MGF file and retrieves a list of spectra.

Parameters:
aFile - the mgf file
Returns:
list of MSnSpectra imported from the file
Throws:
FileNotFoundException - Exception thrown if a problem is encountered reading the file
IOException - Exception thrown if a problem is encountered reading the file
IllegalArgumentException - thrown when a parameter in the file cannot be parsed correctly

getIndexMap

public static MgfIndex getIndexMap(File mgfFile)
                            throws FileNotFoundException,
                                   IOException
Returns the index of all spectra in the given mgf file.

Parameters:
mgfFile - the given mgf file
Returns:
the index of all spectra
Throws:
FileNotFoundException - Exception thrown whenever the file is not found
IOException - Exception thrown whenever an error occurs while reading the file

getIndexMap

public static MgfIndex getIndexMap(File mgfFile,
                                   WaitingHandler waitingHandler)
                            throws FileNotFoundException,
                                   IOException
Returns the index of all spectra in the given MGF file.

Parameters:
mgfFile - the given MGF file
waitingHandler - a waitingHandler showing the progress
Returns:
the index of all spectra
Throws:
FileNotFoundException - Exception thrown whenever the file is not found
IOException - Exception thrown whenever an error occurs while reading the file

validateSpectrumTitles

public static String validateSpectrumTitles(File mgfFile,
                                            WaitingHandler waitingHandler)
                                     throws FileNotFoundException,
                                            IOException
Validates the spectrum titles, i.e., check for duplicate titles.

Parameters:
mgfFile - the MGF file to validate
waitingHandler - a waitingHandler showing the progress
Returns:
the first duplicate spectrum title, or null of no duplicate spectrum titles
Throws:
FileNotFoundException - Exception thrown whenever the file is not found
IOException - Exception thrown whenever an error occurs while reading the file

fixDuplicateSpectrumTitles

public static void fixDuplicateSpectrumTitles(File mgfFile,
                                              WaitingHandler waitingHandler)
                                       throws FileNotFoundException,
                                              IOException,
                                              UnsupportedEncodingException
Fix duplicate spectrum titles. Adds (2), (3) etc, behind the duplicate spectrum titles.

Parameters:
mgfFile - the MGF file to validate
waitingHandler - a waitingHandler showing the progress
Throws:
FileNotFoundException - Exception thrown whenever the file is not found
IOException - Exception thrown whenever an error occurs while reading the file
UnsupportedEncodingException - if the decoding of a spectrum title fails

splitFile

public ArrayList<MgfIndex> splitFile(File mgfFile,
                                     int nSpectra,
                                     WaitingHandler waitingHandler)
                              throws FileNotFoundException,
                                     IOException
Splits an mgf file into smaller ones and returns the indexes of the generated files.

Parameters:
mgfFile - the mgf file to split
nSpectra - the number of spectra allowed in the smaller files
waitingHandler - the waitingHandler showing the progress
Returns:
a list of indexes of the generated files
Throws:
FileNotFoundException - exception thrown whenever a file was not found
IOException - exception thrown whenever a problem occurred while reading/writing a file

getSpectrum

public static MSnSpectrum getSpectrum(uk.ac.ebi.pride.tools.braf.BufferedRandomAccessFile bufferedRandomAccessFile,
                                      long index,
                                      String fileName)
                               throws IOException,
                                      IllegalArgumentException
Returns the next spectrum starting from the given index.

Parameters:
bufferedRandomAccessFile - The random access file of the inspected mgf file
index - The index where to start looking for the spectrum
fileName - The name of the MGF file (
Returns:
The next spectrum encountered
Throws:
IOException - Exception thrown whenever an error is encountered while reading the spectrum
IllegalArgumentException - Exception thrown whenever the file is not of a compatible format

getPrecursor

public static Precursor getPrecursor(uk.ac.ebi.pride.tools.braf.BufferedRandomAccessFile bufferedRandomAccessFile,
                                     Long index,
                                     String fileName)
                              throws IOException,
                                     IllegalArgumentException
Returns the next precursor starting from the given index.

Parameters:
bufferedRandomAccessFile - The random access file of the inspected mgf file
index - The index where to start looking for the spectrum
fileName - The name of the mgf file (
Returns:
The next spectrum encountered
Throws:
IOException - Exception thrown whenever an error is encountered while reading the spectrum
IllegalArgumentException - Exception thrown whenever the file is not of a compatible format

writeAplFile

public static void writeAplFile(File mgfFile,
                                File aplFile,
                                String fragmentation)
                         throws FileNotFoundException,
                                IOException,
                                IllegalArgumentException
Writes an apl file from an MGF file.

Parameters:
mgfFile - the mgf file
aplFile - the target apl file
fragmentation - the fragmentation method used
Throws:
FileNotFoundException - exception thrown whenever a file was not found
IOException - exception thrown whenever an error occurred while reading/writing a file
IllegalArgumentException - exception thrown whenever the mgf file is truncated in the middle of a spectrum


Copyright © 2013. All Rights Reserved.