knakul853

Untitled

Jun 20th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.85 KB | None | 0 0
  1. package io.github.mzmine.modules.visualization.ims.imsVisualizer;
  2.  
  3. import com.google.common.collect.Range;
  4. import io.github.mzmine.gui.chartbasics.chartthemes.EStandardChartTheme;
  5. import io.github.mzmine.gui.chartbasics.chartutils.XYBlockPixelSizePaintScales;
  6. import io.github.mzmine.gui.chartbasics.chartutils.XYBlockPixelSizeRenderer;
  7. import io.github.mzmine.gui.chartbasics.gui.javafx.EChartViewer;
  8. import io.github.mzmine.main.MZmineCore;
  9. import io.github.mzmine.parameters.ParameterSet;
  10. import org.jfree.chart.ChartFactory;
  11. import org.jfree.chart.JFreeChart;
  12. import org.jfree.chart.axis.AxisLocation;
  13. import org.jfree.chart.axis.NumberAxis;
  14. import org.jfree.chart.block.BlockBorder;
  15. import org.jfree.chart.plot.CombinedDomainXYPlot;
  16. import org.jfree.chart.plot.CombinedRangeXYPlot;
  17. import org.jfree.chart.plot.PlotOrientation;
  18. import org.jfree.chart.plot.XYPlot;
  19. import org.jfree.chart.renderer.LookupPaintScale;
  20. import org.jfree.chart.renderer.xy.XYBlockRenderer;
  21. import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
  22. import org.jfree.chart.title.PaintScaleLegend;
  23. import org.jfree.chart.ui.RectangleEdge;
  24. import org.jfree.chart.ui.RectangleInsets;
  25. import org.jfree.data.xy.XYDataset;
  26. import org.jfree.data.xy.XYZDataset;
  27.  
  28. import java.awt.*;
  29. import java.util.Arrays;
  30. import java.util.logging.Logger;
  31.  
  32. public class MobilityRetentionHeatMapPlot extends EChartViewer {
  33.  
  34.   private XYPlot plot3d;
  35.   private XYPlot plot2d;
  36.   private String paintScaleStyle;
  37.   private JFreeChart chart;
  38.   private XYZDataset dataset3d;
  39.   private XYDataset dataset2d;
  40.   private Logger logger = Logger.getLogger(this.getClass().getName());
  41.   static final Font legendFont = new Font("SansSerif", Font.PLAIN, 12);
  42.   private EStandardChartTheme theme;
  43.   private ParameterSet parameterSet;
  44.  
  45.  
  46.   public MobilityRetentionHeatMapPlot(ParameterSet parameterSet, String paintScaleStyle) {
  47.  
  48.       this.paintScaleStyle = paintScaleStyle;
  49.       this.parameterSet = parameterSet;
  50.       this.dataset3d = new RetentionTimeMobilityXYZDataset(parameterSet);
  51.       this.dataset2d = new IntensityRetentionTimeXYDataset(parameterSet);
  52.       // Create 2d plots
  53.     var renderer2d = new XYLineAndShapeRenderer();
  54.     renderer2d.setSeriesPaint(0, Color.GREEN);
  55.     renderer2d.setSeriesStroke(0, new BasicStroke(1.0f));
  56.     NumberAxis range2d = new NumberAxis("intensity");
  57.     plot2d = new XYPlot(dataset2d, null, range2d, renderer2d);
  58.     plot2d.setRenderer(renderer2d);
  59.     plot2d.setBackgroundPaint(Color.BLACK);
  60.     plot2d.setRangeGridlinePaint(Color.RED);
  61.     plot2d.setDomainGridlinePaint(Color.RED);
  62.     plot2d.setOutlinePaint(Color.red);
  63.     plot2d.setOutlineStroke(new BasicStroke(2.5f));
  64.  
  65.  
  66.       // create 3d plot.
  67.     double[] copyZValues = new double[dataset3d.getItemCount(0)];
  68.     double[] copyXValues = new double[dataset3d.getItemCount(0)];
  69.     double[] copyYValues = new double[dataset3d.getItemCount(0)];
  70.  
  71.     for (int i = 0; i < dataset3d.getItemCount(0); i++) {
  72.       copyZValues[i] = dataset3d.getZValue(0, i);
  73.       copyXValues[i] = dataset3d.getXValue(0, i);
  74.       copyYValues[i] = dataset3d.getYValue(0, i);
  75.     }
  76.     Arrays.sort(copyZValues);
  77.     Arrays.sort(copyXValues);
  78.     Arrays.sort(copyYValues);
  79.  
  80.     // get index in accordance to percentile windows
  81.     int minIndexScale = 0;
  82.     int maxIndexScale = copyZValues.length - 1;
  83.     double min = copyZValues[minIndexScale];
  84.     double max = copyZValues[maxIndexScale];
  85.     Paint[] contourColors =
  86.         XYBlockPixelSizePaintScales.getPaintColors(
  87.             "percentile", Range.closed(min, max), paintScaleStyle);
  88.     LookupPaintScale scale = new LookupPaintScale(min, max, Color.BLACK);
  89.  
  90.     double[] scaleValues = new double[contourColors.length];
  91.     double delta = (max - min) / (contourColors.length - 1);
  92.     double value = min;
  93.     for (int i = 0; i < contourColors.length; i++) {
  94.       scaleValues[i] = value;
  95.       scale.add(value, contourColors[i]);
  96.       value = value + delta;
  97.     }
  98.  
  99.     // set the pixel renderer
  100.     XYBlockPixelSizeRenderer pixelRenderer = new XYBlockPixelSizeRenderer();
  101.     pixelRenderer.setPaintScale(scale);
  102.     // set the block renderer
  103.     XYBlockRenderer blockRenderer = new XYBlockRenderer();
  104.     double retentionWidth = 0.0;
  105.     double mobilityWidth = 0.0;
  106.  
  107.     for (int i = 0; i + 1 < copyXValues.length; i++) {
  108.       if (copyXValues[i] != copyXValues[i + 1]) {
  109.         retentionWidth = copyXValues[i + 1] - copyXValues[i];
  110.         break;
  111.       }
  112.     }
  113.     for (int i = 0; i + 1 < copyYValues.length; i++) {
  114.       if (copyYValues[i] != copyYValues[i + 1]) {
  115.         mobilityWidth = copyYValues[i + 1] - copyYValues[i];
  116.         break;
  117.       }
  118.     }
  119.  
  120.     if (mobilityWidth <= 0.0 || retentionWidth <= 0.0) {
  121.       throw new IllegalArgumentException(
  122.           "there must be atleast two unique value of retentio time and mobility");
  123.     }
  124.     blockRenderer.setBlockHeight(mobilityWidth);
  125.     blockRenderer.setBlockWidth(retentionWidth);
  126.  
  127.     NumberAxis range3d = new NumberAxis("mobility");
  128.     plot3d = new XYPlot(dataset3d,null, range3d, blockRenderer);
  129.  
  130.     // Legend
  131.     NumberAxis scaleAxis = new NumberAxis("Intensity");
  132.     scaleAxis.setRange(min, max);
  133.     scaleAxis.setAxisLinePaint(Color.white);
  134.     scaleAxis.setTickMarkPaint(Color.white);
  135.     PaintScaleLegend legend = new PaintScaleLegend(scale, scaleAxis);
  136.  
  137.     legend.setStripOutlineVisible(false);
  138.     legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
  139.     legend.setAxisOffset(5.0);
  140.     legend.setMargin(new RectangleInsets(5, 5, 5, 5));
  141.     legend.setFrame(new BlockBorder(Color.white));
  142.     legend.setPadding(new RectangleInsets(10, 10, 10, 10));
  143.     legend.setStripWidth(10);
  144.     legend.setPosition(RectangleEdge.RIGHT);
  145.     legend.getAxis().setLabelFont(legendFont);
  146.     legend.getAxis().setTickLabelFont(legendFont);
  147.  
  148.     // Set paint scale
  149.     blockRenderer.setPaintScale(scale);
  150.  
  151.     plot3d.setRenderer(blockRenderer);
  152.     plot3d.setBackgroundPaint(Color.black);
  153.     plot3d.setRangeGridlinePaint(Color.black);
  154.     plot3d.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
  155.     plot3d.setOutlinePaint(Color.black);
  156.     plot3d.setDomainCrosshairPaint(Color.GRAY);
  157.     plot3d.setRangeCrosshairPaint(Color.GRAY);
  158.     plot3d.setDomainCrosshairVisible(true);
  159.     plot3d.setRangeCrosshairVisible(true);
  160.     plot3d.setOutlinePaint(Color.red);
  161.     plot3d.setOutlineStroke(new BasicStroke(2.5f));
  162.  
  163.     NumberAxis domain3d = new NumberAxis("retention time");
  164.     domain3d.setRange(copyXValues[0], copyXValues[copyXValues.length-1]);
  165.     CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domain3d);
  166.     plot.setOrientation(PlotOrientation.VERTICAL);
  167.     plot.add(plot2d);
  168.     plot.setGap(10.0);
  169.     plot.add(plot3d);
  170.  
  171.     chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
  172.     chart.addSubtitle(legend);
  173.  
  174.     setChart(chart);
  175.   }
  176.  
  177.  // public XYPlot getPlot(){ return plot;}
  178. }
Add Comment
Please, Sign In to add comment