// Loop through all raw data files, and find the peak with biggest
// height
double maxOriginalHeight = 0.0;
for (RawDataFile file : originalPeakList.getRawDataFiles()) {
for (PeakListRow originalpeakListRow : originalPeakList.getRows()) {
ChromatographicPeak p = originalpeakListRow.getPeak(file);
if (p != null) {
if (maxOriginalHeight <= p.getHeight())
maxOriginalHeight = p.getHeight();
}
}
}
// Loop through all raw data files, and normalize peak values
for (RawDataFile file : originalPeakList.getRawDataFiles()) {
// Cancel?
if (isCanceled()) {
return;
}
// Determine normalization type and calculate normalization factor
double normalizationFactor = 1.0;
// - normalization by average peak intensity
if (normalizationType == NormalizationType.AverageIntensity) {
double intensitySum = 0;
int intensityCount = 0;
for (PeakListRow peakListRow : originalPeakList.getRows()) {
ChromatographicPeak p = peakListRow.getPeak(file);
if (p != null) {
if (peakMeasurementType == PeakMeasurementType.HEIGHT) {
intensitySum += p.getHeight();
} else {
intensitySum += p.getArea();
}
intensityCount++;
}
}
normalizationFactor = intensitySum / (double) intensityCount;
}
// - normalization by average squared peak intensity
if (normalizationType == NormalizationType.AverageSquaredIntensity) {
double intensitySum = 0.0;
int intensityCount = 0;
for (PeakListRow peakListRow : originalPeakList.getRows()) {
ChromatographicPeak p = peakListRow.getPeak(file);
if (p != null) {
if (peakMeasurementType == PeakMeasurementType.HEIGHT) {
intensitySum += (p.getHeight() * p.getHeight());
} else {
intensitySum += (p.getArea() * p.getArea());
}
intensityCount++;
}
}
normalizationFactor = intensitySum / (double) intensityCount;
}
// - normalization by maximum peak intensity
if (normalizationType == NormalizationType.MaximumPeakHeight) {
double maximumIntensity = 0.0;
for (PeakListRow peakListRow : originalPeakList.getRows()) {
ChromatographicPeak p = peakListRow.getPeak(file);
if (p != null) {
if (peakMeasurementType == PeakMeasurementType.HEIGHT) {
if (maximumIntensity < p.getHeight())
maximumIntensity = p.getHeight();
} else {
if (maximumIntensity < p.getArea())
maximumIntensity = p.getArea();
}
}
}
normalizationFactor = maximumIntensity;
}
// - normalization by total raw signal
if (normalizationType == NormalizationType.TotalRawSignal) {
normalizationFactor = 0;
for (int scanNumber : file.getScanNumbers(1)) {
Scan scan = file.getScan(scanNumber);
normalizationFactor += scan.getTIC();
}
}
// Readjust normalization factor so that maximum height will be
// equal to maximumOverallPeakHeightAfterNormalization after
// normalization
double maxNormalizedHeight = maxOriginalHeight
/ normalizationFactor;
normalizationFactor = normalizationFactor * maxNormalizedHeight
/ maximumOverallPeakHeightAfterNormalization;
// Normalize all peak intenisities using the normalization factor
for (PeakListRow originalpeakListRow : originalPeakList.getRows()) {
// Cancel?
if (isCanceled()) {
return;
}
ChromatographicPeak originalPeak = originalpeakListRow
.getPeak(file);
if (originalPeak != null) {
SimpleChromatographicPeak normalizedPeak = new SimpleChromatographicPeak(
originalPeak);
PeakUtils.copyPeakProperties(originalPeak, normalizedPeak);
double normalizedHeight = originalPeak.getHeight()
/ normalizationFactor;
double normalizedArea = originalPeak.getArea()
/ normalizationFactor;
normalizedPeak.setHeight(normalizedHeight);
normalizedPeak.setArea(normalizedArea);
SimplePeakListRow normalizedRow = rowMap