Changeset 217


Ignore:
Timestamp:
Dec 8, 2006, 5:20:24 PM (15 years ago)
Author:
Johan Enell
Message:

References #32. Needs a normsdist function and the HistogramDataset? must create new bins on the fly.

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

Legend:

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

    r216 r217  
    3030import org.jfree.chart.plot.SeriesRenderingOrder;
    3131import org.jfree.chart.plot.XYPlot;
     32import org.jfree.chart.renderer.xy.XYBarRenderer;
    3233import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    3334import org.jfree.data.RangeType;
     35import org.jfree.data.statistics.SimpleHistogramDataset;
     36import org.jfree.data.xy.IntervalXYDataset;
    3437import org.jfree.data.xy.XYSeries;
    3538import org.jfree.data.xy.XYSeriesCollection;
     
    4144public class Plot
    4245{
     46  public static class HistogramDataset extends SimpleHistogramDataset
     47  {
     48
     49    public HistogramDataset(Comparable key)
     50    {
     51      super(key);
     52    }
     53
     54    @Override
     55    public void addObservation(double value, boolean notify)
     56    {
     57      try
     58      {
     59        super.addObservation(value, notify);
     60      }
     61      catch (RuntimeException e)
     62      {
     63        //TODO create new bin
     64        super.addObservation(value, notify);
     65      }
     66    }
     67   
     68   
     69  }
     70
    4371  static void plotOE_FDR(XYSeries observed, XYSeries expected, XYSeries fdr)
    4472    throws IOException
     
    5078    rangeAxisFDR.setRangeType(RangeType.POSITIVE);
    5179    rangeAxisFDR.setAutoRangeIncludesZero(true);
    52     NumberAxis rangeAxisOE = new NumberAxis("Observed / Expected"); // y axis
    53                                                                     // o/e
     80    NumberAxis rangeAxisOE = new NumberAxis("Observed / Expected"); // y axis oe
    5481    rangeAxisOE.setRangeType(RangeType.POSITIVE);
    5582    rangeAxisOE.setAutoRangeIncludesZero(true);
     
    82109    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    83110
    84     JFreeChart chart;
    85     chart = new JFreeChart(plot);
     111    JFreeChart chart = new JFreeChart(plot);
    86112    chart.setAntiAlias(false);
    87113
     
    104130    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    105131
    106     JFreeChart chart;
    107     chart = new JFreeChart(plot);
     132    JFreeChart chart = new JFreeChart(plot);
    108133    chart.setAntiAlias(false);
    109134    chart.removeLegend();
     
    132157    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    133158
    134     JFreeChart chart;
    135     chart = new JFreeChart(plot);
     159    JFreeChart chart = new JFreeChart(plot);
    136160    chart.setAntiAlias(false);
    137161
    138162    ChartUtilities.saveChartAsPNG(new File("oeplot.png"), chart, 800, 600);
    139163  }
     164
     165  static void plotMHist(IntervalXYDataset m, double mean, double sd)
     166    throws IOException
     167  {
     168    NumberAxis domainAxis = new NumberAxis("M, log2(int1/int2)");
     169    NumberAxis rangeAxis = new NumberAxis("Frequence");
     170    rangeAxis.setAutoRangeIncludesZero(true);
     171
     172    XYBarRenderer hRenderer = new XYBarRenderer();
     173    XYLineAndShapeRenderer ndRenderer = new XYLineAndShapeRenderer(true, false);
     174
     175    XYPlot plot = new XYPlot();
     176    plot.setDomainAxis(domainAxis);
     177    plot.setRangeAxis(rangeAxis);
     178   
     179    plot.setDataset(0, m);
     180    plot.setRenderer(0, hRenderer);
     181   
     182    plot.setDataset(1, null);
     183    plot.setRenderer(1, ndRenderer);
     184
     185    JFreeChart chart = new JFreeChart(plot);
     186    chart.setAntiAlias(false);
     187
     188    ChartUtilities.saveChartAsPNG(new File("mhist.png"), chart, 800, 600);
     189  }
    140190}
  • trunk/se/lu/onk/ZTest/src/ztest/Start.java

    r216 r217  
    4040public class Start
    4141{
     42 
     43  private static ZTest ztest = new ZTest();
    4244
    4345  /**
     
    8991        data = bfr.readDataRow(dataLength);
    9092      }
    91       ZTest ztest = new ZTest();
    9293      ztest.calculate(bfss);
    9394
     
    131132      XYSeries eSeries = new XYSeries("Expected");
    132133      XYSeries fdrSeries = new XYSeries("FDR");
    133      
     134      Plot.HistogramDataset mHist = new Plot.HistogramDataset("M");
     135
    134136      PrintWriter html = new PrintWriter(new File("index.html"));
    135137      PrintWriter tab = new PrintWriter(new File("result.tsv"));
     
    147149          "<th>P</th><th>Number of values</th><th>Rank</th><th>Expected</th><th>FDR</th></tr>");
    148150      tab.println("Reporter\tGeneSymbol\tLocusLink\tAverageM\tP\tNumberOfValues\tRank\tExpected\tFDR");
    149      
     151
    150152      for (int i = 0; i < bfss.getReporterSize(); i++)
    151153      {
     
    184186          eSeries.add(rank, expected);
    185187          fdrSeries.add(rank, fdr);
     188          mHist.addObservation(r.getM());
    186189      }
    187190      html.println("</table>");
     
    194197      Plot.plotOE(oSeries, eSeries);
    195198      Plot.plotOE_FDR(oSeries, eSeries, fdrSeries);
     199      Plot.plotMHist(mHist, ztest.getTotalMean(), ztest.getTotalSD());
    196200    }
    197201    catch (IOException e)
  • trunk/se/lu/onk/ZTest/src/ztest/ZTest.java

    r206 r217  
    3434public class ZTest
    3535{
     36  private HashMap<Integer, Double> means;
     37 
     38  private HashMap<Integer, Double> sds;
     39 
    3640  public void calculate(BASEFileSpotSection<Reporter, Spot> bfss)
    3741  {
    3842    List<Integer> assays = bfss.findFieldIntList("assays");
    39     HashMap<Integer, Double> means = getAssayMeans(bfss, assays);
    40     HashMap<Integer, Double> sds = getAssaySDS(bfss, assays, means);
     43    means = getAssayMeans(bfss, assays);
     44    sds = getAssaySDS(bfss, assays, means);
    4145   
    4246    for (int i = 0; i < bfss.getReporterSize(); i++)
     
    7276      r.setSize(popSize);
    7377    }
     78  }
     79 
     80  public double getTotalSD()
     81  {
     82    double sd = 0;
     83    for(Double d : sds.values())
     84    {
     85      sd += Math.pow(d, 2);
     86    }
     87    return Math.sqrt(sd) / sds.size();
     88  }
     89 
     90  public double getTotalMean()
     91  {
     92    double mean = 0;
     93    for(Double d : means.values())
     94    {
     95      mean += d;
     96    }
     97    return mean/means.size();
    7498  }
    7599
Note: See TracChangeset for help on using the changeset viewer.