use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class CameraSearchTask method groupPeaksByIsotope.
/**
* Uses Isotope-field in PeakIdentity to group isotopes and build spectrum
*
* @param peakList PeakList object
* @return new PeakList object
*/
private PeakList groupPeaksByIsotope(PeakList peakList) {
// Create new feature list.
final PeakList combinedPeakList = new SimplePeakList(peakList + " " + parameters.getParameter(CameraSearchParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
// Load previous applied methods.
for (final PeakList.PeakListAppliedMethod method : peakList.getAppliedMethods()) {
combinedPeakList.addDescriptionOfAppliedTask(method);
}
// Add task description to feature list.
combinedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Bioconductor CAMERA", parameters));
// ------------------------------------------------
// Find unique isotopes belonging to the same group
// ------------------------------------------------
Set<String> isotopeGroups = new HashSet<>();
for (PeakListRow row : peakList.getRows()) {
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity == null)
continue;
String isotope = identity.getPropertyValue("Isotope");
if (isotope == null)
continue;
String isotopeGroup = isotope.substring(1, isotope.indexOf("]"));
if (isotopeGroup == null || isotopeGroup.length() == 0)
continue;
isotopeGroups.add(isotopeGroup);
}
List<PeakListRow> groupRows = new ArrayList<>();
Set<String> groupNames = new HashSet<>();
Map<Double, Double> spectrum = new HashMap<>();
List<PeakListRow> newPeakListRows = new ArrayList<>();
for (String isotopeGroup : isotopeGroups) {
// -----------------------------------------
// Find all peaks belonging to isotopeGroups
// -----------------------------------------
groupRows.clear();
groupNames.clear();
spectrum.clear();
int minLength = Integer.MAX_VALUE;
PeakListRow groupRow = null;
for (PeakListRow row : peakList.getRows()) {
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity == null)
continue;
String isotope = identity.getPropertyValue("Isotope");
if (isotope == null)
continue;
String isoGroup = isotope.substring(1, isotope.indexOf("]"));
if (isoGroup == null)
continue;
if (isoGroup.equals(isotopeGroup)) {
groupRows.add(row);
groupNames.add(identity.getName());
spectrum.put(row.getAverageMZ(), row.getAverageHeight());
if (isoGroup.length() < minLength) {
minLength = isoGroup.length();
groupRow = row;
}
}
}
// Skip peaks that have different identity names (belong to different pcgroup)
if (groupRow == null || groupNames.size() != 1)
continue;
if (groupRow == null)
continue;
PeakIdentity identity = groupRow.getPreferredPeakIdentity();
if (identity == null)
continue;
DataPoint[] dataPoints = new DataPoint[spectrum.size()];
int count = 0;
for (Entry<Double, Double> e : spectrum.entrySet()) dataPoints[count++] = new SimpleDataPoint(e.getKey(), e.getValue());
IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
groupRow.getBestPeak().setIsotopePattern(pattern);
// combinedPeakList.addRow(groupRow);
newPeakListRows.add(groupRow);
}
if (includeSingletons) {
for (PeakListRow row : peakList.getRows()) {
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity == null)
continue;
String isotope = identity.getPropertyValue("Isotope");
if (isotope == null || isotope.length() == 0) {
DataPoint[] dataPoints = new DataPoint[1];
dataPoints[0] = new SimpleDataPoint(row.getAverageMZ(), row.getAverageHeight());
IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
row.getBestPeak().setIsotopePattern(pattern);
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) combinedPeakList.addRow(row);
return combinedPeakList;
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class PrecursorDBSearchModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
PeakList[] peakLists = parameters.getParameter(PrecursorDBSearchParameters.peakLists).getValue().getMatchingPeakLists();
for (PeakList peakList : peakLists) {
Task newTask = new PrecursorDBSearchTask(peakList, parameters);
tasks.add(newTask);
}
return ExitCode.OK;
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class VanKrevelenDiagramParameters method showSetupDialog.
@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
PeakList[] selectedPeakLists = getParameter(peakList).getValue().getMatchingPeakLists();
if (selectedPeakLists.length > 0) {
PeakListRow[] plRows = selectedPeakLists[0].getRows();
Arrays.sort(plRows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
}
return super.showSetupDialog(parent, valueCheckRequired);
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class TwoDVisualizerWindow method actionPerformed.
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command.equals("SWITCH_PALETTE")) {
twoDPlot.getXYPlot().switchPalette();
}
if (command.equals("SHOW_DATA_POINTS")) {
twoDPlot.switchDataPointsVisible();
}
if (command.equals("SETUP_AXES")) {
AxesSetupDialog dialog = new AxesSetupDialog(this, twoDPlot.getXYPlot());
dialog.setVisible(true);
}
if (command.equals("SWITCH_PLOTMODE")) {
if (twoDPlot.getPlotMode() == PlotMode.CENTROID) {
toolBar.setCentroidButton(true);
twoDPlot.setPlotMode(PlotMode.CONTINUOUS);
} else {
toolBar.setCentroidButton(false);
twoDPlot.setPlotMode(PlotMode.CENTROID);
}
}
if (command.equals("SWITCH_TOOLTIPS")) {
if (tooltipMode) {
twoDPlot.showPeaksTooltips(false);
toolBar.setTooltipButton(false);
tooltipMode = false;
} else {
twoDPlot.showPeaksTooltips(true);
toolBar.setTooltipButton(true);
tooltipMode = true;
}
}
if (command.equals("SWITCH_LOG_SCALE")) {
if (twoDPlot != null) {
logScale = !logScale;
twoDPlot.setLogScale(logScale);
}
}
if ("PEAKLIST_CHANGE".equals(command)) {
final PeakList selectedPeakList = bottomPanel.getSelectedPeakList();
if (selectedPeakList != null) {
logger.finest("Loading a feature list " + selectedPeakList + " to a 2D view of " + dataFile);
twoDPlot.loadPeakList(selectedPeakList);
}
}
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class TwoDBottomPanel method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == thresholdCombo) {
PeakThresholdMode mode = (PeakThresholdMode) this.thresholdCombo.getSelectedItem();
switch(mode) {
case ABOVE_INTENSITY_PEAKS:
peakTextField.setText(String.valueOf(thresholdSettings.getIntensityThreshold()));
peakTextField.setEnabled(true);
break;
case ALL_PEAKS:
peakTextField.setEnabled(false);
break;
case TOP_PEAKS:
case TOP_PEAKS_AREA:
peakTextField.setText(String.valueOf(thresholdSettings.getTopPeaksThreshold()));
peakTextField.setEnabled(true);
break;
}
thresholdSettings.setMode(mode);
}
if (src == peakTextField) {
PeakThresholdMode mode = (PeakThresholdMode) this.thresholdCombo.getSelectedItem();
String value = peakTextField.getText();
switch(mode) {
case ABOVE_INTENSITY_PEAKS:
double topInt = Double.parseDouble(value);
thresholdSettings.setIntensityThreshold(topInt);
break;
case TOP_PEAKS:
case TOP_PEAKS_AREA:
int topPeaks = Integer.parseInt(value);
thresholdSettings.setTopPeaksThreshold(topPeaks);
break;
default:
break;
}
}
PeakList selectedPeakList = getPeaksInThreshold();
if (selectedPeakList != null)
masterFrame.getPlot().loadPeakList(selectedPeakList);
}
Aggregations