use of net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot in project mzmine2 by mzmine.
the class ScanSelectPanel method createChart.
/**
* Create chart of selected scan
*/
public void createChart() {
setValidSelection(false);
pnChart.removeAll();
if (scans != null && !scans.isEmpty()) {
if (spectrumPlot == null) {
spectrumPlot = new SpectraPlot(this, false);
if (listener != null)
// chart has changed
listener.accept(spectrumPlot);
}
spectrumPlot.removeAllDataSets();
DataPointsDataSet data = new DataPointsDataSet("Data", getFilteredDataPoints());
// green
spectrumPlot.addDataSet(data, colorUsedData, false);
if (showRemovedData) {
// orange
DataPointsDataSet dataRemoved = new DataPointsDataSet("Removed", getFilteredDataPointsRemoved());
spectrumPlot.addDataSet(dataRemoved, colorRemovedData, false);
}
spectrumPlot.getChart().getLegend().setVisible(showLegend);
spectrumPlot.setMaximumSize(new Dimension(chartSize.width, 10000));
spectrumPlot.setPreferredSize(chartSize);
pnChart.add(spectrumPlot, BorderLayout.CENTER);
Scan scan = scans.get(selectedScanI);
analyzeScan(scan);
applySelectionState();
setValidSelection(true);
} else {
// add error label
JLabel error = new JLabel(MessageFormat.format("NO MS2 SPECTRA: 0 of {0} match the minimum criteria", getTotalScans()));
error.setFont(new Font("Tahoma", Font.BOLD, 13));
error.setHorizontalAlignment(SwingConstants.CENTER);
error.setForeground(new Color(220, 20, 60));
pnChart.add(error, BorderLayout.CENTER);
//
}
// set next and prev button enabled
btnPrev.setEnabled(selectedScanI - 1 >= 0);
btnNext.setEnabled(scans != null && selectedScanI + 1 < scans.size());
revalidate();
repaint();
}
use of net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot in project mzmine2 by mzmine.
the class SpectraIdentificationSumFormulaTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.finest("Starting search for formulas for " + massRange + " Da");
// create mass list for scan
DataPoint[] massList = null;
ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
MassDetector massDetector = null;
ArrayList<String> allCompoundIDs = new ArrayList<>();
// Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
massDetector = new CentroidMassDetector();
CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
} else {
massDetector = new ExactMassDetector();
ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
}
numItems = massList.length;
// loop through every peak in mass list
if (getStatus() != TaskStatus.PROCESSING) {
return;
}
IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
for (int i = 0; i < massList.length; i++) {
massRange = mzTolerance.getToleranceRange((massList[i].getMZ() - ionType.getAddedMass()) / charge);
generator = new MolecularFormulaGenerator(builder, massRange.lowerEndpoint(), massRange.upperEndpoint(), elementCounts);
IMolecularFormula cdkFormula;
String annotation = "";
// create a map to store ResultFormula and relative mass deviation for sorting
Map<Double, String> possibleFormulas = new TreeMap<>();
while ((cdkFormula = generator.getNextFormula()) != null) {
if (isCanceled())
return;
// Mass is ok, so test other constraints
if (checkConstraints(cdkFormula) == true) {
String formula = MolecularFormulaManipulator.getString(cdkFormula);
// calc rel mass deviation
Double relMassDev = ((((//
massList[i].getMZ() - ionType.getAddedMass()) / //
charge) - (//
FormulaUtils.calculateExactMass(MolecularFormulaManipulator.getString(cdkFormula))) / charge) / ((//
massList[i].getMZ() - ionType.getAddedMass()) / charge)) * 1000000;
// write to map
possibleFormulas.put(relMassDev, formula);
}
}
Map<Double, String> treeMap = new TreeMap<>((Comparator<Double>) (o1, o2) -> Double.compare(Math.abs(o1), Math.abs(o2)));
treeMap.putAll(possibleFormulas);
// get top 3
int ctr = 0;
for (Map.Entry<Double, String> entry : treeMap.entrySet()) {
int number = ctr + 1;
if (ctr > 2)
break;
annotation = annotation + number + ". " + entry.getValue() + " Δ " + NumberFormat.getInstance().format(entry.getKey()) + " ppm; ";
ctr++;
if (isCanceled())
return;
}
if (annotation != "") {
allCompoundIDs.add(annotation);
massListAnnotated.add(massList[i]);
}
logger.finest("Finished formula search for " + massRange + " m/z, found " + foundFormulas + " formulas");
}
// new mass list
DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
massListAnnotated.toArray(annotatedMassList);
String[] annotations = new String[annotatedMassList.length];
allCompoundIDs.toArray(annotations);
DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
// Add label generator for the dataset
SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot in project mzmine2 by mzmine.
the class ParameterSetupDialogWithScanPreview method addDialogComponents.
/**
* This function add all the additional components for this dialog over the original
* ParameterSetupDialog.
*/
@Override
protected void addDialogComponents() {
super.addDialogComponents();
dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
if (dataFiles.length == 0)
return;
RawDataFile[] selectedFiles = MZmineCore.getDesktop().getSelectedDataFiles();
if (selectedFiles.length > 0)
previewDataFile = selectedFiles[0];
else
previewDataFile = dataFiles[0];
previewCheckBox = new JCheckBox("Show preview");
previewCheckBox.addActionListener(this);
previewCheckBox.setHorizontalAlignment(SwingConstants.CENTER);
mainPanel.add(new JSeparator(), 0, getNumberOfParameters() + 1, 3, 1, 0, 0, GridBagConstraints.HORIZONTAL);
mainPanel.add(previewCheckBox, 0, getNumberOfParameters() + 2, 3, 1, 0, 0, GridBagConstraints.HORIZONTAL);
// Elements of pnlLab
JPanel pnlLab = new JPanel();
pnlLab.setLayout(new BoxLayout(pnlLab, BoxLayout.Y_AXIS));
pnlLab.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
pnlLab.add(new JLabel("Data file "));
pnlLab.add(Box.createVerticalStrut(25));
pnlLab.add(new JLabel("Scan number "));
// Elements of pnlFlds
JPanel pnlFlds = new JPanel();
pnlFlds.setLayout(new BoxLayout(pnlFlds, BoxLayout.Y_AXIS));
pnlFlds.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
comboDataFileName = new JComboBox<RawDataFile>(dataFiles);
comboDataFileName.setSelectedItem(previewDataFile);
comboDataFileName.addActionListener(this);
int[] scanNumbers = previewDataFile.getScanNumbers();
Integer[] scanNumbersObj = CollectionUtils.toIntegerArray(scanNumbers);
comboScanNumber = new JComboBox<Integer>(scanNumbersObj);
comboScanNumber.setSelectedIndex(0);
comboScanNumber.addActionListener(this);
pnlFlds.add(comboDataFileName);
pnlFlds.add(Box.createVerticalStrut(10));
// --> Elements of pnlScanArrows
JPanel pnlScanArrows = new JPanel();
pnlScanArrows.setLayout(new BoxLayout(pnlScanArrows, BoxLayout.X_AXIS));
String leftArrow = new String(new char[] { '\u2190' });
GUIUtils.addButton(pnlScanArrows, leftArrow, null, this, "PREVIOUS_SCAN");
pnlScanArrows.add(Box.createHorizontalStrut(5));
pnlScanArrows.add(comboScanNumber);
pnlScanArrows.add(Box.createHorizontalStrut(5));
String rightArrow = new String(new char[] { '\u2192' });
GUIUtils.addButton(pnlScanArrows, rightArrow, null, this, "NEXT_SCAN");
pnlFlds.add(pnlScanArrows);
// Put all together
pnlPreviewFields = new JPanel(new BorderLayout());
pnlPreviewFields.add(pnlLab, BorderLayout.WEST);
pnlPreviewFields.add(pnlFlds, BorderLayout.CENTER);
pnlPreviewFields.setVisible(false);
spectrumPlot = new SpectraPlot(this);
spectrumPlot.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
spectrumPlot.setMinimumSize(new Dimension(400, 300));
mainPanel.add(pnlPreviewFields, 0, getNumberOfParameters() + 3, 3, 1, 0, 0);
updateMinimumSize();
pack();
}
Aggregations