peakml
Class IPeakSet<Type extends IPeak>

java.lang.Object
  extended by peakml.Annotatable
      extended by peakml.IPeak
          extended by peakml.IPeakSet<Type>
Type Parameters:
Type - The type of peaks stored in the peakset.
All Implemented Interfaces:
java.lang.Iterable<Type>, Measurement

public class IPeakSet<Type extends IPeak>
extends IPeak
implements java.lang.Iterable<Type>, Measurement

Implementation of a class maintaining a set of peaks. The constructor of this class efficiently pre-calculates a large number of properties from the set of peaks, like min, max and mean values of intensity, mass and scan; furthermore it provides a convenient interface for efficiently looking for specific masses in a large list of peaks by employing a binary search approach.

This class implements the Iterable interface, making it possible to use the construct:

 IPeakSet peakset = ...;
 for (IPeak peak : peakset)
    ...;
 


Nested Class Summary
 
Nested classes/interfaces inherited from class peakml.IPeak
IPeak.AnnotationAscending, IPeak.AnnotationDescending, IPeak.MatchCompare<Type>, IPeak.RelationCompare<Type>
 
Field Summary
 
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
IPeakSet(java.util.List<Type> set)
          Constructs a new peakset with the given set of peaks.
IPeakSet(Type t)
           
IPeakSet(Type[] set)
          Constructs a new peakset with the given set of peaks.
 
Method Summary
 Type get(int pos)
          Returns the peak at the given position.
 java.lang.Class<? extends java.lang.Object> getContainerClass()
          Returns the type of peaks stored in the peakset.
 double getIntensity()
          Retrieves the measured intensity for this peak.
 double getMass()
          Retrieves the mass of this peak.
 double getMassStdDev()
          Calculates the standard deviation on the mass.
 double getMaxIntensity()
          Returns the maximum intensity of all the peaks stored in this peakset.
 double getMaxMass()
          Returns the maximum mass of all the peaks stored in this peakset.
 double getMaxRetentionTime()
          Returns the maximum retention time of all the peaks stored in this peakset.
 int getMaxScanID()
          Returns the maximum scan-id of all the peaks stored in this peakset.
 double getMeanIntensity()
          Returns the mean intensity of all the peaks stored in this peakset.
 double getMeanMass()
          Returns the mean mass of all the peaks stored in this peakset.
 double getMeanRetentionTime()
          Returns the mean retention time of all the peaks stored in this peakset.
 int getMeanScanID()
          Returns the mean scan-id of all the peaks stored in this peakset.
 int getMeasurementID()
          Returns an optional measurement-id for this peak.
 double getMedianIntensity()
          Returns the median intensity of all the peaks stored in this peakset.
 double getMedianMass()
          Returns the median mass of all the peaks stored in this peakset.
 double getMinIntensity()
          Returns the minimum intensity of all the peaks stored in this peakset.
 double getMinMass()
          Returns the minimum mass of all the peaks stored in this peakset.
 double getMinRetentionTime()
          Returns the minimum retention time of all the peaks stored in this peakset.
 int getMinScanID()
          Returns the minimum scan-id of all the peaks stored in this peakset.
 int getPatternID()
          Returns an optional id for the peak.
 java.util.Vector<Type> getPeaks()
          Returns the list of peaks stored in this peakset.
 java.util.Vector<Type> getPeaksInMassRange(double minmass, double maxmass)
          Returns all the peaks in this peakset with a mass in the range minmass ..
 java.util.Vector<Type> getPeaksInRetentionTimeRange(double minrt, double maxrt)
          Returns all the peaks in the given retention time range.
 java.util.Vector<Type> getPeaksInScanRange(int minscan, int maxscan)
          Returns all the peaks in the given scan-range.
 java.util.Vector<Type> getPeaksOfMass(double mass, double delta)
          Returns all the peaks in this peakset with a mass in the range mass-delta ..
 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.
 int indexOfMass(double mass)
          Implementation of a binary search for the mass in the peak-list.
 int indexOfRetentionTime(double rt)
          Implementation of a binary search for a retention time in the peak-list.
 int indexOfScan(int scanid)
          Implementation of a binary search for a scan in the peak-list.
 java.util.Iterator<Type> iterator()
          Iterable.iterator()
 void resetPatternIDs(int id)
          This method sets the pattern id of the peaks stored in this peakset to the given id.
 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().
 int size()
          Returns the number of peaks in this peakset.
 
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
 

Constructor Detail

IPeakSet

public IPeakSet(Type t)
         throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException

IPeakSet

public IPeakSet(Type[] set)
         throws java.lang.RuntimeException
Constructs a new peakset with the given set of peaks. This constructor picks up an array of peaks, which is converted into a vector and passed on to IPeakSet(List).

Parameters:
set - An array of peaks to be stored in the peakset.
Throws:
java.lang.RuntimeException - Thrown when a set of size 0 or 1 is passed.

IPeakSet

public IPeakSet(java.util.List<Type> set)
         throws java.lang.RuntimeException
Constructs a new peakset with the given set of peaks. From the peaks stored in the list a large number of properties is calculated, like min, max and mean values of intensity, mass and scan. Apart from this, an extra vector is created, which is sorted on ascending mass. This additional vector is used for an efficient search mechanism based on mass.

A peakset needs at least 2 peaks in order to function correctly.

Parameters:
set - A list of peaks to be stored in the peakset.
Throws:
java.lang.RuntimeException - Thrown when a set of size 0 or 1 is passed.
Method Detail

getContainerClass

public java.lang.Class<? extends java.lang.Object> getContainerClass()
Returns the type of peaks stored in the peakset. The Java programming language does not provide a convenient interface for retrieving a generic type (due to erasure), which can be solved by taking the class information of the first element in the set.

Returns:
The generic class type of the peaks stored in the peakset.

getMinScanID

public int getMinScanID()
Returns the minimum scan-id of all the peaks stored in this peakset. This value can be -1 in the case of peaks from a 1D technology.

Returns:
The minimum scan-id.

getMaxScanID

public int getMaxScanID()
Returns the maximum scan-id of all the peaks stored in this peakset. This value can be -1 in the case of peaks from a 1D technology.

Returns:
The maximum scan-id.

getMeanScanID

public int getMeanScanID()
Returns the mean scan-id of all the peaks stored in this peakset. This value can be -1 in the case of peaks from a 1D technology.

Returns:
The mean scan-id.

getMinRetentionTime

public double getMinRetentionTime()
Returns the minimum retention time of all the peaks stored in this peakset. This value can be -1 in the case of peaks from a 1D technology.

Returns:
The minimum retention time.

getMaxRetentionTime

public double getMaxRetentionTime()
Returns the maximum retention time of all the peaks stored in this peakset. This value can be -1 in the case of peaks from a 1D technology.

Returns:
The maximum retention time.

getMeanRetentionTime

public double getMeanRetentionTime()
Returns the mean retention time of all the peaks stored in this peakset. This value can be -1 in the case of peaks from a 1D technology.

Returns:
The mean retention time.

getMinMass

public double getMinMass()
Returns the minimum mass of all the peaks stored in this peakset.

Returns:
The minimum mass.

getMaxMass

public double getMaxMass()
Returns the maximum mass of all the peaks stored in this peakset.

Returns:
The maximum mass.

getMeanMass

public double getMeanMass()
Returns the mean mass of all the peaks stored in this peakset.

Returns:
The mean mass.

getMedianMass

public double getMedianMass()
Returns the median mass of all the peaks stored in this peakset.

Returns:
The median mass.

getMinIntensity

public double getMinIntensity()
Returns the minimum intensity of all the peaks stored in this peakset.

Returns:
The minimum intensity.

getMaxIntensity

public double getMaxIntensity()
Returns the maximum intensity of all the peaks stored in this peakset.

Returns:
The maximum intensity.

getMeanIntensity

public double getMeanIntensity()
Returns the mean intensity of all the peaks stored in this peakset.

Returns:
The mean intensity.

getMedianIntensity

public double getMedianIntensity()
Returns the median intensity of all the peaks stored in this peakset.

Returns:
The median intensity.

getMassStdDev

public double getMassStdDev()
Calculates the standard deviation on the mass.

Beware this is not a pre-calculated value, but is calculated by this method. As this is a reasonable heavy operation and is not used that often, this is the most optimal solution.

Returns:
The standard deviation of the mass.

indexOfMass

public int indexOfMass(double mass)
Implementation of a binary search for the mass in the peak-list. The peaks are sorted on mass (small to big), so the binary search should be most efficient for looking for the required index. When the mass is outside the range of the peaks, the index -1 is returned. Otherwise the index of the peak, which is the last peak with a mass smaller or equal to the given mass.

Parameters:
mass - The mass to look for.
Returns:
The index of the last element, which is smaller/equal to the given mass, -1 otherwise.

getPeaksOfMass

public java.util.Vector<Type> getPeaksOfMass(double mass,
                                             double delta)
Returns all the peaks in this peakset with a mass in the range mass-delta .. mass+delta. This method utilizes the binairy search algorithm implemented in indexOfMass(double), making the retrieval very speedy.

Parameters:
mass - The mass to look for.
delta - The delta around the mass.
Returns:
A vector with all the peaks in the mass range.

getPeaksInMassRange

public java.util.Vector<Type> getPeaksInMassRange(double minmass,
                                                  double maxmass)
Returns all the peaks in this peakset with a mass in the range minmass .. maxmass. This method utilizes the binairy search algorithm implemented in indexOfMass(double), making the retrieval very speedy.

Parameters:
minmass - The minimum mass to look for.
maxmass - The maximum mass to look for.
Returns:
A vector with all the peaks in the mass range.

indexOfScan

public int indexOfScan(int scanid)
Implementation of a binary search for a scan in the peak-list. The peaks are sorted on scan (small to big), so the binary search should be most efficient for looking for the required index. When the scan is outside the range of the peaks, the index -1 is returned. Otherwise the index of the peak, which is the last peak with a scan smaller or equal to the given scan.

Parameters:
scanid - The scan to look for.
Returns:
The index of the peak to look for.

getPeaksInScanRange

public java.util.Vector<Type> getPeaksInScanRange(int minscan,
                                                  int maxscan)
Returns all the peaks in the given scan-range. The method utilizes the binary search algorithm implement in indexOfScan(int) for optimal searching.

Parameters:
minscan - The scan where to start collecting peaks.
maxscan - The scan where to end collecting peaks.
Returns:
All peaks in the scan range.

indexOfRetentionTime

public int indexOfRetentionTime(double rt)
Implementation of a binary search for a retention time in the peak-list. The peaks are sorted on retention time (small to big), so the binary search should be most efficient for looking for the required index. When the retention time is outside the range of the peaks, the index -1 is returned. Otherwise the index of the peak, which is the last peak with a retention time smaller or equal to the given retention time.

Parameters:
rt - The retention time to look for.
Returns:
The index of the peak to look for.

getPeaksInRetentionTimeRange

public java.util.Vector<Type> getPeaksInRetentionTimeRange(double minrt,
                                                           double maxrt)
Returns all the peaks in the given retention time range. The method utilizes the binary search algorithm implement in indexOfRetentionTime(double) for optimal searching.

Parameters:
minrt - The retention time where to start collecting peaks.
maxrt - The retention time where to end collecting peaks.
Returns:
All peaks in the retention time range.

resetPatternIDs

public void resetPatternIDs(int id)
This method sets the pattern id of the peaks stored in this peakset to the given id.

Parameters:
id - The id for the peaks in the set.

size

public int size()
Returns the number of peaks in this peakset.

Returns:
The number of peaks in this peakset.

get

public Type get(int pos)
                       throws java.lang.IndexOutOfBoundsException
Returns the peak at the given position. When the position is smaller than 0 or larger or equal to size() an IndexOutOfBoundsException is thrown.

Parameters:
pos - The position in the list of the peak to be retrieved.
Returns:
The peak at position pos.
Throws:
java.lang.IndexOutOfBoundsException - When the given position is smaller than 0 or larger or equal to size().

getPeaks

public final java.util.Vector<Type> getPeaks()
Returns the list of peaks stored in this peakset. The reference is to the vector stored in the peakset and should not be altered.

Returns:
A vector containing all the peaks stored in this peakset.

iterator

public java.util.Iterator<Type> iterator()
Iterable.iterator()

Specified by:
iterator in interface java.lang.Iterable<Type extends IPeak>

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.