Changeset 216


Ignore:
Timestamp:
Dec 7, 2006, 4:55:44 PM (15 years ago)
Author:
Johan Enell
Message:

moved plotfunctions to their own class

Location:
trunk/se/lu/onk/ZTest/src/ztest
Files:
1 added
1 edited

Legend:

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

    r214 r216  
    2424package ztest;
    2525
    26 import org.jfree.chart.ChartFactory;
    27 import org.jfree.chart.ChartUtilities;
    28 import org.jfree.chart.JFreeChart;
    29 import org.jfree.chart.axis.LogarithmicAxis;
    30 import org.jfree.chart.axis.NumberAxis;
    31 import org.jfree.chart.plot.CombinedDomainXYPlot;
    32 import org.jfree.chart.plot.SeriesRenderingOrder;
    33 import org.jfree.chart.plot.XYPlot;
    34 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    35 import org.jfree.data.RangeType;
    3626import org.jfree.data.xy.XYSeries;
    37 import org.jfree.data.xy.XYSeriesCollection;
    38 
    39 import java.awt.Color;
     27
    4028import java.io.File;
    4129import java.io.FileNotFoundException;
     
    203191      tab.close();
    204192     
    205       plotFDR(fdrSeries);
    206       plotOE(oSeries, eSeries);
    207       plotOE_FDR(oSeries, eSeries, fdrSeries);
     193      Plot.plotFDR(fdrSeries);
     194      Plot.plotOE(oSeries, eSeries);
     195      Plot.plotOE_FDR(oSeries, eSeries, fdrSeries);
    208196    }
    209197    catch (IOException e)
     
    211199      e.printStackTrace();
    212200    }
    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);
    308   }
    309  
     201  }
    310202}
Note: See TracChangeset for help on using the changeset viewer.