use of net.sf.mzmine.modules.visualization.tic.PeakDataSet in project mzmine2 by mzmine.
the class ShapeModelerSetupDialog method loadPreviewPeak.
private void loadPreviewPeak() {
PeakListRow previewRow = (PeakListRow) comboPeak.getSelectedItem();
if (previewRow == null)
return;
logger.finest("Loading new preview peak " + previewRow);
Feature previewPeak = previewRow.getPeaks()[0];
ticPlot.removeAllTICDataSets();
// Load the intensities into array
RawDataFile dataFile = previewPeak.getDataFile();
int[] scanNumbers = previewPeak.getScanNumbers();
double[] retentionTimes = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
double[] intensities = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) {
DataPoint dp = previewPeak.getDataPoint(scanNumbers[i]);
if (dp != null)
intensities[i] = dp.getIntensity();
else
intensities[i] = 0;
}
// Create shape model
updateParameterSetFromComponents();
JComboBox<?> component = (JComboBox<?>) getComponentForParameter(ShapeModelerParameters.shapeModelerType);
ShapeModel model = (ShapeModel) component.getSelectedItem();
JFormattedTextField resolutionField = (JFormattedTextField) getComponentForParameter(ShapeModelerParameters.massResolution);
double resolution = ((Number) resolutionField.getValue()).doubleValue();
try {
Class<?> shapeModelClass = model.getModelClass();
Constructor<?> shapeModelConstruct = shapeModelClass.getConstructors()[0];
// shapePeakModel(ChromatographicPeak originalDetectedShape, int[]
// scanNumbers,
// double[] intensities, double[] retentionTimes, double resolution)
Feature shapePeak = (Feature) shapeModelConstruct.newInstance(previewPeak, scanNumbers, intensities, retentionTimes, resolution);
PeakDataSet peakDataSet = new PeakDataSet(shapePeak);
ticPlot.addPeakDataset(peakDataSet);
ticDataset = new ChromatogramTICDataSet(previewRow.getPeaks()[0]);
ticPlot.addTICDataset(ticDataset);
// Set auto range to axes
ticPlot.getXYPlot().getDomainAxis().setAutoRange(true);
ticPlot.getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
ticPlot.getXYPlot().getRangeAxis().setAutoRange(true);
ticPlot.getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
} catch (Exception e) {
String message = "Error trying to make an instance of Peak Builder " + model;
MZmineCore.getDesktop().displayErrorMessage(this, message);
logger.severe(message);
e.printStackTrace();
return;
}
}
use of net.sf.mzmine.modules.visualization.tic.PeakDataSet in project mzmine2 by mzmine.
the class PeakResolverSetupDialog method parametersChanged.
@Override
public void parametersChanged() {
if (preview != null && preview.isSelected()) {
final PeakListRow previewRow = (PeakListRow) comboPeak.getSelectedItem();
if (previewRow != null) {
LOG.finest("Loading new preview peak " + previewRow);
ticPlot.removeAllTICDataSets();
ticPlot.addTICDataset(new ChromatogramTICDataSet(previewRow.getPeaks()[0]));
// Auto-range to axes.
ticPlot.getXYPlot().getDomainAxis().setAutoRange(true);
ticPlot.getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
ticPlot.getXYPlot().getRangeAxis().setAutoRange(true);
ticPlot.getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
updateParameterSetFromComponents();
// If there is some illegal value, do not load the preview but
// just exit.
ArrayList<String> errors = new ArrayList<String>();
if (!parameterSet.checkParameterValues(errors)) {
LOG.fine("Illegal parameter value: " + errors);
return;
}
// Load the intensities and RTs into array.
final Feature previewPeak = previewRow.getPeaks()[0];
// Resolve peaks.
Feature[] resolvedPeaks = {};
RSessionWrapper rSession;
try {
if (peakResolver.getRequiresR()) {
// Check R availability, by trying to open the
// connection.
String[] reqPackages = peakResolver.getRequiredRPackages();
String[] reqPackagesVersions = peakResolver.getRequiredRPackagesVersions();
String callerFeatureName = peakResolver.getName();
REngineType rEngineType = peakResolver.getREngineType(parameters);
rSession = new RSessionWrapper(rEngineType, callerFeatureName, reqPackages, reqPackagesVersions);
rSession.open();
} else {
rSession = null;
}
CenterFunction mzCenterFunction = new CenterFunction(CenterMeasure.MEDIAN);
// preview doesn't show msms scans
// set it to be default searching range
resolvedPeaks = peakResolver.resolvePeaks(previewPeak, parameters, rSession, mzCenterFunction, 0, 0);
// Turn off R instance.
if (rSession != null)
rSession.close(false);
} catch (RSessionWrapperException e) {
throw new IllegalStateException(e.getMessage());
} catch (Throwable t) {
LOG.log(Level.SEVERE, "Peak deconvolution error", t);
MZmineCore.getDesktop().displayErrorMessage(this, t.toString());
}
// Add resolved peaks to TIC plot.
final int peakCount = Math.min(MAX_PEAKS, resolvedPeaks.length);
for (int i = 0; i < peakCount; i++) {
final XYDataset peakDataSet = new PeakDataSet(resolvedPeaks[i]);
ticPlot.addPeakDataset(peakDataSet);
}
// Check peak count.
if (resolvedPeaks.length > MAX_PEAKS) {
// MZmineCore.getDesktop().displayMessage(this,
// "Too many peaks detected, please adjust parameter values");
MZmineCore.getDesktop().displayMessage(this, "Too many peaks detected. Not all of the peaks might be displayed");
}
}
}
}
Aggregations