source: branches/2.6-stable/www/views/experiments/bioassays/list_bioassays.jsp @ 4215

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

Fixes #984: Bioassays may show up duplicated in list of bioassays

The reason was a LEFT JOIN to the raw parents. This is needed to be able to filter bioassays by experimental factor values.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.7 KB
Line 
1<%-- $Id: list_bioassays.jsp 4215 2008-04-10 11:52:46Z 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 2
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 this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330,
22  Boston, MA  02111-1307, USA.
23  ------------------------------------------------------------------
24
25  @author Nicklas
26  @version 2.0
27--%>
28<%@ page session="false"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Experiment"
34  import="net.sf.basedb.core.BioAssaySet"
35  import="net.sf.basedb.core.BioAssay"
36  import="net.sf.basedb.core.RawBioAssay"
37  import="net.sf.basedb.core.AnnotationSet"
38  import="net.sf.basedb.core.AnnotationType"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultIterator"
41  import="net.sf.basedb.core.ItemResultList"
42  import="net.sf.basedb.core.Permission"
43  import="net.sf.basedb.core.PluginDefinition"
44  import="net.sf.basedb.core.PermissionDeniedException"
45  import="net.sf.basedb.core.RawDataType"
46  import="net.sf.basedb.core.Type"
47  import="net.sf.basedb.core.Include"
48  import="net.sf.basedb.core.query.Restrictions"
49  import="net.sf.basedb.core.query.Expressions"
50  import="net.sf.basedb.core.query.Orders"
51  import="net.sf.basedb.core.query.Hql"
52  import="net.sf.basedb.core.plugin.GuiContext"
53  import="net.sf.basedb.core.plugin.Plugin"
54  import="net.sf.basedb.util.Tree"
55  import="net.sf.basedb.util.Enumeration"
56  import="net.sf.basedb.util.BioAssaySetUtil"
57  import="net.sf.basedb.clients.web.Base"
58  import="net.sf.basedb.clients.web.ModeInfo"
59  import="net.sf.basedb.clients.web.PermissionUtil"
60  import="net.sf.basedb.clients.web.util.HTML"
61  import="net.sf.basedb.util.Values"
62  import="net.sf.basedb.util.formatter.Formatter"
63  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
64  import="java.util.List"
65  import="java.util.LinkedList"
66  import="java.util.Map"
67  import="java.util.HashMap"
68  import="java.util.Iterator"
69  import="java.util.Collection"
70%>
71<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
72<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
73<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
74<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
75<%!
76  private static final Item itemType = Item.BIOASSAY;
77  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
78%>
79<%
80final int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id"));
81final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
82final String ID = sc.getId();
83final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
84
85final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
86final String callback = request.getParameter("callback");
87final String title = mode.generateTitle("bioassay", "bioassays");
88final DbControl dc = sc.newDbControl();
89ItemResultIterator<BioAssay> bioAssays = null;
90ItemResultList<AnnotationType> annotationTypes = null;
91ItemResultList<AnnotationType> experimentalFactors = null;
92try
93{
94  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
95  final BioAssaySet bioAssaySet = BioAssaySet.getById(dc, bioAssaySetId);
96  final Experiment experiment = bioAssaySet.getExperiment();
97  final ItemQuery<AnnotationType> experimentalFactorQuery = experiment.getExperimentalFactors();
98  experimentalFactorQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
99  final int experimentId = experiment.getId();
100  final RawDataType rawDataType = experiment.getRawDataType();
101  final boolean createPermission = experiment.hasPermission(Permission.WRITE);
102  final boolean deletePermission = createPermission;
103  final boolean writePermission = createPermission;
104
105  // Query for raw bioassays related to the current bioassay
106  final ItemQuery<RawBioAssay> rawQuery = RawBioAssay.getQuery();
107  rawQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
108  rawQuery.join(Hql.innerJoin("bioAssays", "bas"));
109  rawQuery.restrict(Restrictions.eq(Hql.alias("bas"), Expressions.parameter("bioAssay"))); 
110  rawQuery.order(Orders.asc(Hql.property("name"))); 
111 
112  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
113  annotationTypes = annotationTypeQuery.list(dc);
114  experimentalFactors = experimentalFactorQuery.list(dc);
115  try
116  {
117    final ItemQuery<BioAssay> query = Base.getConfiguredQuery(cc, true, bioAssaySet.getBioAssays(), mode);
118    query.join(Hql.leftJoin("rawParents", "rba"));
119    query.setDistinct(true);
120    bioAssays = query.iterate(dc);
121  }
122  catch (Throwable t)
123  {
124    t.printStackTrace();
125    cc.setMessage(t.getMessage());
126  }
127  int numListed = 0;
128  %>
129  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
130  <base:head scripts="table.js,tabcontrol.js" styles="table.css,headertabcontrol.css,path.css">
131    <script language="JavaScript">
132    var submitPage = 'index.jsp';
133    var formId = 'bioAssaySets';
134    function editItem(itemId)
135    {
136      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
137    }
138    function viewItem(itemId)
139    {
140      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
141    }
142    function itemOnClick(evt, itemId)
143    {
144      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
145    }
146    function configureColumns()
147    {
148      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
149    }
150    function runPlugin(cmd)
151    {
152      Table.submitToPopup(formId, cmd, 740, 540);
153    }
154    function returnSelected()
155    {
156      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
157      window.close();
158    }
159    function presetOnChange()
160    {
161      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
162    }
163    function switchTab(tabControlId, tabId)
164    {
165      if (tabId == 'properties' || tabId == 'overviewplots' || tabId == 'cfplots' || tabId == 'annotations')
166      {
167        location.href = '../bioassaysets/index.jsp?ID=<%=ID%>&cmd=ViewItem&experiment_id=<%=experiment.getId()%>&item_id=<%=bioAssaySetId%>&tab='+tabId;
168      }
169      else if (tabId == 'spotdata')
170      {
171        location.href = '../spotdata/index.jsp?ID=<%=ID%>&experiment_id=<%=experimentId%>&bioassayset_id=<%=bioAssaySetId%>';
172      }
173      else
174      {
175        TabControl.setActiveTab(tabControlId, tabId);
176      }
177    }
178    function openPlotTool(bioAssayId)
179    {
180      Main.openPopup('../plotter/index.jsp?ID=<%=ID%>&bioassay_id='+bioAssayId, 'Plotter', 1000, 700);
181    }
182    function viewSpotData(bioAssayId)
183    {
184      location.href = '../spotdata/index.jsp?ID=<%=ID%>&bioassay_id='+bioAssayId;
185    }
186    </script>
187  </base:head>
188 
189  <base:body>
190    <p>
191    <%
192    if (!mode.isSelectionMode())
193    {
194      %>
195      <p:path>
196        <p:pathelement title="Experiments" href="<%="../index.jsp?ID="+ID%>" />
197        <p:pathelement title="<%=HTML.encodeTags(experiment.getName())%>" 
198          href="<%="../bioassaysets/index.jsp?ID="+ID+"&experiment_id="+experiment.getId()%>" />
199        <p:pathelement title="<%=HTML.encodeTags(bioAssaySet.getName())%>" />
200      </p:path>
201      <%
202    }
203    %>
204
205    <t:tabcontrol id="main" active="bioassays" switch="switchTab" notabs="<%=mode.isSelectionMode()%>">
206    <t:tab id="properties" title="Properties" />
207   
208    <t:tab id="annotations" title="Annotations" 
209        tooltip="View annotation values" />
210   
211    <t:tab id="bioassays" title="Bioassays">
212    <%
213    if (cc.getMessage() != null)
214    {
215      %>
216      <div class="error"><%=cc.getMessage()%></div>
217      <%
218      cc.setMessage(null);
219    }
220    %>
221    <tbl:table 
222      id="bioAssaySets" 
223      clazz="itemlist" 
224      columns="<%=cc.getSetting("columns")%>"
225      sortby="<%=cc.getSortProperty()%>" 
226      direction="<%=cc.getSortDirection()%>"
227      title="<%=title%>"
228      action="index.jsp"
229      sc="<%=sc%>"
230      item="<%=itemType%>"
231      >
232      <tbl:hidden 
233        name="mode" 
234        value="<%=mode.getName()%>" 
235      />
236      <tbl:hidden 
237        name="bioassayset_id" 
238        value="<%=String.valueOf(bioAssaySetId)%>" 
239      />
240      <tbl:hidden 
241        name="callback" 
242        value="<%=callback%>" 
243        skip="<%=callback == null%>" 
244      />
245      <tbl:columndef 
246        id="name"
247        property="name"
248        datatype="string"
249        title="Name"
250        sortable="true" 
251        filterable="true"
252        exportable="true"
253        show="always" 
254      />
255      <tbl:columndef 
256        id="spots"
257        property="numSpots"
258        datatype="int"
259        title="Spots"
260        sortable="true" 
261        filterable="true"
262        exportable="true"
263      />
264      <tbl:columndef
265        id="rawBioAssays"
266        title="Raw bioassays"
267      />
268      <tbl:columndef 
269        id="description"
270        property="description"
271        datatype="string"
272        title="Description" 
273        sortable="true" 
274        filterable="true" 
275        exportable="true"
276      />
277      <tbl:columndef 
278        id="tools"
279        title="Tools" 
280        show="<%=mode.isSelectionMode() ? "never" : "auto"%>"
281      />
282      <%
283      for (AnnotationType at : annotationTypes)
284      {
285        Enumeration<String, String> annotationEnum = null;
286        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
287        if (at.isEnumeration())
288        {
289          annotationEnum = new Enumeration<String, String>();
290          List<?> values = at.getValues();
291          for (Object value : values)
292          {
293            String encoded = formatter.format(value);
294            annotationEnum.add(encoded, encoded);
295          }
296        }
297        %>
298        <tbl:columndef 
299          id="<%="at"+at.getId()%>"
300          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
301          property="<%="#"+at.getId()%>"
302          annotation="true"
303          datatype="<%=at.getValueType().getStringValue()%>"
304          enumeration="<%=annotationEnum%>"
305          sortable="false" 
306          filterable="true" 
307          exportable="true"
308          formatter="<%=formatter%>"
309        />
310        <%
311      }
312      %>
313      <%
314      for (AnnotationType at : experimentalFactors)
315      {
316        Enumeration<String, String> annotationEnum = null;
317        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
318        if (at.isEnumeration())
319        {
320          annotationEnum = new Enumeration<String, String>();
321          List<?> values = at.getValues();
322          for (Object value : values)
323          {
324            String encoded = formatter.format(value);
325            annotationEnum.add(encoded, encoded);
326          }
327        }
328        %>
329        <tbl:columndef 
330          id="<%="ef"+at.getId()%>"
331          title="<%=HTML.encodeTags(at.getName())+" [EF]"%>" 
332          property="<%="$rba.##"+at.getId()%>"
333          annotation="true"
334          datatype="<%=at.getValueType().getStringValue()%>"
335          enumeration="<%=annotationEnum%>"
336          sortable="false" 
337          filterable="true" 
338          exportable="true"
339          formatter="<%=formatter%>"
340        />
341        <%
342      }
343      %>
344      <tbl:toolbar
345        visible="<%=mode.hasToolbar()%>"
346        >
347        <tbl:button 
348          image="columns.gif" 
349          onclick="configureColumns()" 
350          title="Columns&hellip;" 
351          tooltip="Show, hide and re-order columns" 
352        />
353        <tbl:button 
354          image="import.gif" 
355          onclick="runPlugin('ImportItems')" 
356          title="Import&hellip;" 
357          tooltip="Import data" 
358          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
359        />
360        <tbl:button 
361          image="export.gif" 
362          onclick="runPlugin('ExportItems')" 
363          title="Export&hellip;" 
364          tooltip="Export data" 
365          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
366        />
367        <tbl:button
368          disabled="<%=!createPermission%>"
369          image="<%=createPermission ? "filter.gif" : "filter_disabled.gif"%>"
370          onclick="<%="runPlugin('NewFilteredBioAssaySet')"%>"
371          title="Filter bioassay set&hellip;"
372          tooltip="<%=createPermission ? 
373            "Create a new bioassay set by filtering this bioassayset" :
374            "You do not have permission analyze this experiment"%>"
375          visible="<%=!mode.isSelectionMode()%>"
376        />
377        <tbl:button 
378          image="runplugin.gif" 
379          onclick="runPlugin('RunListPlugin')" 
380          title="Run plugin&hellip;" 
381          tooltip="Run a plugin" 
382          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER) && !mode.isSelectionMode()%>"
383        />
384        <tbl:button 
385          disabled="<%=!createPermission%>"
386          image="<%=createPermission ? "runplugin.gif" : "runplugin_disabled.gif"%>" 
387          onclick="<%="runPlugin('RunListAnalysisPlugin')"%>"
388          title="Run analysis&hellip;" 
389          tooltip="<%=createPermission ? "Run an analysis plugin" : 
390            "You do not have permission to analyze this experiment"%>"
391          visible="<%=pluginCount.containsKey(Plugin.MainType.ANALYZE) && !mode.isSelectionMode()%>"
392        />
393      </tbl:toolbar>
394      <tbl:navigator
395        page="<%=cc.getPage()%>" 
396        rowsperpage="<%=cc.getRowsPerPage()%>" 
397        totalrows="<%=bioAssays == null ? 0 : bioAssays.getTotalCount()%>" 
398        visible="<%=mode.hasNavigator()%>"
399      />
400      <tbl:data>
401        <tbl:columns>
402        <tbl:presetselector 
403          clazz="columnheader"
404          colspan="3"
405          onchange="presetOnChange()"
406        />
407        </tbl:columns>
408        <tr>
409          <tbl:header 
410            clazz="index"
411            >&nbsp;</tbl:header>
412          <tbl:header 
413            clazz="check" 
414            visible="<%=mode.hasCheck()%>"
415            ><base:icon 
416              image="check_uncheck.gif" 
417              tooltip="Check/uncheck all" 
418              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
419            /></tbl:header>
420          <tbl:header 
421            clazz="check" 
422            visible="<%=mode.hasRadio()%>"
423            />
424          <tbl:header 
425            clazz="icons" 
426            visible="<%=mode.hasIcons()%>"
427            >&nbsp;</tbl:header>
428          <tbl:propertyfilter />
429        </tr>
430   
431          <tbl:rows>
432          <%
433          int index = cc.getPage()*cc.getRowsPerPage();
434          int selectedItemId = cc.getId();
435          if (bioAssays != null)
436          {           
437            while (bioAssays.hasNext())
438            {
439              BioAssay item = bioAssays.next();
440              int itemId = item.getId();
441              String name = HTML.encodeTags(item.getName());
442              String tooltip = mode.isSelectionMode() ?
443                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
444              index++;
445              numListed++;         
446              %>
447              <tbl:row>
448                <tbl:header 
449                  clazz="index"
450                  ><%=index%></tbl:header>
451                <tbl:header 
452                  clazz="check" 
453                  visible="<%=mode.hasCheck()%>"
454                  ><input 
455                      type="checkbox" 
456                      name="<%=itemId%>" 
457                      value="<%=itemId%>" 
458                      title="<%=name%>" 
459                      <%=cc.getSelected().contains(itemId) ? "checked" : ""%>
460                    ></tbl:header>
461                <tbl:header 
462                  clazz="check" 
463                  visible="<%=mode.hasRadio()%>"
464                  ><input 
465                      type="radio" 
466                      name="item_id" 
467                      value="<%=itemId%>" 
468                      title="<%=name%>" 
469                      <%=selectedItemId == itemId ? "checked" : ""%>
470                    ></tbl:header>
471                <tbl:header 
472                  clazz="icons" 
473                  visible="<%=mode.hasIcons()%>"
474                  >&nbsp;</tbl:header>
475                <tbl:cell column="name"><div class="link" 
476                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
477                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
478                <tbl:cell column="spots"><%=item.getNumSpots()%></tbl:cell>
479                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
480                <tbl:cell column="rawBioAssays">
481                  <%
482                  rawQuery.setParameter("bioAssay", itemId, Type.INT);
483                  try
484                  {
485                    String separator = "";
486                    for (RawBioAssay rba : rawQuery.list(dc))
487                    {
488                      out.write(separator);
489                      if (mode.hasPropertyLink())
490                      {
491                        out.write(Base.getLinkedName(ID, rba, false, mode.hasEditLink()));
492                      }
493                      else
494                      {
495                        out.write(HTML.encodeTags(rba.getName()));
496                      }
497                      separator = ", ";
498                    }
499                  }
500                  catch (Throwable t)
501                  {
502                    %>
503                    <div class="error"><%=t.getMessage()%></div>
504                    <%
505                  }
506                  %>
507                </tbl:cell>
508                <%
509                AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
510                if (as != null)
511                {
512                  for (AnnotationType at : annotationTypes)
513                  {
514                    if (as.hasAnnotation(at))
515                    {
516                      %>
517                      <tbl:cell column="<%="at"+at.getId()%>"
518                        ><tbl:cellvalue 
519                        list="<%=as.getAnnotation(at).getValues()%>" 
520                      /></tbl:cell>
521                      <%
522                    }
523                  }
524                }
525                for (AnnotationType at : experimentalFactors)
526                {
527                  %>
528                  <tbl:cell column="<%="ef"+at.getId()%>"
529                    ><tbl:cellvalue
530                    list="<%=BioAssaySetUtil.getAnnotationValues(dc, item, at)%>"
531                  /></tbl:cell>
532                  <%
533                }               
534                %>
535                <tbl:cell column="tools">
536                  <nobr>
537                  <a href="javascript:openPlotTool(<%=itemId%>)" 
538                    title="A simple plot tool"><img 
539                    src="../../../images/plotter.gif" border="0"></a>
540                  <a href="javascript:viewSpotData(<%=itemId%>)"
541                    title="View spot data as a table"><img 
542                    src="../../../images/table.gif" border="0"></a>
543                  </nobr>
544                </tbl:cell>
545              </tbl:row>
546              <%
547            }
548          }
549          %>
550          </tbl:rows>
551        </tbl:data>
552      <%
553      if (numListed == 0)
554      {
555        %>
556        <tbl:panel><%=bioAssays == null || bioAssays.getTotalCount() == 0 ? "No bioassays were found" : "No bioassays on this page. Please select another page!" %></tbl:panel>
557        <%
558      }
559      else
560      {
561        %>
562        <tbl:navigator
563          page="<%=cc.getPage()%>" 
564          rowsperpage="<%=cc.getRowsPerPage()%>" 
565          totalrows="<%=bioAssays == null ? 0 : bioAssays.getTotalCount()%>" 
566          visible="<%=mode.hasNavigator()%>"
567          locked="true"
568        />
569        <%
570      }
571      %>
572
573    </tbl:table>
574    <base:buttongroup align="center" clazz="fixedatbottom">
575      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
576      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
577      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
578    </base:buttongroup>
579    </t:tab>
580   
581    <t:tab id="spotdata" title="Spot data" />
582   
583    <t:tab id="overviewplots" title="Overview plots" 
584      visible="<%=rawDataType.getChannels() == 2%>" />
585     
586    <t:tab id="cfplots" title="Correction factor plots" 
587      visible="<%=rawDataType.getChannels() == 2 && bioAssaySet.getTransformation().getSource() != null %>" />
588   
589    </t:tabcontrol>
590
591  </base:body>
592  </base:page>
593  <%
594}
595finally
596{
597  if (bioAssays != null) bioAssays.close();
598  if (dc != null) dc.close();
599}
600%>
Note: See TracBrowser for help on using the repository browser.