use of dulab.adap.datamodel.ReferenceComponent in project mzmine2 by mzmine.
the class ADAP3AlignerTask method alignPeaks.
private PeakList alignPeaks() {
// Collect all data files
List<RawDataFile> allDataFiles = new ArrayList<>(peakLists.length);
for (final PeakList peakList : peakLists) {
RawDataFile[] dataFiles = peakList.getRawDataFiles();
if (dataFiles.length != 1)
throw new IllegalArgumentException("Found more then one data " + "file in some of the peaks lists");
allDataFiles.add(dataFiles[0]);
}
for (int i = 0; i < peakLists.length; ++i) {
PeakList peakList = peakLists[i];
Sample sample = new Sample(i);
for (final PeakListRow row : peakList.getRows()) {
Component component = getComponent(row);
if (component != null)
sample.addComponent(component);
}
alignment.addSample(sample);
}
process();
// Create new feature list
final PeakList alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
int rowID = 0;
List<ReferenceComponent> alignedComponents = alignment.getComponents();
Collections.sort(alignedComponents);
for (final ReferenceComponent referenceComponent : alignedComponents) {
SimplePeakListRow newRow = new SimplePeakListRow(++rowID);
for (int i = 0; i < referenceComponent.size(); ++i) {
Component component = referenceComponent.getComponent(i);
Peak peak = component.getBestPeak();
peak.getInfo().mzValue(component.getMZ());
PeakListRow row = findPeakListRow(referenceComponent.getSampleID(i), peak.getInfo().peakID);
if (row == null)
throw new IllegalStateException(String.format("Cannot find a feature list row for fileId = %d and peakId = %d", referenceComponent.getSampleID(), peak.getInfo().peakID));
RawDataFile file = row.getRawDataFiles()[0];
// Create a new MZmine feature
Feature feature = ADAPInterface.peakToFeature(file, peak);
// Add spectrum as an isotopic pattern
DataPoint[] spectrum = component.getSpectrum().entrySet().stream().map(e -> new SimpleDataPoint(e.getKey(), e.getValue())).toArray(DataPoint[]::new);
feature.setIsotopePattern(new SimpleIsotopePattern(spectrum, IsotopePattern.IsotopePatternStatus.PREDICTED, "Spectrum"));
newRow.addPeak(file, feature);
}
// Save alignment score
SimplePeakInformation peakInformation = (SimplePeakInformation) newRow.getPeakInformation();
if (peakInformation == null)
peakInformation = new SimplePeakInformation();
peakInformation.addProperty("Alignment score", Double.toString(referenceComponent.getScore()));
newRow.setPeakInformation(peakInformation);
alignedPeakList.addRow(newRow);
}
return alignedPeakList;
}
Aggregations