peakml
Class MassChromatogram<gPeak extends Peak>

java.lang.Object
  extended by peakml.Annotatable
      extended by peakml.IPeak
          extended by peakml.MassChromatogram<gPeak>
Type Parameters:
gPeak - The type of peaks stored in this mass chromatogram.
All Implemented Interfaces:
java.lang.Iterable<gPeak>

public class MassChromatogram<gPeak extends Peak>
extends IPeak
implements java.lang.Iterable<gPeak>

Implementation of a mass chromatogram, usable for LC-MS, GC-MS, or any 2 dimensional mass spectrometry method. This class maintains a list of peaks (either Centroid or Profile), which make up the mass chromatogram. When a list of Centroid is maintained the mass chromatogram is 2D, but if a list of Profile is maintained the mass chromatogram is 3D. A mass chromatogram is expected to display a normal or log-normal distribution.

The constructor of this class automatically calculates a number of properties, like: mass, intensity and scan out of the peaks associated with the mass chromatogram. A constructor is supplied, which allows the calculation of the mass with a different method than the standard weighted mean, which assumes that mass measurements with low intensity have a low accuracy.


Nested Class Summary
static interface MassChromatogram.MassCalculator<Type extends Peak>
          In order to accommodate for a different calculation of the mass for a mass chromatogram, implement this interface.
 
Nested classes/interfaces inherited from class peakml.IPeak
IPeak.AnnotationAscending, IPeak.AnnotationDescending, IPeak.MatchCompare<Type>, IPeak.RelationCompare<Type>
 
Field Summary
static MassChromatogram.MassCalculator<Peak> standard_masscalculator
          Standard implementation of the mass calculator, which reduces memory requirements.
 
Fields inherited from class peakml.IPeak
relationid, sort_intensity_ascending, sort_intensity_descending, sort_mass_ascending, sort_mass_descending, sort_patternid_ascending, sort_patternid_descending, sort_profileid_ascending, sort_profileid_descending, sort_retentiontime_ascending, sort_retentiontime_descending, sort_scanid_ascending, sort_scanid_descending
 
Constructor Summary
MassChromatogram(PeakData<gPeak> peakdata)
          Constructs a new mass chromatogram instance out of the given set of peaks (either Centroid or Profile).
MassChromatogram(PeakData<gPeak> peakdata, MassChromatogram.MassCalculator<gPeak> mass)
          Constructs a new mass chromatogram instance out of the given set of peaks (either Centroid or Profile).
 
Method Summary
 double coda()
          Simplistic implementation of the CoDA algorithm working on individual mass chromatograms.
 double codaDW()
          Implementation of a CoDA-like approach for evalution of an individual mass chromatogram based on the Durbin-Watson statistic.
 double codaSW()
          Implementation of a CoDA-like approach for evaluation of an individual mass chromatogram based on the Shapiro-Wilk test.
 double getIntensity()
          Retrieves the measured intensity for this peak.
 double getMass()
          Retrieves the mass of this peak.
 double getMaxIntensity()
          Returns the maximum intensity of all the peaks associated with this mass chromatogram.
 double getMaxMass()
          Returns the maximum mass of all the peaks associated with this mass chromatogram.
 double getMaxRetentionTime()
          Returns the retention time where the mass chromatogram ends (e.g.
 int getMaxScanID()
          Returns the maximum scan of all the peaks associated with this mass chromatogram.
 int getMeasurementID()
          Returns an optional measurement-id for this peak.
 double getMinIntensity()
          Returns the minimum intensity of all the peaks associated with this mass chromatogram.
 double getMinMass()
          Returns the minimum mass of all the peaks associated with this mass chromatogram.
 double getMinRetentionTime()
          Returns the retention time where the mass chromatogram begins (e.g.
 int getMinScanID()
          Returns the minimum scan of all the peaks associated with this mass chromatogram.
 int getNrPeaks()
          Returns the number of peaks associated with this mass chromatogram.
 int getPatternID()
          Returns an optional id for the peak.
 gPeak getPeak(int pos)
          Retrieves the peak at position pos.
 PeakData<gPeak> getPeakData()
          Returns the PeakData instance associated to this MassChromatogram, containing all the peak-information.
 double getPeakRetentionTime()
          Returns the retention time where the mass chromatogram is most intense.
 java.util.Vector<gPeak> getPeaks()
          Returns the vector filled with all the peaks associated to this mass chromatogram.
 int getPeakScanID()
          Returns the scan where the mass chromatogram is most intense.
 double getRetentionTime()
          Retrieves the retention time for this peak.
 int getScanID()
          Retrieves the scan-id for this peak.
 Signal getSignal()
          Calculates the signal for this IPeak object.
 double getTotalIntensity()
          Returns the total intensity of the mass chromatogram.
 java.util.Iterator<gPeak> iterator()
           
 void savitzkyGolay()
           
 void savitzkyGolay(SavitzkyGolayFilter.Points p)
           
 void setIntensity(double intensity)
          Sets the intensity of this peak, for more information on mass see IPeak.getIntensity().
 void setMass(double mass)
          Sets the mass of this peak, for more information on mass see IPeak.getMass().
 void setMeasurementID(int id)
          Sets the profile-id of this peak, for more information on mass see IPeak.getMeasurementID().
 void setPatternID(int id)
          Sets the pattern-id of this peak, for more information on mass see IPeak.getPatternID().
 void setRetentionTime(double retentiontime)
          Sets the retention time for this peak, for more information on retention time see IPeak.setRetentionTime(double).
 void setScanID(int scan)
          Sets the scan-id for this peak, for more information on scan-id see IPeak.getScanID().
 
Methods inherited from class peakml.IPeak
findRelatedPeaks, getBestPeakOnMass, getBestPeakOnRT, match, match, peaksOfMeasurements, sha1, unpack
 
Methods inherited from class peakml.Annotatable
addAnnotation, addAnnotation, addAnnotation, addAnnotation, addAnnotation, addAnnotations, getAnnotation, getAnnotations, removeAllAnnotations, removeAnnotation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

standard_masscalculator

public static MassChromatogram.MassCalculator<Peak> standard_masscalculator
Standard implementation of the mass calculator, which reduces memory requirements.

Constructor Detail

MassChromatogram

public MassChromatogram(PeakData<gPeak> peakdata)
Constructs a new mass chromatogram instance out of the given set of peaks (either Centroid or Profile). The calculations of the properties are done in MassChromatogram(PeakData, peakml.MassChromatogram.MassCalculator), where the mass calculation has been implemented to calculate a weighted mean, where the intensity is used as the weight so that peaks of low intensity have a low impact on the mean. This makes sense as for most mass spectrometers it's assumed that a low intensity peak has a high deviation from the true mass.

Parameters:
peakdata - The PeakData instance containing the data of this mass chromatogram.

MassChromatogram

public MassChromatogram(PeakData<gPeak> peakdata,
                        MassChromatogram.MassCalculator<gPeak> mass)
Constructs a new mass chromatogram instance out of the given set of peaks (either Centroid or Profile). All the properties associated to a mass chromatogram are calculated here. This means that min and max scan, min and max intensity, and the total intensity of the peak are calculated. The parameter mass can be used to plug a new mass calculation MassChromatogram.MassCalculator class, which can be suited to different needs than the standard weighted mean.

Parameters:
peakdata - The PeakData instance containing the data of this mass chromatogram.
mass - An instance of MassChromatogram.MassCalculator
Method Detail

getMass

public double getMass()
Description copied from class: IPeak
Retrieves the mass of this peak. For a single peak implementation this would be the real mass, but for a chromatographic peak for example this would consist of the mean of a cluster of peaks.

Specified by:
getMass in class IPeak
Returns:
The mass of the peak.

setMass

public void setMass(double mass)
Description copied from class: IPeak
Sets the mass of this peak, for more information on mass see IPeak.getMass(). It is possible that the class implementing this interface does not support this method.

Specified by:
setMass in class IPeak
Parameters:
mass - The new mass for this peak.

getIntensity

public double getIntensity()
Description copied from class: IPeak
Retrieves the measured intensity for this peak. For a single peak implementation this would be the real measured intensity, but for a chromatographic peak for example this would consist of the mean measured intensity for a cluster of peaks.

Specified by:
getIntensity in class IPeak
Returns:
The measured intensity of the peak.

setIntensity

public void setIntensity(double intensity)
Description copied from class: IPeak
Sets the intensity of this peak, for more information on mass see IPeak.getIntensity(). It is possible that the class implementing this interface does not support this method.

Specified by:
setIntensity in class IPeak
Parameters:
intensity - The new intensity for this peak.

getScanID

public int getScanID()
Description copied from class: IPeak
Retrieves the scan-id for this peak. For a single peak implementation this would be the scan at which it was measured, but for a chromatographic peak for example this would be the scan with the most intense peak.

Specified by:
getScanID in class IPeak
Returns:
The scan at which the peak was measured.

setScanID

public void setScanID(int scan)
Description copied from class: IPeak
Sets the scan-id for this peak, for more information on scan-id see IPeak.getScanID(). It is possible that the class implementing this interface does not support this method.

Specified by:
setScanID in class IPeak
Parameters:
scan - The new scan for this peak.

getRetentionTime

public double getRetentionTime()
Description copied from class: IPeak
Retrieves the retention time for this peak. The retention time is closely linked to the scan-id, which is the index or order at which a particular measurement was made. The time is expressed in seconds (all parsers make sure the time-value stored in a file is converted to this convention) and can easily be converted into minutes and seconds with:
 double rt = peak.getRetentionTime();
 int minutes = (int) (rt / 60);
 int seconds = (int) (rt % 60);
 

Specified by:
getRetentionTime in class IPeak
Returns:
The retention time at which the peak was measured.

setRetentionTime

public void setRetentionTime(double retentiontime)
Description copied from class: IPeak
Sets the retention time for this peak, for more information on retention time see IPeak.setRetentionTime(double). It is possible that the class implementing this interface does not support this method.

Specified by:
setRetentionTime in class IPeak
Parameters:
retentiontime - The new retention time for this peak.

getMeasurementID

public int getMeasurementID()
Description copied from class: IPeak
Returns an optional measurement-id for this peak. This is a convenience mechanism for locating the measurement-information for this peak in the Header.

Specified by:
getMeasurementID in class IPeak
Returns:
The profile-id of this peak.

setMeasurementID

public void setMeasurementID(int id)
Description copied from class: IPeak
Sets the profile-id of this peak, for more information on mass see IPeak.getMeasurementID(). It is possible that the class implementing this interface does not support this method.

Specified by:
setMeasurementID in class IPeak
Parameters:
id - The new profile-id for this peak.

getPatternID

public int getPatternID()
Description copied from class: IPeak
Returns an optional id for the peak. This id can for example be used for peak sequence identification. Beware that this mechanism is highly volatile and can only be used in a single-threaded environment within a strictly controlled environment like a single function or a completely controlled application.

Specified by:
getPatternID in class IPeak
Returns:
The id of this peak.

setPatternID

public void setPatternID(int id)
Description copied from class: IPeak
Sets the pattern-id of this peak, for more information on mass see IPeak.getPatternID(). It is possible that the class implementing this interface does not support this method.

Specified by:
setPatternID in class IPeak
Parameters:
id - The new id for this peaks

getSignal

public Signal getSignal()
Description copied from class: IPeak
Calculates the signal for this IPeak object. For a single data-point this will be a signal of one element. For a collection of IPeaks it will be a compounded version.

Specified by:
getSignal in class IPeak
Returns:
The calculated signal.

getPeaks

public java.util.Vector<gPeak> getPeaks()
Returns the vector filled with all the peaks associated to this mass chromatogram. The reference points to the same vector as used inside this class, so do not remove anything from this vector. Sorting is OK as all the properties have already been calculated in the constructor. However, this is not recommended as the peaks are kept sorted on scan, which for access with getPeak(int) makes more sense.

Returns:
The vector containing all the peaks associated to this mass chromatogram.

getPeakData

public PeakData<gPeak> getPeakData()
Returns the PeakData instance associated to this MassChromatogram, containing all the peak-information.

Returns:
The PeakData instance.

getNrPeaks

public int getNrPeaks()
Returns the number of peaks associated with this mass chromatogram.

Returns:
The number of peaks associated to this mass chromatogram.

getPeak

public gPeak getPeak(int pos)
Retrieves the peak at position pos. An IndexOutOfBoundsException is thrown when the pos value is either smaller then 0 or larger than the number of peaks.

Parameters:
pos - The position of the peak to retrieve.
Returns:
The peak at position pos.

getMinMass

public double getMinMass()
Returns the minimum mass of all the peaks associated with this mass chromatogram.

Returns:
The minimum mass of all the peaks.

getMaxMass

public double getMaxMass()
Returns the maximum mass of all the peaks associated with this mass chromatogram.

Returns:
The maximum mass of all the peaks.

getMinIntensity

public double getMinIntensity()
Returns the minimum intensity of all the peaks associated with this mass chromatogram.

Returns:
The minimum intensity of all the peaks.

getMaxIntensity

public double getMaxIntensity()
Returns the maximum intensity of all the peaks associated with this mass chromatogram.

Returns:
The maximum intensity of all the peaks.

getTotalIntensity

public double getTotalIntensity()
Returns the total intensity of the mass chromatogram. This basically is the area under the curve of the trace and should be the most accurate intensity value possible. The area under the curve represents all the measured intensity of the compound in question.

Returns:
The total intensity.

getMinScanID

public int getMinScanID()
Returns the minimum scan of all the peaks associated with this mass chromatogram.

Returns:
The minimum scan of all the peaks.

getMaxScanID

public int getMaxScanID()
Returns the maximum scan of all the peaks associated with this mass chromatogram.

Returns:
The maximum scan of all the peaks.

getPeakScanID

public int getPeakScanID()
Returns the scan where the mass chromatogram is most intense. This is the scan which should be used for the retention time of the peak and is returned by the IPeak.getScanID() method.

Returns:
The scan where the mass chromatogram is most intense.

getMinRetentionTime

public double getMinRetentionTime()
Returns the retention time where the mass chromatogram begins (e.g. the first scan where a data point for this mass chromatogram is recorded).

Returns:
The minimum retention time for this mass chromatogram.

getMaxRetentionTime

public double getMaxRetentionTime()
Returns the retention time where the mass chromatogram ends (e.g. the last scan where a data point for this mass chromatogram is recorded).

Returns:
The maximum retention time for this mass chromatogram.

getPeakRetentionTime

public double getPeakRetentionTime()
Returns the retention time where the mass chromatogram is most intense.

Returns:
The retention time where the mass chromatogram is most intense.

savitzkyGolay

public void savitzkyGolay()

savitzkyGolay

public void savitzkyGolay(SavitzkyGolayFilter.Points p)

coda

public double coda()
Simplistic implementation of the CoDA algorithm working on individual mass chromatograms. The CoDA returns an MCQ (mass chromatogram quality) value for the mass chromatogram, indicating how well defined it is (a larger value indicates a better quality [0-1]). This MCQ is calculated by correlating the original signal and a smoothed version (@see Signal.savitzkyGolaySmooth() of the original signal. In order to remove tails on both sides the smoothed version is mean subtracted. The idea of CoDA is that noisy signals will be different to their smoothed version (spikes are gone causing a low correlation). The correlation value is then adjusted to fall between 0 and 1.

Returns:
The MCQ value for this mass chromatogram [0..1], higher is better.

codaDW

public double codaDW()
Implementation of a CoDA-like approach for evalution of an individual mass chromatogram based on the Durbin-Watson statistic. The Durbin-Watson statistic is a value between 0 and 4 where smaller is better. In order to keep in line with the normal coda approach this value is rescaled between [0..1], where higher is better.

Returns:
The MCQ value for this mass chromatogram [0..1], higher is better.

codaSW

public double codaSW()
Implementation of a CoDA-like approach for evaluation of an individual mass chromatogram based on the Shapiro-Wilk test. A mass chromatogram is expected to have a log-normal distribution, which can be made normal by taking the log of all the intensity values. The Shapiro-Wilk test implemented in Statistical.shapiroWilk(double[]) is then used to evaluate whether the signal is normally distributed.

The p-value of the test is used for the indicator and is scaled between [0..1] (higher is better), in order to keep in line with the MCQ value calculated by coda().

Returns:
The MCQ value for this mass chromatogram [0..1], higher is better.

iterator

public java.util.Iterator<gPeak> iterator()
Specified by:
iterator in interface java.lang.Iterable<gPeak extends Peak>