Changeset 222


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

References #37

Location:
trunk/se/lu/onk/Smooth/src/smooth
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/se/lu/onk/Smooth/src/smooth/Smooth.java

    r150 r222  
    11package smooth;
    22
     3import org.jfree.data.statistics.BoxAndWhiskerCalculator;
     4import org.jfree.data.statistics.BoxAndWhiskerItem;
     5
    36import basefile.BASEFileSpotSection;
    47
    58import java.util.Arrays;
     9import java.util.Collections;
    610import java.util.Comparator;
     11import java.util.HashMap;
    712import java.util.Iterator;
    813import java.util.LinkedList;
    914import java.util.List;
     15import java.util.Map;
    1016
    1117/**
     
    3945
    4046  private float w;
     47 
     48  private Map<Integer, BoxAndWhiskerItem> boxAndWhiskerItems;
    4149
    4250  /**
     
    6068    this.winSize = winSize;
    6169    this.w = w;
     70    this.boxAndWhiskerItems = new HashMap<Integer, BoxAndWhiskerItem>();
    6271  }
    6372
     
    9099    });
    91100
     101    List<Integer> winSizes = new LinkedList<Integer>();
     102   
    92103    while (chromosomeIterator.hasNext())
    93104    {
     
    117128            }
    118129          }
     130          winSizes.add(reporters.get(stop).getChrPosition() - reporters.get(start).getChrPosition());
    119131        }
    120132        else if (winType.equals("bp"))
     
    133145            }
    134146          }
     147          winSizes.add(stop - start);
    135148        }
    136149        float mean = Float.NaN;
     
    151164      }
    152165    }
     166    boxAndWhiskerItems.put(bfss.findIntOpt("assays"), BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(winSizes));
     167  }
     168
     169  public BoxAndWhiskerItem getBoxAndWhiskerItem(Integer assayId)
     170  {
     171    return boxAndWhiskerItems.get(assayId);
    153172  }
    154173
  • trunk/se/lu/onk/Smooth/src/smooth/SmoothMain.java

    r151 r222  
    2424package smooth;
    2525
     26import org.jfree.chart.ChartUtilities;
     27import org.jfree.chart.JFreeChart;
     28import org.jfree.chart.axis.CategoryAxis;
     29import org.jfree.chart.axis.LogarithmicAxis;
     30import org.jfree.chart.axis.NumberAxis;
     31import org.jfree.chart.axis.ValueAxis;
     32import org.jfree.chart.plot.CategoryPlot;
     33import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
     34import org.jfree.data.RangeType;
     35import org.jfree.data.statistics.BoxAndWhiskerItem;
     36import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
     37
    2638import basefile.BASEFileException;
    2739import basefile.BASEFileReader;
     
    3042
    3143import java.io.File;
     44import java.io.IOException;
    3245import java.io.PrintStream;
     46import java.util.HashMap;
    3347import java.util.List;
     48import java.util.Map;
    3449
    3550/**
     
    8095        System.exit(-1);
    8196      }
     97     
     98      bfs = bfr.readSection();
     99      if (!bfs.isType("assays"))
     100      {
     101        throw new BASEFileException("Can't find section assays");
     102      }
     103      Map<Integer, String> assays = getAssays(bfs, bfr);
     104     
    82105      System.out.println("BASEfile");
    83106
     
    86109      while (bfss != null)
    87110      {
    88         bfss.setDataMatrix(bfss.findIntOpt("count"), bfss.findFieldList("assays").size());
    89111        List<String> columns = bfss.findFieldList("columns");
    90112        List<String> assayFields = bfss.findFieldList("assayFields");
     
    110132            bfss.addData(r, s);
    111133          }
    112           catch (NumberFormatException e)
     134          catch (Exception e)
    113135          {}
    114136          data = bfr.readDataRow(7);
     
    130152      }
    131153
     154      plot(assays, smooth);
     155     
    132156    }
    133157    catch (OutOfMemoryError oome)
    134158    {
    135       System.err.println("No more memory in the java virtual machine. Start the application with more memory. If you need even more memory, duplicate the digit");
     159      System.err.println("No more memory in the java virtual machine. Start the application with more memory.");
    136160      System.exit(-1);
    137161    }
     
    143167  }
    144168
     169  private static void plot(Map<Integer, String> assays, Smooth smooth) throws IOException
     170  {
     171    DefaultBoxAndWhiskerCategoryDataset data = new DefaultBoxAndWhiskerCategoryDataset();
     172    for (Integer assayId : assays.keySet())
     173    {
     174      BoxAndWhiskerItem bw = smooth.getBoxAndWhiskerItem(assayId);
     175      data.add(bw, "Windows distibution", assays.get(assayId));
     176    }
     177   
     178    CategoryAxis domainAxis = new CategoryAxis("Sample"); // x axis
     179    NumberAxis rangeAxis = new NumberAxis("Window size"); // y axis fdr
     180    rangeAxis.setAutoRangeIncludesZero(true);
     181   
     182    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
     183    CategoryPlot plot = new CategoryPlot(data, domainAxis, rangeAxis, renderer);
     184   
     185    JFreeChart chart = new JFreeChart(plot);
     186    chart.setAntiAlias(false);
     187
     188    ChartUtilities.saveChartAsPNG(new File("windowsize.png"), chart, 800, 600);
     189  }
     190
     191  private static Map<Integer, String> getAssays(BASEFileSection bfs, BASEFileReader bfr) throws IOException
     192  {
     193    List<String> columns = bfs.findFieldList("columns");
     194    int idCol = columns.indexOf("id");
     195    int nameCol = columns.indexOf("name");
     196
     197    Map<Integer, String> assays = new HashMap<Integer, String>();
     198    String[] data = bfr.readDataRow();
     199    while (data != null)
     200    {
     201      assays.put(new Integer(data[idCol]), data[nameCol]);
     202      data = bfr.readDataRow();
     203    }
     204    return assays;
     205  }
     206
    145207}
Note: See TracChangeset for help on using the changeset viewer.