Proteome Informatics Group > Java Proteomic Library
 

Recipe 3.7. Filtering MS peak lists

Problem

You want to filter MS peak lists.

Solution

A filter process a MS peak list and return a sub-peak list with selected peaks only. Any MS filters have to subclass AbstractPeakListFilter.

import org.expasy.jpl.core.ms.spectrum.filter.*;
import org.expasy.jpl.core.ms.spectrum.PeakList;

// the peak list to filter
PeakList pl =
	new PeakListImpl.Builder(new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
		.intensities(new double[] {2, 4, 6, 8, 10, 1, 3, 5, 7, 9})
		.build();

// this filter select the 3 most intense peaks 
AbstractPeakListFilter filter = new NHighestPeaksFilter(3);

// the filter object make the job here
PeakList subPl = filter.transform(pl);

final double[] ms = newPL.getMzs();		
Assert.assertTrue(Arrays.equals(new double[] {4.0, 5.0, 10.0}, ms));

A filter can also include a list of approved mzs even if it does not pass the filter:

import import org.apache.commons.collections15.Transformer;

// this filter select the 3 most intense peaks 
AbstractPeakListFilter filter = new NHighestPeaksFilter(3);

// a white list with a tolerance
filter.setWhiteList(Arrays.asList(2.3), 0.5);

// the filter object make the job here
PeakList subPl = filter.transform(pl);

final double[] ms = newPL.getMzs();		
Assert.assertTrue(Arrays.equals(new double[] {2.0, 4.0, 5.0, 10.0}, ms));

Discussion

See Also