Changeset 214


Ignore:
Timestamp:
Dec 7, 2006, 3:15:33 PM (15 years ago)
Author:
Johan Enell
Message:

Fixes #29 #30

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/se/lu/onk/ZTest/src/ztest/Start.java

    r213 r214  
    2424package ztest;
    2525
     26import org.jfree.chart.ChartFactory;
    2627import org.jfree.chart.ChartUtilities;
    2728import org.jfree.chart.JFreeChart;
    2829import org.jfree.chart.axis.LogarithmicAxis;
    2930import org.jfree.chart.axis.NumberAxis;
     31import org.jfree.chart.plot.CombinedDomainXYPlot;
    3032import org.jfree.chart.plot.SeriesRenderingOrder;
    3133import org.jfree.chart.plot.XYPlot;
     
    3537import org.jfree.data.xy.XYSeriesCollection;
    3638
     39import java.awt.Color;
    3740import java.io.File;
    3841import java.io.FileNotFoundException;
     
    139142      XYSeries oSeries = new XYSeries("Observed");
    140143      XYSeries eSeries = new XYSeries("Expected");
     144      XYSeries fdrSeries = new XYSeries("FDR");
    141145     
    142146      PrintWriter html = new PrintWriter(new File("index.html"));
     
    189193          fdr);
    190194       
    191           oSeries.add(rank, rank, true);
    192           eSeries.add(rank, expected, true);
     195          oSeries.add(rank, rank);
     196          eSeries.add(rank, expected);
     197          fdrSeries.add(rank, fdr);
    193198      }
    194199      html.println("</table>");
     
    198203      tab.close();
    199204     
    200      
    201       XYSeriesCollection allSeries = new XYSeriesCollection();
    202       allSeries.addSeries(oSeries);
    203       allSeries.addSeries(eSeries);
    204      
    205       NumberAxis domainAxis = new LogarithmicAxis(""); //x axis
    206       domainAxis.setAutoRangeIncludesZero(false);
    207       domainAxis.setRangeType(RangeType.POSITIVE);
    208       NumberAxis rangeAxis = new NumberAxis(); //y axis
    209       rangeAxis.setRangeType(RangeType.POSITIVE);
    210       rangeAxis.setAutoRangeIncludesZero(true);
    211       XYPlot oePlot = new XYPlot(allSeries, domainAxis, rangeAxis, new XYLineAndShapeRenderer(true, false));
    212       oePlot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    213 
    214       JFreeChart oeChart;
    215       oeChart = new JFreeChart(oePlot);
    216       oeChart.setAntiAlias(false);
    217      
    218       ChartUtilities.saveChartAsPNG(new File("oeplot.png"), oeChart, 800, 600);
     205      plotFDR(fdrSeries);
     206      plotOE(oSeries, eSeries);
     207      plotOE_FDR(oSeries, eSeries, fdrSeries);
    219208    }
    220209    catch (IOException e)
     
    222211      e.printStackTrace();
    223212    }
    224 
     213  }
     214
     215  private static void plotOE_FDR(XYSeries observed, XYSeries expected, XYSeries fdr)
     216    throws IOException
     217  {
     218    NumberAxis domainAxis = new LogarithmicAxis("Rank"); //x axis
     219    domainAxis.setAutoRangeIncludesZero(false);
     220    domainAxis.setRangeType(RangeType.POSITIVE);
     221    NumberAxis rangeAxisFDR = new NumberAxis("FDR"); //y axis fdr
     222    rangeAxisFDR.setRangeType(RangeType.POSITIVE);
     223    rangeAxisFDR.setAutoRangeIncludesZero(true);
     224    NumberAxis rangeAxisOE = new NumberAxis("Observed / Expected"); //y axis o/e
     225    rangeAxisOE.setRangeType(RangeType.POSITIVE);
     226    rangeAxisOE.setAutoRangeIncludesZero(true);
     227   
     228    XYSeriesCollection datasetOE = new XYSeriesCollection();
     229    datasetOE.addSeries(observed);
     230    datasetOE.addSeries(expected);
     231    XYSeriesCollection datasetFDR = new XYSeriesCollection();
     232    datasetFDR.addSeries(fdr);
     233
     234    XYLineAndShapeRenderer oeRenderer = new XYLineAndShapeRenderer(true, false);
     235    oeRenderer.setSeriesPaint(0, Color.RED);
     236    oeRenderer.setSeriesPaint(1, Color.BLUE);
     237    XYLineAndShapeRenderer fdrRenderer = new XYLineAndShapeRenderer(true, false);
     238    fdrRenderer.setSeriesPaint(0, Color.BLACK);
     239   
     240    XYPlot plot = new XYPlot();
     241    plot.setDomainAxis(domainAxis);
     242   
     243    plot.setDataset(0, datasetOE);
     244    plot.setRangeAxis(0, rangeAxisOE);
     245    plot.mapDatasetToRangeAxis(0, 0);
     246    plot.setRenderer(0, oeRenderer);
     247   
     248    plot.setDataset(1, datasetFDR);
     249    plot.setRangeAxis(1, rangeAxisFDR);
     250    plot.mapDatasetToRangeAxis(1, 1);
     251    plot.setRenderer(1, fdrRenderer);
     252   
     253    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
     254   
     255    JFreeChart chart;
     256    chart = new JFreeChart(plot);
     257    chart.setAntiAlias(false);
     258   
     259    ChartUtilities.saveChartAsPNG(new File("oe_fdrplot.png"), chart, 800, 600);
     260  }
     261 
     262  private static void plotFDR(XYSeries fdr) throws IOException
     263  {
     264    XYLineAndShapeRenderer fdrRenderer = new XYLineAndShapeRenderer(true, false);
     265    fdrRenderer.setSeriesPaint(0, Color.BLACK);
     266   
     267    NumberAxis domainAxis = new LogarithmicAxis("Rank"); //x axis
     268    domainAxis.setAutoRangeIncludesZero(false);
     269    domainAxis.setRangeType(RangeType.POSITIVE);
     270    NumberAxis rangeAxis = new NumberAxis("FDR"); //y axis
     271    rangeAxis.setRangeType(RangeType.POSITIVE);
     272    rangeAxis.setAutoRangeIncludesZero(true);
     273    XYPlot plot = new XYPlot(new XYSeriesCollection(fdr), domainAxis, rangeAxis, fdrRenderer);
     274    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
     275
     276    JFreeChart chart;
     277    chart = new JFreeChart(plot);
     278    chart.setAntiAlias(false);
     279    chart.removeLegend();
     280   
     281    ChartUtilities.saveChartAsPNG(new File("fdrplot.png"), chart, 800, 600);
     282  }
     283 
     284  private static void plotOE(XYSeries observed, XYSeries expected) throws IOException
     285  {
     286    XYSeriesCollection allSeries = new XYSeriesCollection();
     287    allSeries.addSeries(observed);
     288    allSeries.addSeries(expected);
     289   
     290    XYLineAndShapeRenderer oeRenderer = new XYLineAndShapeRenderer(true, false);
     291    oeRenderer.setSeriesPaint(0, Color.RED);
     292    oeRenderer.setSeriesPaint(1, Color.BLUE);
     293   
     294    NumberAxis domainAxis = new LogarithmicAxis("Rank"); //x axis
     295    domainAxis.setAutoRangeIncludesZero(false);
     296    domainAxis.setRangeType(RangeType.POSITIVE);
     297    NumberAxis rangeAxis = new NumberAxis(); //y axis
     298    rangeAxis.setRangeType(RangeType.POSITIVE);
     299    rangeAxis.setAutoRangeIncludesZero(true);
     300    XYPlot plot = new XYPlot(allSeries, domainAxis, rangeAxis, oeRenderer);
     301    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
     302
     303    JFreeChart chart;
     304    chart = new JFreeChart(plot);
     305    chart.setAntiAlias(false);
     306   
     307    ChartUtilities.saveChartAsPNG(new File("oeplot.png"), chart, 800, 600);
    225308  }
    226309 
Note: See TracChangeset for help on using the changeset viewer.