Proteome Informatics Group > Java Proteomic Library

Generic MS Parsers


Our MS readers (specific and generic) can parse files of many formats like mgf, mzxml or mzml.

These parsers have the main advantage of handling huge data file through iterators and filters.

It is also possible to handle bunches of spectra in the fly in the limit of available memory.

Specific Parsing

We provide a few specific MS parsers that may be create explicitly and that parse specific file format (dta, mgf, mzxml, ...):


// build the specific parser
MZXMLReader reader = MZXMLReader.newInstance();


// get the iterator over spectrum
Iterator<MassSpectrum> it = reader.iterator();
while (it.hasNext()) {
	// get next spectrum;

Generic Parsing

We also propose a more generic way to parse MS spectra:


// build a new generic MS parser
MSReader reader = MSReaderFacade.newInstance();

// get infos on run

// get the iterator over spectrum
Iterator<MassSpectrum> it = reader.iterator();

while (it.hasNext()) {
	// get next spectrum;

You can also limit the kind of file this generic parser may parse:

// this reader is only able to read ms spectra library 
reader = MSReaderFacade.withExtension(Pattern.compile("msp|sptxt",

// the following call will throw a ParseException as mgf format
// is not readable by this parser

Parsing With Filters

Filters (through JPLICondition) can be defined and coupled to any MS parsers to select spectra to keep:

import org.expasy.jpl.core.util.condition.Condition;
import org.expasy.jpl.core.util.condition.ConditionImpl;
import org.expasy.jpl.core.util.condition.operator.OperatorLowerThan;

// a ms level filter on spectrum
Condition<MassSpectrum> msLevelFilter(int level) {
	// show how to access mslevel from a spectrum
	Transformer<MassSpectrum, Integer> sp2level =
		new Transformer<MassSpectrum, Integer>() {
			public Integer process(MassSpectrum sp) {
	        	return sp.getPeakList().getMsLevel();
	return new ConditionImpl.Builder<MassSpectrum, Integer>(level)

Iterator<MassSpectrum> it = reader.iterator();

while (it.hasNext()) {
	// get next MS1 spectrum;

Look conditions in jpl-commons for more informations.

Progress Bar Ready

All Progression bar that implements JPLProgressBar can be given to any MS parser:

// a generic parser
MSReader parser = MSReaderFacade.newInstance();
// new terminal progress bar
TerminalProgressBar pb =

// set the progress bar length

// set the roaming segment length


parser.parse(new File(paramManager.getFilename()));

Iterator it = parser.iterator();
while (it.hasNext()) {
	// each entry parsed internally
	// increments the step in the progress bar;

//  0   [============        ]
// ..   [       ============ ]
// 1000 [    ============    ]
// 5949 [      ============  ]
// ..
// 5979 [       ============ ]
// ..
// 9208 [====================]
// task finished
TerminalProgressBar and JProgressBarAdapter all implements ProgressBar.

Block Parsing

Another mode of parsing is available in the new version. It consists of returning blocks of spectra at once:


Iterator<MassSpectrum> it = reader.iterator();

// the number of spectra max in a block (depending on
// allocated memory)

// get the next block
List<MassSpectrum> l = it.nextToList(245);

while (it.hasNext()) {
	// get the next bunch of spectra
	l = it.nextToList();

Calls to nextToList() may pose some kind of memory issues when executed on large files. Ms-readers deal with this problem by automatically estimating and controlling the limit in the size of each returned list.

Hopefully, the memory management for those who would like to tune the block parameters can also be handled easily:

// set the maximum part of total free memory dedicated to the 
// nextToList block for all ms-readers (optional)

// set the max memory in bytes for a block (100 KB)


Iterator<MassSpectrum> it = reader.iterator();

// get the next block
List<MassSpectrum> l = it.nextToList();

// comparing with the max number of spectra in a block equivalent 
// to a size of 100 KB 
AssertTrue(l.size() <= reader.getNextToListMaxSize());
The memory test is enabled by default, it can be disabled from method "enableMemoryTest(false)".