use of net.sf.mzmine.util.ColorPalettes.Vision 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();
}
Aggregations