source: trunk/www/views/experiments/bioassaysets/view_bioassayset.jsp @ 4825

Last change on this file since 4825 was 4825, checked in by Nicklas Nordborg, 15 years ago

References #1262: Overview and correction factor plots should use the static cache

The overview and correction factor plots now use the cache. Unless the cache API changes there is really not much more to do on this ticket.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.3 KB
Line 
1<%-- $Id: view_bioassayset.jsp 4825 2009-03-20 14:41:22Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.Permission"
32  import="net.sf.basedb.core.Experiment"
33  import="net.sf.basedb.core.BioAssaySet"
34  import="net.sf.basedb.core.BioAssay"
35  import="net.sf.basedb.core.Transformation"
36  import="net.sf.basedb.core.Job"
37  import="net.sf.basedb.core.PluginDefinition"
38  import="net.sf.basedb.core.PluginConfiguration"
39  import="net.sf.basedb.core.User"
40  import="net.sf.basedb.core.ItemQuery"
41  import="net.sf.basedb.core.ItemResultList"
42  import="net.sf.basedb.core.Include"
43  import="net.sf.basedb.core.PermissionDeniedException"
44  import="net.sf.basedb.core.PluginDefinition"
45  import="net.sf.basedb.core.ParameterInfo"
46  import="net.sf.basedb.core.RawDataType"
47  import="net.sf.basedb.core.BasicItem"
48  import="net.sf.basedb.core.Nameable"
49  import="net.sf.basedb.core.File"
50  import="net.sf.basedb.core.plugin.GuiContext"
51  import="net.sf.basedb.core.plugin.Plugin"
52  import="net.sf.basedb.core.query.Orders"
53  import="net.sf.basedb.core.query.Hql"
54  import="net.sf.basedb.clients.web.Base"
55  import="net.sf.basedb.clients.web.PermissionUtil"
56  import="net.sf.basedb.clients.web.util.HTML"
57  import="net.sf.basedb.util.Values"
58  import="net.sf.basedb.clients.web.util.NameablePluginAdaptor"
59  import="net.sf.basedb.util.formatter.Formatter"
60  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
61  import="java.util.Date"
62  import="java.util.Map"
63  import="java.util.Set"
64  import="java.util.List"
65%>
66<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
67<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
68<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
69<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
70<%!
71  private static final Item itemType = Item.BIOASSAYSET;
72  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
73%>
74<%
75final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
76final String ID = sc.getId();
77final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
78final int itemId = cc.getId();
79final String tabId = Values.getString(request.getParameter("tab"), "properties");
80
81final float scale = Base.getScale(sc);
82final String root = request.getContextPath();
83final DbControl dc = sc.newDbControl();
84try
85{
86  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
87
88  String title = null;
89  final BioAssaySet bioAssaySet = BioAssaySet.getById(dc, itemId);
90  final Experiment experiment = bioAssaySet.getExperiment();
91  final int experimentId = experiment.getId();
92  final boolean hasDbSpots = bioAssaySet.getNumSpots() > 0;
93  Transformation transformation = bioAssaySet.getTransformation();
94  RawDataType rawDataType = experiment.getRawDataType();
95 
96  Job job = null;
97  boolean readJob = true;
98  PluginDefinition plugin = null;
99  boolean readPlugin = true;
100  PluginConfiguration configuration = null;
101  boolean readConfiguration = true;
102
103  try
104  {
105    job = transformation.getJob();
106  }
107  catch (PermissionDeniedException ex)
108  {
109    readJob = false;
110    readPlugin = false;
111    readConfiguration = false;
112  }
113  if (job != null)
114  {
115    try
116    {
117      plugin = job.getPluginDefinition();
118    }
119    catch (PermissionDeniedException ex)
120    {
121      readPlugin = false;
122    }
123    try
124    {
125      configuration = job.getPluginConfiguration();
126    }
127    catch (PermissionDeniedException ex)
128    {
129      readConfiguration = false;
130    }
131  }
132 
133  final boolean createPermission = experiment.hasPermission(Permission.USE);
134  final boolean writePermission = bioAssaySet.hasPermission(Permission.WRITE);
135  final boolean deletePermission = bioAssaySet.hasPermission(Permission.DELETE);
136  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
137  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
138  %>
139
140  <base:page title="<%=title%>">
141  <base:head scripts="table.js,tabcontrol.js,newjoust.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css,newjoust.css">
142    <script language="JavaScript">
143    function editItem()
144    {
145      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
146    }
147    function deleteItem()
148    {
149      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&experiment_id=<%=experimentId%>&item_id=<%=itemId%>');
150    }
151    function restoreItem()
152    {
153      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&experiment_id=<%=experimentId%>&item_id=<%=itemId%>');
154    }
155    function switchTab(tabControlId, tabId)
156    {
157      if (TabControl.isActive(tabControlId, tabId)) return;
158      if (tabId == 'bioassays')
159      {
160        location.href = '../bioassays/index.jsp?ID=<%=ID%>&experiment_id=<%=experimentId%>&bioassayset_id=<%=itemId%>&tab='+tabId;
161      }
162      else if (tabId == 'spotdata')
163      {
164        location.href = '../spotdata/index.jsp?ID=<%=ID%>&experiment_id=<%=experimentId%>&bioassayset_id=<%=itemId%>';
165      }
166      else if ((tabId == 'overviewplots' || tabId == 'cfplots') && tabId != '<%=tabId%>')
167      {
168        location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&experiment_id=<%=experimentId%>&bioassayset_id=<%=itemId%>&tab='+tabId;
169      }
170      else
171      {
172        TabControl.setActiveTab(tabControlId, tabId);
173      }
174    }
175    function runItemPlugin(cmd)
176    {
177      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&experiment_id=<%=experimentId%>&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
178    }
179    var imageQueue = new Array();
180    var nextImage = 0;
181    function addImage(imageId, url)
182    {
183      imageQueue[imageQueue.length] = imageId;
184      var img = document.getElementById(imageId);
185      img.realSrc = url;
186    }
187    function imageLoaded()
188    {
189      var imageId = imageQueue[nextImage];
190      var img = document.getElementById(imageId);
191      img.src = img.realImg.src;
192      nextImage++;
193      setTimeout('loadNextImage()', 100);
194    }
195    function loadNextImage()
196    {
197      if (imageQueue.length > nextImage)
198      {
199        var imageId = imageQueue[nextImage];
200        var img = document.getElementById(imageId);
201        img.src = '../../../images/plot_generating_400x300.gif';
202        img.realImg = new Image();
203        img.realImg.onload = imageLoaded;
204        img.realImg.src = img.realSrc;
205      }
206    }
207    </script>
208    <style>
209    .plot {
210      border: 1px solid #666666;
211      background-image: url('../../../images/plot_empty_400x300.png');
212    }
213    </style>
214  </base:head>
215  <base:body onload="loadNextImage()">
216    <p>
217    <p:path>
218      <p:pathelement title="Experiments" href="<%="../index.jsp?ID="+ID%>" />
219      <p:pathelement title="<%=HTML.encodeTags(experiment.getName())%>" 
220        href="<%="index.jsp?ID="+ID+"&experiment_id="+experimentId%>" />
221      <p:pathelement title="<%=HTML.encodeTags(bioAssaySet.getName())%>" />
222    </p:path>
223   
224    <t:tabcontrol id="view" active="<%=tabId%>" switch="switchTab" remember="false">
225    <t:tab id="properties" title="Properties">
226   
227    <tbl:toolbar
228      >
229      <tbl:button 
230        disabled="<%=writePermission ? false : true%>" 
231        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
232        onclick="editItem()" 
233        title="Edit&hellip;" 
234        tooltip="<%=writePermission ? "Edit this bioassay set" : "You do not have permission to edit this bioassay set"%>" 
235      />
236      <tbl:button 
237        disabled="<%=deletePermission ? false : true%>" 
238        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
239        onclick="deleteItem()" 
240        title="Delete"
241        visible="<%=!bioAssaySet.isRemoved()%>"
242        tooltip="<%=deletePermission ? "Delete this bioassay set" : "You do not have permission to delete this bioassay set"%>" 
243      />
244      <tbl:button 
245        disabled="<%=writePermission ? false : true%>" 
246        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
247        onclick="restoreItem()" 
248        title="Restore"
249        visible="<%=bioAssaySet.isRemoved()%>"
250        tooltip="<%=writePermission ? "Restore this bioassay set" : "You do not have permission to restore this bioassay set"%>" 
251      />
252      <tbl:button 
253        image="import.gif" 
254        onclick="runItemPlugin('ImportItem')" 
255        title="Import&hellip;" 
256        tooltip="Import data" 
257        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
258      />
259      <tbl:button 
260        image="export.gif" 
261        onclick="runItemPlugin('ExportItem')" 
262        title="Export&hellip;" 
263        tooltip="Export data" 
264        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
265      />
266      <tbl:button
267        image="plotter.gif"
268        onclick="<%="openPlotTool(" + itemId + ")"%>"
269        title="Plot tool&hellip;"
270        tooltip="A simple tool for generating plots"
271        visible="<%=hasDbSpots%>"
272      />
273      <tbl:button
274        image="explorer.png"
275        onclick="<%="openExperimentExplorer(" + itemId + ")"%>"
276        title="Experiment explorer"
277        tooltip="View the data reporter by reporter"
278        visible="<%=hasDbSpots%>"
279      />
280      <tbl:button
281        disabled="<%=!createPermission%>"
282        image="<%=createPermission ? "filter.gif" : "filter_disabled.gif"%>"
283        onclick="<%="filter(" + itemId +")"%>"
284        title="Filter bioassay set&hellip;"
285        tooltip="<%=createPermission ? 
286          "Create a new bioassay set by filtering this bioassayset" :
287          "You do not have permission analyze this experiment"%>"
288        visible="<%=pluginCount.containsKey(Plugin.MainType.ANALYZE)%>"
289      />
290      <tbl:button 
291        image="runplugin.gif" 
292        onclick="runItemPlugin('RunPlugin')"
293        title="Run plugin&hellip;" 
294        tooltip="Run a plugin" 
295        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
296      />
297      <tbl:button 
298        disabled="<%=!createPermission%>"
299        image="<%=createPermission ? "runplugin.gif" : "runplugin_disabled.gif"%>" 
300        onclick="<%="runAnalysisPlugin(" + itemId + ")"%>"
301        title="Run analysis&hellip;" 
302        tooltip="<%=createPermission ? "Run an analysis plugin" : 
303          "You do not have permission to analyze this experiment"%>"
304        visible="<%=pluginCount.containsKey(Plugin.MainType.ANALYZE)%>"
305      />
306      <tbl:button
307        image="help.gif"
308        onclick="<%="Main.openHelp('" + ID +"', 'bioassayset.view.properties')"%>"
309        title="Help&hellip;"
310        tooltip="Get help about this page"
311      />
312      </tbl:toolbar>
313    <div class="boxedbottom">
314      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(bioAssaySet)%></i></div>
315      <%
316      if (bioAssaySet.isRemoved())
317      {
318        %>
319        <div class="itemstatus">
320          <base:icon image="deleted.gif" 
321            visible="<%=bioAssaySet.isRemoved()%>"> This item has been flagged for deletion<br></base:icon>
322        </div>
323        <%
324      }
325      %>
326     
327      <table width="100%">
328      <tr valign="top">
329      <td width="50%">
330        <h4>Bioassay set</h4>
331        <table class="form" cellspacing=0>
332        <tr>
333          <td class="prompt">Name</td>
334          <td><%=HTML.encodeTags(bioAssaySet.getName())%></td>
335        </tr>
336        <tr>
337          <td class="prompt">Experiment</td>
338          <td><%=Base.getLinkedName(ID, experiment, false, writePermission)%>
339          (<%=experiment.getRawDataType()%>)</td>
340        </tr>
341        <tr>
342          <td class="prompt">Spots</td>
343          <td>db: <%=bioAssaySet.getNumSpots()%>; file: <%=bioAssaySet.getNumFileSpots()%></td>
344        </tr>
345        <tr>
346          <td class="prompt">Reporters</td>
347          <td>db: <%=bioAssaySet.getNumReporters()%>; file: <%=bioAssaySet.getNumFileReporters()%></td>
348        </tr>
349        <tr>
350          <td class="prompt">Description</td>
351          <td><%=HTML.niceFormat(bioAssaySet.getDescription())%></td>
352        </tr>
353        </table>
354       
355        <h4>Transformation &amp; job</h4>
356        <table class="form" cellspacing=0>
357        <tr>
358          <td class="prompt">Transformation</td>
359          <td><%=Base.getLinkedName(ID, transformation, false, 
360              transformation.hasPermission(Permission.WRITE))%></td>
361        </tr>
362        <tr>
363          <td class="prompt">Job</td>
364          <td><%=Base.getLinkedName(ID, job, !readJob, false)%></td>
365        </tr>
366        <tr valign=top>
367          <td class="prompt">Started</td>
368          <td>
369            <%=job == null ? "" : dateTimeFormatter.format(job.getStarted())%>
370          </td>
371        </tr>
372        <tr valign=top>
373          <td class="prompt">Ended</td>
374          <td>
375            <%=job == null ? "" : dateTimeFormatter.format(job.getEnded())%>
376          </td>
377        </tr>
378        <tr valign=top>
379          <td class="prompt">Server</td>
380          <td>
381            <%=job == null ? "" : HTML.encodeTags(job.getServer())%>
382          </td>
383        </tr>
384        <tr>
385          <td class="prompt">Description</td>
386          <td><%=HTML.niceFormat(transformation.getDescription())%></td>
387        </tr>
388        </table>
389      </td>
390      <td width="50%">
391        <h4>Plugin &amp; parameters</h4>
392        <table class="form" cellspacing=0>
393        <tr>
394          <td class="prompt">Plugin</td>
395          <td><%=Base.getLinkedName(ID, plugin == null ? null : new NameablePluginAdaptor(plugin), 
396              !readPlugin, plugin != null && plugin.hasPermission(Permission.WRITE))%></td>
397        </tr>
398        <tr>
399          <td class="prompt">Plugin configuration</td>
400          <td><%=Base.getLinkedName(ID, configuration, !readConfiguration, 
401            configuration != null && configuration.hasPermission(Permission.WRITE))%></td>
402        </tr>
403        <%
404        if (job != null)
405        {
406          for (String name : job.getParameterNames())
407          {
408            StringBuilder sb = new StringBuilder();
409            String displayValue = "";
410            String description = "";
411            try
412            {
413              ParameterInfo pi = job.getParameterInfo(name);
414              if (pi.getLabel() != null) name = HTML.encodeTags(pi.getLabel());
415              description = HTML.encodeTags(pi.getDescription());
416              List<?> values = pi.getValues();
417              int i = 0;
418              for (Object value : values)
419              {
420                if (value != null)
421                {
422                  if (i > 0) sb.append(", ");
423                  i++;
424                  if (value instanceof BasicItem)
425                  {
426                    BasicItem item = (BasicItem)value;
427                    String itemName = "";
428                    if (item instanceof File)
429                    {
430                      itemName = ((File)item).getPath().toString();
431                    }
432                    else if (item instanceof Nameable)
433                    {
434                      itemName = ((Nameable)item).getName();
435                    }
436                    else
437                    {
438                      itemName = item.toString();
439                    }
440                    sb.append(Base.getLink(ID, HTML.encodeTags(itemName), 
441                      item.getType(), item.getId(), item.hasPermission(Permission.WRITE)));
442                  }
443                  else if (value instanceof Date)
444                  {
445                    sb.append(dateFormatter.format((Date)value));
446                  }
447                  else
448                  {
449                    sb.append(HTML.encodeTags(value.toString()));
450                  }
451                }
452              }
453              displayValue = sb.toString();
454            }
455            catch (Throwable ex)
456            {
457              displayValue = "<i>ERROR: "+ex.getMessage()+"</i>";
458            }
459            %>
460            <tr>
461            <td class="prompt"><span title="<%=description%>"><%=name%></span></td>
462              <td>
463                <%=displayValue%>
464              </td>
465            </tr>
466            <%
467          }
468        }
469        %>
470        </table>
471
472      </td>
473      </tr>
474      </table>
475     
476      <jsp:include page="../../../common/datafiles/list_files.jsp">
477        <jsp:param name="item_type" value="<%=itemType.name()%>" />
478        <jsp:param name="item_id" value="<%=itemId%>" />
479        <jsp:param name="ID" value="<%=ID%>" />
480      </jsp:include>
481     
482      <p>
483      <h4 class="docked">Analysis subtree</h4>
484      <jsp:include page="analysis_tree.jsp">
485        <jsp:param name="ID" value="<%=ID%>" />
486        <jsp:param name="experiment_id" value="<%=experimentId%>" />
487        <jsp:param name="item_id" value="<%=itemId%>" />
488      </jsp:include>
489      </div>
490      </t:tab>
491     
492      <t:tab id="annotations" title="Annotations" 
493        tooltip="View annotation values">
494        <div class="boxed">
495        <jsp:include page="../../../common/annotations/list_annotations.jsp">
496          <jsp:param name="item_type" value="<%=itemType.name()%>" />
497          <jsp:param name="item_id" value="<%=itemId%>" />
498          <jsp:param name="ID" value="<%=ID%>" />
499        </jsp:include>
500        </div>
501      </t:tab>
502     
503      <t:tab id="bioassays" title="Bioassays" />
504     
505      <t:tab id="spotdata" title="Spot data" 
506        visible="<%=hasDbSpots%>" />
507     
508      <t:tab id="overviewplots" title="Overview plots" 
509        tooltip="MA-plots of each bioassay in this bioassay set"
510        visible="<%=hasDbSpots && rawDataType.getChannels() == 2%>">
511      <%
512      if ("overviewplots".equals(tabId))
513      {
514        String M = HTML.urlEncode("log2(ch(1) / ch(2))");
515        String A = HTML.urlEncode("log(ch(1) * ch(2)) / 2");
516        String xLabel = HTML.urlEncode("A, log10(ch1 * ch2) / 2");
517        String yLabel = HTML.urlEncode("M, log2(ch1 / ch2)");
518        String filter = HTML.urlEncode("ch(1) > 0 && ch(2) > 0");
519        ItemQuery<BioAssay> bioAssayQuery = bioAssaySet.getBioAssays();
520        bioAssayQuery.order(Orders.asc(Hql.property("name")));
521        StringBuilder script = new StringBuilder();
522        for (BioAssay bioAssay : bioAssayQuery.list(dc))
523        {
524          String url = "../plotter/plot?ID="+ID+"&bioassay_id="+bioAssay.getId();
525          url += "&type=scatter&width=400&height=300";
526          url += "&cache=overview/bioassay." + bioAssay.getId() + "/maplot.png";
527          url += "&x="+A+"&y="+M+"&xLabel="+xLabel+"&yLabel="+yLabel;
528          url += "&filter="+filter;
529          url += "&title="+HTML.urlEncode(bioAssay.getName());
530          script.append("addImage('MA").append(bioAssay.getId()).append("','").
531              append(url).append("');\n");
532          %>
533          <img id="MA<%=bioAssay.getId()%>" 
534            src="../../../images/transparent_pixel.gif" 
535            width="400" height="300"
536            alt="MA-plot for bioassay <%=HTML.encodeTags(bioAssay.getName())%>"
537            class="plot"
538            >
539          <%
540        }
541        %>
542        <script language="JavaScript">
543        <%=script%>
544        </script>
545        <%
546      }
547      %>
548      </t:tab>
549     
550      <t:tab id="cfplots" title="Correction factor plots" 
551        tooltip="MA-plot of the parent bioassays together with a correction factor for each spot in the current bioassayset."
552        visible="<%=hasDbSpots && rawDataType.getChannels() == 2 && bioAssaySet.getTransformation().getSource() != null %>">
553      <%
554      if ("cfplots".equals(tabId))
555      {
556        ItemQuery<BioAssay> bioAssayQuery = bioAssaySet.getBioAssays();
557        bioAssayQuery.order(Orders.asc(Hql.property("name")));
558        String xLabel = HTML.urlEncode("A, log10(ch1 * ch2) / 2");
559        String yLabel = HTML.urlEncode("M, log2(ch1 / ch2)");
560        StringBuilder script = new StringBuilder();
561        for (BioAssay bioAssay : bioAssayQuery.list(dc))
562        {
563          String url = "../plotter/plot?ID="+ID+"&bioassay_id="+bioAssay.getId();
564          url += "&type=cfplot&width=400&height=300";
565          url += "&cache=overview/bioassay." + bioAssay.getId() + "/cfplot.png";
566          url += "&xLabel="+xLabel+"&yLabel="+yLabel;
567          url += "&title="+HTML.urlEncode(bioAssay.getName());
568          script.append("addImage('CF").append(bioAssay.getId()).append("','").
569          append(url).append("');\n");
570          %>
571          <img id="CF<%=bioAssay.getId()%>" 
572            src="../../../images/transparent_pixel.gif" 
573            width="400" height="300"
574            alt="Correction factor plot for bioassay <%=HTML.encodeTags(bioAssay.getName())%>"
575            class="plot"
576            >
577          <%
578        }
579        %>
580        <script language="JavaScript">
581        <%=script%>
582        </script>
583        <%
584      }
585      %>
586      </t:tab>
587
588      </t:tabcontrol>
589
590  </base:body>
591  </base:page>
592  <%
593}
594finally
595{
596  if (dc != null) dc.close();
597}
598
599%>
Note: See TracBrowser for help on using the repository browser.