* @return New peak list row with normalized retention time
*/
private PeakListRow normalizeRow(PeakListRow originalRow,
PeakListRow standards[], double normalizedStdRTs[]) {
PeakListRow normalizedRow = new SimplePeakListRow(originalRow.getID());
// Standard rows preceding and following this row
int prevStdIndex = -1, nextStdIndex = -1;
for (int stdIndex = 0; stdIndex < standards.length; stdIndex++) {
// If this standard peak is actually originalRow
if (standards[stdIndex] == originalRow) {
prevStdIndex = stdIndex;
nextStdIndex = stdIndex;
break;
}
// If this standard peak is before our originalRow
if (standards[stdIndex].getAverageRT() < originalRow.getAverageRT()) {
if ((prevStdIndex == -1)
|| (standards[stdIndex].getAverageRT() > standards[prevStdIndex]
.getAverageRT()))
prevStdIndex = stdIndex;
}
// If this standard peak is after our originalRow
if (standards[stdIndex].getAverageRT() > originalRow.getAverageRT()) {
if ((nextStdIndex == -1)
|| (standards[stdIndex].getAverageRT() < standards[nextStdIndex]
.getAverageRT()))
nextStdIndex = stdIndex;
}
}
// Calculate normalized retention time of this row
double normalizedRT = -1;
if ((prevStdIndex == -1) || (nextStdIndex == -1)) {
normalizedRT = originalRow.getAverageRT();
} else
if (prevStdIndex == nextStdIndex) {
normalizedRT = normalizedStdRTs[prevStdIndex];
} else {
double weight = (originalRow.getAverageRT() - standards[prevStdIndex]
.getAverageRT())
/ (standards[nextStdIndex].getAverageRT() - standards[prevStdIndex]
.getAverageRT());
normalizedRT = normalizedStdRTs[prevStdIndex]
+ (weight * (normalizedStdRTs[nextStdIndex] - normalizedStdRTs[prevStdIndex]));
}
// Set normalized retention time to all peaks in this row
for (RawDataFile file : originalRow.getRawDataFiles()) {
ChromatographicPeak originalPeak = originalRow.getPeak(file);
if (originalPeak != null) {
SimpleChromatographicPeak normalizedPeak = new SimpleChromatographicPeak(
originalPeak);
PeakUtils.copyPeakProperties(originalPeak, normalizedPeak);
normalizedPeak.setRT(normalizedRT);
normalizedRow.addPeak(file, normalizedPeak);
}
}
return normalizedRow;