plugins/base2/net.sf.basedb.illumina/trunk/src/net/sf/basedb/illumina/extensions/plot/PlotFactory.java

Code
Comments
Other
Rev Date Author Line
1097 28 May 09 martin 1 /**
1097 28 May 09 martin 2   $Id$
1097 28 May 09 martin 3
1097 28 May 09 martin 4   Copyright (C) 2009 Martin Svensson
1097 28 May 09 martin 5
1097 28 May 09 martin 6   This file is part of BASE - BioArray Software Environment.
1097 28 May 09 martin 7   Available at http://base.thep.lu.se/
1097 28 May 09 martin 8
1097 28 May 09 martin 9   BASE is free software; you can redistribute it and/or
1097 28 May 09 martin 10   modify it under the terms of the GNU General Public License
1097 28 May 09 martin 11   as published by the Free Software Foundation; either version 3
1097 28 May 09 martin 12   of the License, or (at your option) any later version.
1097 28 May 09 martin 13
1097 28 May 09 martin 14   BASE is distributed in the hope that it will be useful,
1097 28 May 09 martin 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
1097 28 May 09 martin 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1097 28 May 09 martin 17   GNU General Public License for more details.
1097 28 May 09 martin 18
1097 28 May 09 martin 19   You should have received a copy of the GNU General Public License
1097 28 May 09 martin 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
1097 28 May 09 martin 21 */
1097 28 May 09 martin 22
1097 28 May 09 martin 23 package net.sf.basedb.illumina.extensions.plot;
1097 28 May 09 martin 24
1097 28 May 09 martin 25 import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory;
1133 18 Jun 09 martin 26 import net.sf.basedb.clients.web.extensions.ExtensionsControl;
1097 28 May 09 martin 27 import net.sf.basedb.clients.web.extensions.plot.OverviewPlotAction;
1097 28 May 09 martin 28 import net.sf.basedb.clients.web.extensions.plot.OverviewPlotBean;
1097 28 May 09 martin 29 import net.sf.basedb.clients.web.extensions.plot.PlotGenerator;
1097 28 May 09 martin 30 import net.sf.basedb.clients.web.extensions.plot.PlotGeneratorBean;
1097 28 May 09 martin 31 import net.sf.basedb.core.BioAssaySet;
1141 24 Jun 09 martin 32 import net.sf.basedb.illumina.Illumina;
1135 23 Jun 09 martin 33 import net.sf.basedb.illumina.servlet.IlluminaPlotServlet;
1097 28 May 09 martin 34 import net.sf.basedb.util.Values;
1097 28 May 09 martin 35 import net.sf.basedb.util.extensions.InvokationContext;
1097 28 May 09 martin 36 import net.sf.basedb.util.extensions.xml.PathSetter;
1097 28 May 09 martin 37 import net.sf.basedb.util.extensions.xml.VariableSetter;
1097 28 May 09 martin 38
1097 28 May 09 martin 39
1097 28 May 09 martin 40 /**
1141 24 Jun 09 martin 41    Factory for generating plots for Illumina bead summary data.
1097 28 May 09 martin 42    Plots will only be generated if the bioassay set has any
1097 28 May 09 martin 43    data stored in the database. 
1097 28 May 09 martin 44    <p>
1135 23 Jun 09 martin 45    The image generation
1141 24 Jun 09 martin 46   is handled by the illumina plot servlet: {@link IlluminaPlotServlet}. 
1097 28 May 09 martin 47    
1097 28 May 09 martin 48    @version 1.4
1097 28 May 09 martin 49     @author martin
1097 28 May 09 martin 50     @base.modified $Date$
1097 28 May 09 martin 51  */
1097 28 May 09 martin 52 public class PlotFactory
1097 28 May 09 martin 53   extends AbstractJspActionFactory<OverviewPlotAction>
1097 28 May 09 martin 54 {
1097 28 May 09 martin 55
1135 23 Jun 09 martin 56   private String servletPath = null;
1141 24 Jun 09 martin 57   private int width = 800;
1135 23 Jun 09 martin 58   private int height = 600;
1097 28 May 09 martin 59
1097 28 May 09 martin 60   public PlotFactory()
1097 28 May 09 martin 61   {}
1097 28 May 09 martin 62   
1097 28 May 09 martin 63   @Override
1097 28 May 09 martin 64   public boolean prepareContext(InvokationContext<? super OverviewPlotAction> context) 
1097 28 May 09 martin 65   {
1097 28 May 09 martin 66     BioAssaySet bas = (BioAssaySet)context.getClientContext().getCurrentItem();
1141 24 Jun 09 martin 67     if (bas.getNumSpots() <= 0) return false;
1141 24 Jun 09 martin 68     if (!bas.getRawDataType().equals(Illumina.getBeadSummaryType())) return false;    
1097 28 May 09 martin 69     return super.prepareContext(context);
1097 28 May 09 martin 70   }
1097 28 May 09 martin 71
1097 28 May 09 martin 72   @VariableSetter
1097 28 May 09 martin 73   @PathSetter
1133 18 Jun 09 martin 74   public void setPlotServlet(String servletPath)
1097 28 May 09 martin 75   {
1097 28 May 09 martin 76     this.servletPath = servletPath;
1097 28 May 09 martin 77   }
1097 28 May 09 martin 78   
1097 28 May 09 martin 79   public void setWidth(String width)
1097 28 May 09 martin 80   {
1141 24 Jun 09 martin 81     this.width = Values.getInt(width, 800);
1097 28 May 09 martin 82   }
1097 28 May 09 martin 83   
1097 28 May 09 martin 84   public void setHeight(String height)
1097 28 May 09 martin 85   {
1141 24 Jun 09 martin 86     this.height = Values.getInt(height, 600);
1097 28 May 09 martin 87   }
1133 18 Jun 09 martin 88
1097 28 May 09 martin 89   @Override
1097 28 May 09 martin 90   public OverviewPlotAction[] getActions(
1097 28 May 09 martin 91       InvokationContext<? super OverviewPlotAction> context)
1097 28 May 09 martin 92   {
1097 28 May 09 martin 93     // Get context information
1097 28 May 09 martin 94     String ID = context.getClientContext().getSessionControl().getId();
1141 24 Jun 09 martin 95     String servletName = "net.sf.basedb.illumina.extensions.overviewplots.illuminaPlots";
1141 24 Jun 09 martin 96     servletPath = servletPath == null ? 
1141 24 Jun 09 martin 97         ExtensionsControl.getHomeUrl(servletName) + "/illuminaPlot.servlet" : 
1141 24 Jun 09 martin 98         servletPath;
1097 28 May 09 martin 99     BioAssaySet source = (BioAssaySet)context.getClientContext().getCurrentItem();
1097 28 May 09 martin 100     OverviewPlotAction[] actions = new OverviewPlotAction[1];
1133 18 Jun 09 martin 101         
1135 23 Jun 09 martin 102     StringBuilder urlString = new StringBuilder();
1135 23 Jun 09 martin 103     urlString.append(servletPath + "?ID=" + ID ); 
1141 24 Jun 09 martin 104     urlString.append("&bioassayset_id=" + source.getId());  
1141 24 Jun 09 martin 105     urlString.append("&cache=overview/bioassayset." + source.getId() + "/controlsummaryplot.png");
1135 23 Jun 09 martin 106     
1133 18 Jun 09 martin 107     PlotGeneratorBean overviewPlot = new PlotGeneratorBean();
1133 18 Jun 09 martin 108     overviewPlot.setId("illuminaPlot");
1133 18 Jun 09 martin 109     overviewPlot.setWidth(width);
1133 18 Jun 09 martin 110     overviewPlot.setHeight(height);
1178 20 Oct 09 jari 111     overviewPlot.setTitle("Control summary plot");
1135 23 Jun 09 martin 112     overviewPlot.setUrl(urlString.toString());
1141 24 Jun 09 martin 113     
1141 24 Jun 09 martin 114     // Control summary plot
1141 24 Jun 09 martin 115     OverviewPlotBean overviewBean = new OverviewPlotBean();    
1178 20 Oct 09 jari 116     overviewBean.setTitle("Control summary plot");
1178 20 Oct 09 jari 117     overviewBean.setDescription("Control summary plot for this bioassay set.");
1141 24 Jun 09 martin 118     overviewBean.setId("illuminaPlot");
1141 24 Jun 09 martin 119
1141 24 Jun 09 martin 120     PlotGenerator[] plotGenerators = new PlotGenerator[]{overviewPlot};
1141 24 Jun 09 martin 121     overviewBean.setPlotGenerators(plotGenerators);
1141 24 Jun 09 martin 122     actions[0] = overviewBean;    
1135 23 Jun 09 martin 123         
1097 28 May 09 martin 124     return actions;
1097 28 May 09 martin 125   }
1097 28 May 09 martin 126 }