use of dulab.adap.datamodel.Component in project mzmine2 by mzmine.
the class ADAP3DecompositionV1_5Task method decomposePeaks.
private PeakList decomposePeaks(PeakList peakList) throws CloneNotSupportedException, IOException {
RawDataFile dataFile = peakList.getRawDataFile(0);
// Create new feature list.
final PeakList resolvedPeakList = new SimplePeakList(peakList + " " + parameters.getParameter(ADAP3DecompositionV1_5Parameters.SUFFIX).getValue(), dataFile);
// Load previous applied methods.
for (final PeakList.PeakListAppliedMethod method : peakList.getAppliedMethods()) {
resolvedPeakList.addDescriptionOfAppliedTask(method);
}
// Add task description to feature list.
resolvedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak deconvolution by ADAP-3", parameters));
// Collect peak information
List<Peak> peaks = getPeaks(peakList, this.parameters.getParameter(ADAP3DecompositionV1_5Parameters.EDGE_TO_HEIGHT_RATIO).getValue(), this.parameters.getParameter(ADAP3DecompositionV1_5Parameters.DELTA_TO_HEIGHT_RATIO).getValue());
// Find components (a.k.a. clusters of peaks with fragmentation spectra)
List<Component> components = getComponents(peaks);
// Create PeakListRow for each components
List<PeakListRow> newPeakListRows = new ArrayList<>();
int rowID = 0;
for (final Component component : components) {
if (component.getSpectrum().isEmpty())
continue;
PeakListRow row = new SimplePeakListRow(++rowID);
// Add the reference peak
PeakListRow refPeakRow = originalPeakList.getRow(component.getBestPeak().getInfo().peakID);
Feature refPeak = new SimpleFeature(refPeakRow.getBestPeak());
// Add spectrum
List<DataPoint> dataPoints = new ArrayList<>();
for (Map.Entry<Double, Double> entry : component.getSpectrum().entrySet()) {
dataPoints.add(new SimpleDataPoint(entry.getKey(), entry.getValue()));
}
refPeak.setIsotopePattern(new SimpleIsotopePattern(dataPoints.toArray(new DataPoint[dataPoints.size()]), IsotopePattern.IsotopePatternStatus.PREDICTED, "Spectrum"));
row.addPeak(dataFile, refPeak);
// Add PeakInformation
if (refPeakRow.getPeakInformation() == null) {
SimplePeakInformation information = new SimplePeakInformation(new HashMap<>(refPeakRow.getPeakInformation().getAllProperties()));
row.setPeakInformation(information);
}
// Set row properties
row.setAverageMZ(refPeakRow.getAverageMZ());
row.setAverageRT(refPeakRow.getAverageRT());
// resolvedPeakList.addRow(row);
newPeakListRows.add(row);
}
// ------------------------------------
// Sort new peak rows by retention time
// ------------------------------------
Collections.sort(newPeakListRows, new Comparator<PeakListRow>() {
@Override
public int compare(PeakListRow row1, PeakListRow row2) {
double retTime1 = row1.getAverageRT();
double retTime2 = row2.getAverageRT();
return Double.compare(retTime1, retTime2);
}
});
for (PeakListRow row : newPeakListRows) resolvedPeakList.addRow(row);
return resolvedPeakList;
}
use of dulab.adap.datamodel.Component 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;
}
use of dulab.adap.datamodel.Component in project mzmine2 by mzmine.
the class ADAP3AlignerTask method getComponent.
/**
* Convert a {@link PeakListRow} with one {@link Feature} into {@link Component}.
*
* @param row an instance of {@link PeakListRow}. This parameter cannot be null.
* @return an instance of {@link Component} or null if the row doesn't contain any peaks or isotope patterns.
*/
@Nullable
private Component getComponent(final PeakListRow row) {
if (row.getNumberOfPeaks() == 0)
return null;
// Read Spectrum information
NavigableMap<Double, Double> spectrum = new TreeMap<>();
IsotopePattern pattern = row.getBestIsotopePattern();
if (pattern == null)
throw new IllegalArgumentException("ADAP Alignment requires mass " + "spectra (or isotopic patterns) of peaks. No spectra found.");
for (DataPoint dataPoint : pattern.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
// Read Chromatogram
final Feature peak = row.getBestPeak();
final RawDataFile dataFile = peak.getDataFile();
NavigableMap<Double, Double> chromatogram = new TreeMap<>();
for (final int scan : peak.getScanNumbers()) {
final DataPoint dataPoint = peak.getDataPoint(scan);
if (dataPoint != null)
chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
}
return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
use of dulab.adap.datamodel.Component in project mzmine2 by mzmine.
the class ADAPInterface method getComponent.
public static Component getComponent(final PeakListRow row) {
if (row.getNumberOfPeaks() == 0)
throw new IllegalArgumentException("No peaks found");
NavigableMap<Double, Double> spectrum = new TreeMap<>();
// Read Spectrum information
IsotopePattern ip = row.getBestIsotopePattern();
if (ip != null) {
for (DataPoint dataPoint : ip.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
}
// Read Chromatogram
final Feature peak = row.getBestPeak();
final RawDataFile dataFile = peak.getDataFile();
NavigableMap<Double, Double> chromatogram = new TreeMap<>();
for (final int scan : peak.getScanNumbers()) {
final DataPoint dataPoint = peak.getDataPoint(scan);
if (dataPoint != null)
chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
}
return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
Aggregations