Changeset 1135


Ignore:
Timestamp:
Jun 23, 2009, 3:52:29 PM (12 years ago)
Author:
Martin Svensson
Message:

References #180 The overview plots are almost finished. Some smaller adjustments concerning the image format and axis-size are left to do.

Location:
plugins/base2/net.sf.basedb.illumina/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.illumina/trunk/META-INF/extensions.xml

    r1133 r1135  
    3232    <about>
    3333      <name>Illumina overview plot</name>
    34       <description> Generates overview plot for Illumina expression data.</description>
     34      <description>Generates overview plot for Illumina expression data.</description>
    3535    </about>
    3636    <action-factory>
    3737      <factory-class>net.sf.basedb.illumina.extensions.plot.PlotFactory</factory-class>
    3838      <parameters>
    39         <width>400</width>
    40         <height>300</height>
    41         <plotServlet>/views/experiments/plotter/illuminaPlot</plotServlet>
     39        <width>1000</width>
     40        <height>700</height>       
    4241      </parameters>
    4342    </action-factory>
  • plugins/base2/net.sf.basedb.illumina/trunk/META-INF/servlets.xml

    r1133 r1135  
    2323<servlets xmlns="http://base.thep.lu.se/servlets.xsd"> 
    2424  <servlet> 
    25     <servlet-name>illuminaplot</servlet-name> 
     25    <servlet-name>illuminaPlot</servlet-name> 
    2626        <servlet-class>net.sf.basedb.illumina.servlet.IlluminaPlotServlet</servlet-class> 
    2727    <init-param>
  • plugins/base2/net.sf.basedb.illumina/trunk/src/net/sf/basedb/illumina/extensions/plot/PlotFactory.java

    r1133 r1135  
    2929import net.sf.basedb.clients.web.extensions.plot.PlotGenerator;
    3030import net.sf.basedb.clients.web.extensions.plot.PlotGeneratorBean;
    31 import net.sf.basedb.clients.web.servlet.PlotServlet;
    3231import net.sf.basedb.clients.web.util.HTML;
    3332import net.sf.basedb.core.BioAssaySet;
     33import net.sf.basedb.illumina.servlet.IlluminaPlotServlet;
    3434import net.sf.basedb.util.Values;
    3535import net.sf.basedb.util.extensions.InvokationContext;
     
    4646  data stored in the database.
    4747  <p>
    48   If the conditions are fulfilled one plot for each
    49   bioassay will be generated. The image generation
    50   is handled by the standard plot servlet: {@link PlotServlet}.
     48  The image generation
     49  is handled by the standard plot servlet: {@link IlluminaPlotServlet}.
    5150 
    5251  @version 1.4
     
    5857{
    5958
    60   private String servletPath = ExtensionsControl.getHomeUrl("net.sf.basedb.illumina.extensions.overviewplots.illuminaPlots") + "/illuminaplot";
    61   private int width = 400;
    62   private int height = 300;
     59  private String servletPath = null;
     60  private int width = 1200;
     61  private int height = 600;
    6362
    6463  public PlotFactory()
     
    101100    OverviewPlotAction[] actions = new OverviewPlotAction[1];
    102101   
    103     // Control summary (perfect match) plot
     102    // Control summary plot
    104103    OverviewPlotBean overviewBean = new OverviewPlotBean();   
    105104    overviewBean.setTitle("Control summary plots");
     
    108107   
    109108    List<String>  filters = new ArrayList<String>(2);
    110     filters.add(HTML.urlEncode("raw(mean)"));
    111     filters.add(HTML.urlEncode("raw(mean)"));
     109//    filters.add(HTML.urlEncode("rep('controlGroupId') == '%:pm%'"));
     110//    filters.add(HTML.urlEncode("rep('controlGroupId') == '%housekeeping%'"));
    112111   
    113112    List<String> series = new ArrayList<String> (2);
    114     series.add(HTML.urlEncode("Perfect match"));
    115     series.add(HTML.urlEncode("House keeping"));
     113//    series.add(HTML.urlEncode("Perfect match"));
     114//    series.add(HTML.urlEncode("House keeping"));
    116115   
    117     String columnFormula = HTML.urlEncode("ch(1)");
     116    String columnFormula = HTML.urlEncode("raw('mean')");
    118117
    119118    PlotGenerator[] plotGenerators = new PlotGenerator[1];
     
    122121    actions[0] = overviewBean;   
    123122       
    124     // Generate plot url:s for each bioassay
     123    // Generate plot url
    125124    String xLabel = HTML.urlEncode("Raw bioassay");
    126125    String yLabel = HTML.urlEncode("Signal");
     126   
     127    StringBuilder urlString = new StringBuilder();
     128   
     129    servletPath = servletPath == null ? ExtensionsControl.getHomeUrl("net.sf.basedb.illumina.extensions.overviewplots.illuminaPlots") + "/illuminaPlot.servlet" : servletPath;
     130    urlString.append(servletPath + "?ID=" + ID );
     131    urlString.append("&bioassayset_id=" + source.getId());       
     132    urlString.append("&width="+width+"&height=" + height);   
    127133   
    128134    PlotGeneratorBean overviewPlot = new PlotGeneratorBean();
     
    131137    overviewPlot.setHeight(height);
    132138    overviewPlot.setTitle("Control summary plot");
    133     overviewPlot.setUrl(
    134         servletPath + "?ID=" + ID +
    135         "&bioassayset_id=" + source.getId() +       
    136         "&width="+width+"&height=" + height +
    137         "&cache=overview/bioassayset." + source.getId() + "/controlsummaryplot.png" +
    138         "&xLabel="+xLabel+"&yLabel="+yLabel +
    139         "&filters="+filters +
    140         "&columnFormula="+columnFormula +
    141         "&series="+series +
    142         "&title="+HTML.urlEncode("Control summary plot")
    143     );
     139    overviewPlot.setUrl(urlString.toString());
     140       
    144141    plotGenerators[0] = overviewPlot;   
    145142       
  • plugins/base2/net.sf.basedb.illumina/trunk/src/net/sf/basedb/illumina/servlet/IlluminaPlotServlet.java

    r1133 r1135  
    3535import net.sf.basedb.core.Path;
    3636import net.sf.basedb.core.SessionControl;
     37import net.sf.basedb.core.query.Dynamic;
     38import net.sf.basedb.core.query.Expression;
     39import net.sf.basedb.core.query.Expressions;
     40import net.sf.basedb.core.query.JoinType;
    3741import net.sf.basedb.core.query.Restriction;
    3842import net.sf.basedb.core.query.Restrictions;
    3943import net.sf.basedb.core.query.Selects;
    4044import net.sf.basedb.core.query.SqlResult;
    41 import net.sf.basedb.util.BioAssaySetUtil;
    4245import net.sf.basedb.util.FileUtil;
    4346import net.sf.basedb.util.StaticCache;
     
    5659import java.sql.SQLException;
    5760import java.util.ArrayList;
    58 import java.util.Arrays;
    59 import java.util.HashMap;
    6061import java.util.List;
    61 import java.util.Map;
    6262
    6363import javax.imageio.ImageIO;
     
    7070import org.apache.commons.io.output.TeeOutputStream;
    7171import org.jfree.chart.JFreeChart;
     72import org.jfree.chart.axis.CategoryAxis;
     73import org.jfree.chart.axis.CategoryLabelPositions;
    7274import org.jfree.chart.axis.NumberAxis;
    7375import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
    7476import org.jfree.chart.plot.CategoryPlot;
     77import org.jfree.chart.plot.CombinedDomainCategoryPlot;
    7578import org.jfree.chart.renderer.category.CategoryItemRenderer;
    7679import org.jfree.chart.renderer.category.LineAndShapeRenderer;
     
    9194     
    9295  */
    93   private static final long serialVersionUID = 1L;
    9496  private int maxWidth = 1000;
    9597  private int maxHeight = 800;
     
    110112    defaultFormat = Values.getString(cfg.getInitParameter("defaultFormat"), defaultFormat);
    111113    cacheBase = Values.getString(cfg.getInitParameter("cacheBase"), cacheBase);
    112     System.out.println("external servlet");
    113114  }
    114115 
     
    143144    }
    144145   
    145     // Formulas to plot
    146     final String columnFormula = request.getParameter("columnFormula");
    147     final List<String> filterFormulas = Arrays.asList(request.getParameterValues("filters"));
    148  
    149146    // Axis, legends and titles
    150147    String title = Values.getStringOrNull(request.getParameter("title"));
    151     String subTitle = Values.getStringOrNull(request.getParameter("subTitle"));
    152     String[] series = request.getParameterValues("series");
    153     String xLabel = Values.getStringOrNull(request.getParameter("xLabel"));
    154     if (xLabel == null) xLabel = "Raw bioassay";
    155     String yLabel = Values.getStringOrNull(request.getParameter("yLabel"));
    156     if (yLabel != null) yLabel = "Average intensity";
     148    String subTitle = Values.getStringOrNull(request.getParameter("subTitle"));   
    157149     
    158150    StaticCache cache = Application.getStaticCache();
     
    185177         
    186178          BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId);
    187           ItemQuery<BioAssay> bioassays = bas.getBioAssays();
     179          ItemQuery<BioAssay> bioassayQuery = bas.getBioAssays();
     180         
     181          // Prepare chart and datasets
    188182          JFreeChart chart = null;
    189           Map<String, DefaultCategoryDataset> datasets = new HashMap<String, DefaultCategoryDataset>(filterFormulas.size());
    190           List<Restriction> controlGroupIdRestrictions = new ArrayList<Restriction>();
    191          
    192           for (String filter : filterFormulas)
    193           {
    194             datasets.put(filter, new DefaultCategoryDataset());
    195             controlGroupIdRestrictions.add(BioAssaySetUtil.createJepRestriction(dc, bas, filter, false));
    196           }                 
    197           Restriction restrictions = Restrictions.or(
    198               controlGroupIdRestrictions.toArray(new Restriction[controlGroupIdRestrictions.size()]));
    199          
    200           for (BioAssay ba : bioassays.list(dc))
    201           {
     183          DefaultCategoryDataset pmDataset = new DefaultCategoryDataset();
     184          DefaultCategoryDataset houseKeepingDataset = new DefaultCategoryDataset();
     185         
     186          String perfectMatch = ":pm";
     187          String houseKeeping = "housekeeping";
     188          String restrictionColumn = "controlGroupId";
     189          String meanColumn = "mean";
     190         
     191          Restriction pmRestriction = Restrictions.like(Dynamic.reporter(restrictionColumn), Expressions.string("%"+perfectMatch+"%"));
     192          Restriction hkRestriction = Restrictions.like(Dynamic.reporter(restrictionColumn), Expressions.string("%"+houseKeeping+"%"));
     193          Restriction restrictions = Restrictions.or(pmRestriction, hkRestriction);
     194          Expression yExpression = Dynamic.rawData("mean");
     195         
     196          List<BioAssay> bioassays = bioassayQuery.list(dc);
     197//          if (bioassays.size() > 6 && bioassays.size() <= 12) width = bioassays.size() * 100;
     198//          else if (bioassays.size() > 12
     199          for (BioAssay ba : bioassays)
     200          {
     201            List<Number> perfectMatchSpots = new ArrayList<Number>();
     202            List<Number> houseKeepingSpots = new ArrayList<Number>();
     203           
     204            // Configure query restrictions and selection
    202205            DynamicSpotQuery query = ba.getSpotData();
     206            query.setAutoJoinType(JoinType.INNER);
    203207            query.restrict(restrictions);
    204             query.select(Selects.expression(BioAssaySetUtil.createJepExpression(dc, bas, columnFormula, false), null));           
    205             for (String filter : filterFormulas)
     208            query.select(Selects.expression(yExpression, meanColumn));
     209            query.select(Selects.expression(Dynamic.reporter("controlGroupId"), restrictionColumn));
     210           
     211            // Work through the iteration result to get the wanted values to plot
     212            DynamicResultIterator result = query.iterate(dc);           
     213            int cgiIndex = result.getIndex(restrictionColumn);
     214            int meanIndex = result.getIndex(meanColumn);
     215            while (result.hasNext())
    206216            {
    207               int listIndex = filterFormulas.indexOf(filterFormulas);
    208               List<Number> spotData = getFilteredSpotData(query.iterate(dc), filter, "controlGroupId");
    209               datasets.get(filter).addValue(Statistics.calculateMean(spotData), series[listIndex], ba.getName());
     217              SqlResult data = result.next();
     218              if (data.getString(cgiIndex).contains(perfectMatch))
     219              {
     220                perfectMatchSpots.add(data.getFloat(meanIndex));
     221              }
     222              if (data.getString(cgiIndex).contains(houseKeeping))
     223              {
     224                houseKeepingSpots.add(data.getFloat(meanIndex));
     225              }
    210226            }
    211           }
     227            pmDataset.addValue(Statistics.calculateMean(perfectMatchSpots), "Perfect match", ba.getName());
     228            houseKeepingDataset.addValue(Statistics.calculateMean(houseKeepingSpots), "Housekeeping", ba.getName());
     229          }
     230         
    212231          NumberAxis axis = new NumberAxis("Signal");
    213232          axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    214           final CategoryItemRenderer renderer = new LineAndShapeRenderer();         
    215           renderer.setSeriesPaint(0, Color.red);
    216           renderer.setSeriesPaint(1, Color.red);
    217               renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
     233          final CategoryItemRenderer renderer1 = new LineAndShapeRenderer();
     234          final CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
     235         
     236          renderer1.setSeriesPaint(0, Color.red);
     237          renderer2.setSeriesPaint(0, Color.blue);
     238              renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    218239             
    219               CategoryPlot plot = new CategoryPlot(null, null, axis, renderer);
    220               for (String filter : filterFormulas)
    221               {
    222                 plot.setDataset(filterFormulas.indexOf(filter), datasets.get(filter));
    223               }
    224          
     240              CategoryPlot subplot1 = new CategoryPlot(pmDataset, null, axis, renderer1);
     241              subplot1.setRenderer(0, renderer1);
     242              subplot1.setRenderer(1, renderer2);
     243              subplot1.setDataset(1, houseKeepingDataset);
     244         
     245              final CategoryAxis domainAxis = new CategoryAxis("Raw bioassays");
     246              domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
     247              final CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
     248
     249              plot.add(subplot1, 1);             
     250             
    225251              chart = new JFreeChart(
    226252                      null, new Font("SansSerif", Font.BOLD, 12),
     
    406432   */
    407433  private List<Number> getFilteredSpotData(DynamicResultIterator iterator,
    408       String filter, String filterColumn) throws SQLException
    409   {
     434      String filter, String filterColumn)
     435    throws SQLException
     436  {   
    410437    int columnIndex = iterator.getIndex(filterColumn);
    411438    List<Number> filteredSpotData = new ArrayList<Number>();
     
    414441      SqlResult result = iterator.next();
    415442      String controlGroupId = result.getString(columnIndex);
    416       if (controlGroupId.indexOf(filter) > 0) filteredSpotData.add(result.getInt(0));
     443     
    417444    }
    418445    return filteredSpotData;
Note: See TracChangeset for help on using the changeset viewer.