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

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

public class MgfReader
extends java.lang.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 MgfIndex getIndexMap(java.io.File mgfFile)
          Returns the index of all spectra in the given mgf file.
static MgfIndex getIndexMap(java.io.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, java.lang.Long index, java.lang.String fileName)
          Returns the next precursor starting from the given index.
 java.util.ArrayList<MSnSpectrum> getSpectra(java.io.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, java.lang.String fileName)
          Returns the next spectrum starting from the given index.
 java.util.ArrayList<MgfIndex> splitFile(java.io.File mgfFile, int nSpectra, WaitingHandler waitingHandler)
          Splits an mgf file into smaller ones and returns the indexes of the generated files.
static void writeAplFile(java.io.File mgfFile, java.io.File aplFile, java.lang.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 java.util.ArrayList<MSnSpectrum> getSpectra(java.io.File aFile)
                                            throws java.io.FileNotFoundException,
                                                   java.io.IOException,
                                                   java.lang.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:
java.io.FileNotFoundException - Exeption thrown if a problem is encountered reading the file
java.io.IOException - Exception thrown if a problem is encountered reading the file
java.lang.IllegalArgumentException - thrown when a parameter in the file cannot be parsed correctly

getIndexMap

public static MgfIndex getIndexMap(java.io.File mgfFile)
                            throws java.io.FileNotFoundException,
                                   java.io.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:
java.io.FileNotFoundException - Exception thrown whenever the file is not found
java.io.IOException - Exception thrown whenever an error occurs while reading the file

getIndexMap

public static MgfIndex getIndexMap(java.io.File mgfFile,
                                   WaitingHandler waitingHandler)
                            throws java.io.FileNotFoundException,
                                   java.io.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:
java.io.FileNotFoundException - Exception thrown whenever the file is not found
java.io.IOException - Exception thrown whenever an error occurs while reading the file

splitFile

public java.util.ArrayList<MgfIndex> splitFile(java.io.File mgfFile,
                                               int nSpectra,
                                               WaitingHandler waitingHandler)
                                        throws java.io.FileNotFoundException,
                                               java.io.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:
java.io.FileNotFoundException - exception thrown whenever a file was not found
java.io.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,
                                      java.lang.String fileName)
                               throws java.io.IOException,
                                      java.lang.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 (@TODO get this from the random access file?)
Returns:
The next spectrum encountered
Throws:
java.io.IOException - Exception thrown whenever an error is encountered while reading the spectrum
java.lang.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,
                                     java.lang.Long index,
                                     java.lang.String fileName)
                              throws java.io.IOException,
                                     java.lang.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 (@TODO get this from the random access file?)
Returns:
The next spectrum encountered
Throws:
java.io.IOException - Exception thrown whenever an error is encountered while reading the spectrum
java.lang.IllegalArgumentException - Exception thrown whenever the file is not of a compatible format

writeAplFile

public static void writeAplFile(java.io.File mgfFile,
                                java.io.File aplFile,
                                java.lang.String fragmentation)
                         throws java.io.FileNotFoundException,
                                java.io.IOException,
                                java.lang.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:
java.io.FileNotFoundException - exception thrown whenever a file was not found
java.io.IOException - exception thrown whenever an error occurred while reading/writing a file
java.lang.IllegalArgumentException - exception thrown whenever the mgf file is truncated in the middle of a spectrum


Copyright © 2013. All Rights Reserved.