Search in sources :

Example 1 with PseudoSpectrumDataSet

use of net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet in project mzmine2 by mzmine.

the class MirrorScanWindow method setScans.

/**
 * Based on a data base match to a spectral library
 *
 * @param row
 * @param db
 */
public void setScans(SpectralDBPeakIdentity db) {
    Scan scan = db.getQueryScan();
    if (scan == null)
        return;
    // get highest data intensity to calc relative intensity
    double mostIntenseQuery = Arrays.stream(db.getQueryDataPoints(DataPointsTag.ORIGINAL)).mapToDouble(DataPoint::getIntensity).max().orElse(0d);
    double mostIntenseDB = Arrays.stream(db.getLibraryDataPoints(DataPointsTag.ORIGINAL)).mapToDouble(DataPoint::getIntensity).max().orElse(0d);
    if (mostIntenseDB == 0d)
        logger.warning("This data set has no original data points in the library spectrum (development error)");
    if (mostIntenseQuery == 0d)
        logger.warning("This data set has no original data points in the query spectrum (development error)");
    if (mostIntenseDB == 0d || mostIntenseQuery == 0d)
        return;
    // get colors for vision
    Vision vision = MZmineCore.getConfiguration().getColorVision();
    // colors for the different DataPointsTags:
    final Color[] colors = new Color[] { // black = filtered
    Color.black, // unaligned
    ColorPalettes.getNegativeColor(vision), // aligned
    ColorPalettes.getPositiveColor(vision) };
    // scan a
    double precursorMZA = scan.getPrecursorMZ();
    double rtA = scan.getRetentionTime();
    Double precursorMZB = db.getEntry().getPrecursorMZ();
    Double rtB = (Double) db.getEntry().getField(DBEntryField.RT).orElse(0d);
    contentPane.removeAll();
    // create without data
    mirrorSpecrumPlot = SpectrumChartFactory.createMirrorChartPanel("Query: " + scan.getScanDefinition(), precursorMZA, rtA, null, "Library: " + db.getName(), precursorMZB == null ? 0 : precursorMZB, rtB, null, false, true);
    mirrorSpecrumPlot.setMaximumDrawWidth(4200);
    mirrorSpecrumPlot.setMaximumDrawHeight(2500);
    // add data
    DataPoint[][] query = new DataPoint[tags.length][];
    DataPoint[][] library = new DataPoint[tags.length][];
    for (int i = 0; i < tags.length; i++) {
        DataPointsTag tag = tags[i];
        query[i] = db.getQueryDataPoints(tag);
        library[i] = db.getLibraryDataPoints(tag);
    }
    // add datasets and renderer
    // set up renderer
    CombinedDomainXYPlot domainPlot = (CombinedDomainXYPlot) mirrorSpecrumPlot.getChart().getXYPlot();
    NumberAxis axis = (NumberAxis) domainPlot.getDomainAxis();
    axis.setLabel("m/z");
    XYPlot queryPlot = (XYPlot) domainPlot.getSubplots().get(0);
    XYPlot libraryPlot = (XYPlot) domainPlot.getSubplots().get(1);
    // add all datapoints to a dataset that are not present in subsequent masslist
    for (int i = 0; i < tags.length; i++) {
        DataPointsTag tag = tags[i];
        PseudoSpectrumDataSet qdata = new PseudoSpectrumDataSet(true, "Query " + tag.toRemainderString());
        for (DataPoint dp : query[i]) {
            // not contained in other
            if (notInSubsequentMassList(dp, query, i) && mostIntenseQuery > 0)
                qdata.addDP(dp.getMZ(), dp.getIntensity() / mostIntenseQuery * 100d, null);
        }
        PseudoSpectrumDataSet ldata = new PseudoSpectrumDataSet(true, "Library " + tag.toRemainderString());
        for (DataPoint dp : library[i]) {
            if (notInSubsequentMassList(dp, library, i) && mostIntenseDB > 0)
                ldata.addDP(dp.getMZ(), dp.getIntensity() / mostIntenseDB * 100d, null);
        }
        Color color = colors[i];
        PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(color, false);
        PseudoSpectraRenderer renderer2 = new PseudoSpectraRenderer(color, false);
        queryPlot.setDataset(i, qdata);
        queryPlot.setRenderer(i, renderer);
        libraryPlot.setDataset(i, ldata);
        libraryPlot.setRenderer(i, renderer2);
    }
    // add legend
    LegendItem item;
    LegendItemCollection collection = new LegendItemCollection();
    for (int i = 0; i < tags.length; i++) {
        item = new LegendItem(tags[i].toRemainderString(), colors[i]);
        collection.add(item);
    }
    mirrorSpecrumPlot.getChart().removeLegend();
    LegendTitle legend = new LegendTitle(() -> collection);
    legend.setPosition(RectangleEdge.BOTTOM);
    mirrorSpecrumPlot.getChart().addLegend(legend);
    // set y axis title
    queryPlot.getRangeAxis().setLabel("rel. intensity [%] (query)");
    libraryPlot.getRangeAxis().setLabel("rel. intensity [%] (library)");
    contentPane.add(mirrorSpecrumPlot, BorderLayout.CENTER);
    contentPane.revalidate();
    contentPane.repaint();
}
Also used : PseudoSpectrumDataSet(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet) NumberAxis(org.jfree.chart.axis.NumberAxis) PseudoSpectraRenderer(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectraRenderer) LegendItemCollection(org.jfree.chart.LegendItemCollection) Color(java.awt.Color) LegendTitle(org.jfree.chart.title.LegendTitle) DataPoint(net.sf.mzmine.datamodel.DataPoint) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) DataPoint(net.sf.mzmine.datamodel.DataPoint) LegendItem(org.jfree.chart.LegendItem) Vision(net.sf.mzmine.util.ColorPalettes.Vision) Scan(net.sf.mzmine.datamodel.Scan) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) DataPointsTag(net.sf.mzmine.util.spectraldb.entry.DataPointsTag)

Example 2 with PseudoSpectrumDataSet

use of net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet in project mzmine2 by mzmine.

the class SpectrumChartFactory method createMSMSDataSet.

public static PseudoSpectrumDataSet createMSMSDataSet(double precursorMZ, double rt, DataPoint[] dps, String label) {
    NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
    NumberFormat rtForm = MZmineCore.getConfiguration().getRTFormat();
    if (label == null)
        label = "";
    else if (!label.isEmpty())
        label = " (" + label + ")";
    // data
    PseudoSpectrumDataSet series = new PseudoSpectrumDataSet(true, MessageFormat.format("MSMS for m/z={0} RT={1}{2}", mzForm.format(precursorMZ), rtForm.format(rt), label));
    // for each row
    for (DataPoint dp : dps) {
        series.addDP(dp.getMZ(), dp.getIntensity(), null);
    }
    return series;
}
Also used : PseudoSpectrumDataSet(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet) DataPoint(net.sf.mzmine.datamodel.DataPoint) NumberFormat(java.text.NumberFormat)

Example 3 with PseudoSpectrumDataSet

use of net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet in project mzmine2 by mzmine.

the class SpectrumChartFactory method createScanChartPanel.

public static EChartPanel createScanChartPanel(Scan scan, boolean showTitle, boolean showLegend) {
    if (scan == null)
        return null;
    PseudoSpectrumDataSet dataset = createMSMSDataSet(scan, "");
    JFreeChart chart = createChart(dataset, showTitle, showLegend, scan.getRetentionTime(), scan.getPrecursorMZ());
    return createChartPanel(chart);
}
Also used : PseudoSpectrumDataSet(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet) JFreeChart(org.jfree.chart.JFreeChart)

Example 4 with PseudoSpectrumDataSet

use of net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet in project mzmine2 by mzmine.

the class SpectrumChartFactory method createMirrorChartPanel.

public static EChartPanel createMirrorChartPanel(String labelA, double precursorMZA, double rtA, DataPoint[] dpsA, String labelB, double precursorMZB, double rtB, DataPoint[] dpsB, boolean showTitle, boolean showLegend) {
    PseudoSpectrumDataSet data = dpsA == null ? null : createMSMSDataSet(precursorMZA, rtA, dpsA, labelA);
    PseudoSpectrumDataSet dataMirror = dpsB == null ? null : createMSMSDataSet(precursorMZB, rtB, dpsB, labelB);
    NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
    NumberFormat intensityFormat = new DecimalFormat("0.#");
    // set the X axis (retention time) properties
    NumberAxis xAxis = new NumberAxis("m/z");
    xAxis.setNumberFormatOverride(mzForm);
    xAxis.setUpperMargin(0.08);
    xAxis.setLowerMargin(0.00);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setMinorTickCount(5);
    PseudoSpectraRenderer renderer1 = new PseudoSpectraRenderer(Color.BLACK, false);
    PseudoSpectraRenderer renderer2 = new PseudoSpectraRenderer(Color.BLACK, false);
    // create subplot 1...
    final NumberAxis rangeAxis1 = new NumberAxis("rel. intensity [%]");
    final XYPlot subplot1 = new XYPlot(data, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    rangeAxis1.setNumberFormatOverride(intensityFormat);
    rangeAxis1.setAutoRangeIncludesZero(true);
    rangeAxis1.setAutoRangeStickyZero(true);
    // create subplot 2...
    final NumberAxis rangeAxis2 = new NumberAxis("rel. intensity [%]");
    rangeAxis2.setNumberFormatOverride(intensityFormat);
    rangeAxis2.setAutoRangeIncludesZero(true);
    rangeAxis2.setAutoRangeStickyZero(true);
    rangeAxis2.setInverted(true);
    final XYPlot subplot2 = new XYPlot(dataMirror, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(0);
    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    // set the plot properties
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    // set rendering order
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // set crosshair (selection) properties
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setVisible(false);
    // chart.getXYPlot().setRangeZeroBaselineVisible(true);
    chart.getTitle().setVisible(showTitle);
    chart.getLegend().setVisible(showLegend);
    return new EChartPanel(chart);
}
Also used : PseudoSpectrumDataSet(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet) EChartPanel(net.sf.mzmine.chartbasics.gui.swing.EChartPanel) NumberAxis(org.jfree.chart.axis.NumberAxis) PseudoSpectraRenderer(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectraRenderer) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) DecimalFormat(java.text.DecimalFormat) RectangleInsets(org.jfree.chart.ui.RectangleInsets) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) JFreeChart(org.jfree.chart.JFreeChart) NumberFormat(java.text.NumberFormat)

Example 5 with PseudoSpectrumDataSet

use of net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet in project mzmine2 by mzmine.

the class SpectrumChartFactory method createMirrorDataSet.

/**
 * Two scans as a mirror comparison
 *
 * @param scan
 * @param mirror gets reflected by *-1
 * @return
 */
public static PseudoSpectrumDataSet createMirrorDataSet(Scan scan, Scan mirror) {
    NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
    NumberFormat rtForm = MZmineCore.getConfiguration().getRTFormat();
    if (scan != null && mirror != null) {
        String label1 = MessageFormat.format("MSMS for m/z={0} RT={1}", mzForm.format(scan.getPrecursorMZ()), rtForm.format(scan.getRetentionTime()));
        String label2 = MessageFormat.format("MSMS for m/z={0} RT={1}", mzForm.format(mirror.getPrecursorMZ()), rtForm.format(mirror.getRetentionTime()));
        // data
        PseudoSpectrumDataSet data = new PseudoSpectrumDataSet(true, label1, label2);
        // for each row
        for (DataPoint dp : scan.getDataPoints()) data.addDP(0, dp.getMZ(), dp.getIntensity(), null);
        for (DataPoint dp : mirror.getDataPoints()) data.addDP(1, dp.getMZ(), -dp.getIntensity(), null);
        return data;
    } else
        return null;
}
Also used : PseudoSpectrumDataSet(net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet) DataPoint(net.sf.mzmine.datamodel.DataPoint) NumberFormat(java.text.NumberFormat)

Aggregations

PseudoSpectrumDataSet (net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectrumDataSet)5 NumberFormat (java.text.NumberFormat)3 DataPoint (net.sf.mzmine.datamodel.DataPoint)3 PseudoSpectraRenderer (net.sf.mzmine.modules.visualization.spectra.multimsms.pseudospectra.PseudoSpectraRenderer)2 JFreeChart (org.jfree.chart.JFreeChart)2 NumberAxis (org.jfree.chart.axis.NumberAxis)2 CombinedDomainXYPlot (org.jfree.chart.plot.CombinedDomainXYPlot)2 XYPlot (org.jfree.chart.plot.XYPlot)2 Color (java.awt.Color)1 DecimalFormat (java.text.DecimalFormat)1 EChartPanel (net.sf.mzmine.chartbasics.gui.swing.EChartPanel)1 Scan (net.sf.mzmine.datamodel.Scan)1 Vision (net.sf.mzmine.util.ColorPalettes.Vision)1 DataPointsTag (net.sf.mzmine.util.spectraldb.entry.DataPointsTag)1 LegendItem (org.jfree.chart.LegendItem)1 LegendItemCollection (org.jfree.chart.LegendItemCollection)1 LegendTitle (org.jfree.chart.title.LegendTitle)1 RectangleInsets (org.jfree.chart.ui.RectangleInsets)1