source: trunk/www/analyze/index.jsp @ 1889

Last change on this file since 1889 was 1889, checked in by Gregory Vincic, 17 years ago

Added TableColumn? class

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.9 KB
Line 
1<%-- $Id: index.jsp 1889 2006-02-02 10:18:35Z gregory $
2  ------------------------------------------------------------------
3  BioArray Software Environment (BASE) - http:// base.thep.lu.se/
4  Copyright (C) 2002-2004 Lao Saal, Carl Troein,
5  Johan Vallon-Christersson, Jari Häkkinen, Nicklas Nordborg
6
7  This file is part of BASE.
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
26  @author Nicklas, Gregory
27  @version 2.0
28--%>
29<%@ page
30  import="net.sf.basedb.core.SessionControl"
31  import="net.sf.basedb.core.DbControl"
32  import="net.sf.basedb.core.PluginDefinition"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.User"
35  import="net.sf.basedb.core.Item"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.ItemParameterType"
38  import="net.sf.basedb.core.ItemResultIterator"   
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.SystemItems"
41  import="net.sf.basedb.core.Permission"
42  import="net.sf.basedb.core.Experiment"
43  import="net.sf.basedb.core.BioAssaySet"
44  import="net.sf.basedb.core.DynamicResultIterator"
45  import="net.sf.basedb.core.DynamicSpotQuery"
46  import="net.sf.basedb.core.VirtualColumn"
47  import="net.sf.basedb.core.BioAssay"
48  import="net.sf.basedb.core.Transformation"
49  import="net.sf.basedb.core.Job"
50  import="net.sf.basedb.core.query.SqlResult"
51  import="net.sf.basedb.core.query.Hql"
52  import="net.sf.basedb.core.query.Expressions"
53  import="net.sf.basedb.core.query.Restrictions"
54  import="net.sf.basedb.core.query.Dynamic"
55  import="net.sf.basedb.core.query.JoinType"
56  import="net.sf.basedb.core.RawBioAssay"
57  import="net.sf.basedb.core.RawDataType"
58  import="net.sf.basedb.core.RawDataTypes"
59  import="net.sf.basedb.core.ItemQuery"
60  import="net.sf.basedb.core.PermissionDeniedException"
61  import="net.sf.basedb.core.InvalidDataException"
62  import="net.sf.basedb.core.BaseException"
63  import="net.sf.basedb.clients.web.Base"
64  import="net.sf.basedb.clients.web.taglib.table.TableColumn"
65  import="net.sf.basedb.clients.web.util.HTML"
66  import="net.sf.basedb.clients.web.util.Values"
67  import="net.sf.basedb.clients.web.WebException"
68  import="net.sf.basedb.clients.web.ModeInfo"
69  import="java.util.LinkedList"
70  import="java.util.List"
71  import="java.lang.reflect.Array"
72%>
73<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
74<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
75<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
76<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
77
78<%!
79  private static int index = 1;
80
81  private static final ItemContext defaultContext = Base.createDefaultContext("1", "ch1,ch2,externalId");
82 
83  private static String newBioAssaySetRow(BioAssaySet bas, int level)
84  {
85    String row = "<tr class=\"L" + level +"\">";
86    row += "<td class=\"cell\">" + index + "</td>";
87    row += "<td class=\"cell\"><input type=\"checkbox\" name=\"bioassayset_id\" value=\"" + bas.getId() +"\"/></td>";
88    String icon = "bioassayset";
89    if(bas.isRemoved())
90    {
91        icon = "deletedbioassayset";
92    }
93    row += "<td class=\"" + icon + " cell\"><div class=\"link\" onclick=\"viewBioAssaySet(" + bas.getId()+ ")\">" + bas.getName() + "</div></td>";
94   
95    Transformation t = bas.getTransformation();
96    row += "<td class=\"cell\">" + t.getName() + "</td>";
97    row += "<td class=\"cell\">" + bas.getNumSpots() + "</td>";
98    row += "<td class=\"cell\">";
99    Job j = t.getJob();
100    if(j != null) row += Values.formatDate(j.getEnded());
101    row += "</td>";
102    row += "</tr>\n";
103    index++;
104      return row;
105  }
106
107  private static String writeChildTransformations(DbControl dc, BioAssaySet bas, int level)
108  {
109    String output = "";
110    output += newBioAssaySetRow(bas, level);
111    if(!bas.isRemoved())
112    {
113      ItemQuery<Transformation> query = bas.getTransformations();         
114      ItemResultList<Transformation> tList = query.list(dc);
115      for(Transformation t : tList)
116      {
117        ItemQuery<BioAssaySet> basQuery = t.getProducts();
118        basQuery.include( Include.REMOVED );
119        for( BioAssaySet p : basQuery.list(dc))
120        {               
121          output += writeChildTransformations( dc, p, level + 1);
122        }
123      }
124    }
125    return output;
126  }
127
128  private static LinkedList<BioAssaySet> getSelectedItems(DbControl dc, String[] bioassaySetIdList)
129  {
130    LinkedList<BioAssaySet> basList = new LinkedList<BioAssaySet>();
131   
132    if( bioassaySetIdList != null && Array.getLength(bioassaySetIdList) > 0 )
133    {
134      for( String bioassayId : bioassaySetIdList)
135      {     
136        basList.add(BioAssaySet.getById(dc, Integer.decode(bioassayId).intValue()));     
137      }     
138    }
139    return basList;
140  }
141 
142%>
143
144<%
145/* Experiment */
146final Item itemType = Item.EXPERIMENT;
147final int experimentId = Values.getInt(request.getParameter("experiment_id"), 0);
148
149/* Session */
150final SessionControl sc = experimentId == 0 ? 
151    Base.getExistingSessionControl(pageContext, Permission.CREATE, itemType) :
152    Base.getExistingSessionControl(pageContext, true);
153final String ID = sc.getId();
154
155/* Action and Template */
156final String cmd = Values.getString(request.getParameter("cmd"), "");
157final String tabId = Values.getString(request.getParameter("tabId"), "properties");
158final float scale = Base.getScale(sc);
159final String root = request.getContextPath()+"/";
160final String root_img = request.getContextPath()+"/images/treeline/";
161
162/* BioAssaySet */
163final int itemId = Values.getInt(request.getParameter("item_id"), 0);
164BioAssaySet bas = null;
165
166/* BioAssay */
167final Item basType = Item.BIOASSAY;
168final int bioassayId = Values.getInt(request.getParameter("bioassay_id"), 0);
169final ItemContext cc = Base.getAndSetCurrentContext(sc, basType, pageContext, defaultContext);
170final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
171
172/* Command validation */
173DbControl dc = sc.newDbControl();
174try
175{
176  boolean currentBioassaysetWritePermission = false;
177
178  if( cmd.equals("RunPlugin") )
179  {
180    /* Set ItemContext to BioAssaySet and set it's id*/
181    ItemContext ic = sc.getCurrentContext(Item.BIOASSAYSET);
182    bas = BioAssaySet.getById(dc,itemId);
183   
184    if( bas != null )
185    {
186      ic.setId( bas.getId() );
187      response.sendRedirect( root + "common/plugin/index.jsp?ID=" + ID + "&cmd=SelectPlugin&main_type=ANALYZE&item_type=BIOASSAYSET&context_type=ITEM&title=New job");
188    }
189    else
190    {
191      /* No bioassaysets where selected */
192      throw new WebException("popup", "BioAssaySet is null", "BioAssaySet with id " + itemId + " doesn't exsist");
193    }
194  } 
195  else if( cmd.equals("DeleteItems") || cmd.equals("RestoreItems"))
196  {
197    LinkedList<BioAssaySet> basList = getSelectedItems(dc, request.getParameterValues("bioassayset_id"));
198    boolean removedFlag = cmd.equals("DeleteItems") ? true : false;
199    if( basList.size() > 0 )
200    {     
201      for(BioAssaySet b : basList)
202      {       
203        b.setRemoved(removedFlag);     
204      }
205      dc.commit();
206      dc = sc.newDbControl();           
207    }
208    else
209    {
210      /* No bioassaysets where selected */
211      throw new WebException("popup","No items selected", "Please select at least one bioassayset");
212    }   
213  }
214 
215 
216  /* BioAssaySet */
217  if(itemId != 0)
218  {
219    bas = BioAssaySet.getById(dc,itemId);
220    currentBioassaysetWritePermission = bas.hasPermission(Permission.WRITE);
221  }
222 
223  /* Experiment */
224  Experiment experiment = Experiment.getById(dc, experimentId);
225  final boolean writePermission = experiment.hasPermission(Permission.WRITE);
226   
227  boolean readCurrentOwner = true;
228  User currentOwner = null;
229  try
230  {
231    currentOwner = experiment.getOwner();
232  }
233  catch (PermissionDeniedException ex)
234  {
235    readCurrentOwner = false;
236  }
237  %>
238
239  <base:page title="<%=null%>">
240  <base:head scripts="table.js,treeline.js,tabcontrol.js" styles="toolbar.css,headertabcontrol.css,path.css,table.css,treeline.jsp">
241    <title>Experiment Analysis -- <%=HTML.encodeTags(experiment.getName())%></title>
242 
243  <script language="JavaScript">
244    var submitPage = 'index.jsp';
245    var formId = 'bioassaysets';
246   
247    function viewExperiment()
248    {
249      Main.openPopup('<%=root%>/views/experiments/index.jsp?ID=<%=ID%>&item_id=<%=experimentId%>&cmd=ViewItem', 'CreateRootBioAssaySet', 800, 500);
250    }
251    function newRootBioAssaySet()
252    {
253      Main.openPopup('create_root_bioassayset.jsp?ID=<%=ID%>&experiment_id=<%=experimentId%>', 'CreateRootBioAssaySet', 600, 400);
254    }
255    function viewBioAssaySet(itemId)
256    {
257      location.replace('index.jsp?ID=<%=ID%>&experiment_id=<%=experimentId%>&item_id=' + itemId);
258    }
259    function deleteItems()
260    {
261      var frm = document.forms[formId];
262      frm.action = submitPage;
263      frm.cmd.value = 'DeleteItems';
264      frm.submit();
265    }
266    function restoreItems()
267    {
268      var frm = document.forms[formId];
269      frm.action = submitPage;
270      frm.cmd.value = 'RestoreItems';
271      frm.submit();
272    }
273    function createChildCopy()
274    {
275      var frm = document.forms[formId];
276      frm.action = submitPage;
277      frm.cmd.value = 'CreateChildCopy';
278      frm.submit();
279    }
280    function runPlugin()
281    {
282      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=RunPlugin&item_id=<%=itemId%>&experiment_id=<%=experimentId%>', 'SelectPlugin', 600, 600);       
283    }
284    function switchTab(tabControlId, tabId)
285    {
286      TabControl.setActiveTab(tabControlId, tabId);       
287    }
288  </script>
289
290  <script type="text/javascript" language="javascript1.2">
291    <!-- TreeLine configuration -->
292    COL = 2; <!-- which column contains the title -->
293  </script>
294  </base:head>
295  <base:body>
296
297    <p>
298    <p:path>
299      <p:pathelement title="Experiments" href="<%=root + "views/experiments/index.jsp?ID=" +ID +"&experiment_id=" + experimentId + "&cmd=List"%>" />
300      <p:pathelement title="<%=HTML.encodeTags(experiment.getName())%>" href="<%="index.jsp?ID=" +ID +"&experiment_id=" + experimentId%>" />
301      <%if(bas != null) {%> 
302        <p:pathelement title="<%=HTML.encodeTags(bas.getName())%>" />
303      <%}%>     
304    </p:path>
305 
306    <%if(bas != null) {%> 
307    <br clear="all"/>
308    <t:tabcontrol id="main" active="<%=tabId%>" switch="switchTab">
309   
310    <t:tab id="properties" title="Properties">   
311      <tbl:toolbar
312        > 
313
314        <tbl:button 
315          disabled="<%=bas.isRemoved() ? true : false%>" 
316          image="<%=currentBioassaysetWritePermission ? "" : ""%>" 
317          onclick="runPlugin()" 
318          title="Run plugin&hellip;" 
319          tooltip="<%=currentBioassaysetWritePermission ? "Run plugin" : "You do not have permission to analyze this experiment"%>" 
320        /> 
321         
322      </tbl:toolbar>
323       
324    <div class="boxedbottom">
325    <div class="itemstatus">
326    <base:icon image="deleted.gif" 
327      visible="<%=bas.isRemoved()%>"> This item has been flagged for deletion.<br></base:icon>
328      </div>
329         
330    <%
331    Transformation transformation = bas.getTransformation();
332    if(transformation != null) {%>
333      <h4>Transformation</h4>
334      <table>
335      <tr>
336        <th>Name</th>
337        <td><%=HTML.encodeTags(transformation.getName())%></td>
338        </tr>
339        <tr>
340        <th>Description</th>
341        <td><%=HTML.encodeTags(transformation.getDescription())%></td>
342      </tr>
343      </table>
344    <%}%>
345   
346
347    <h4>Experiment</h4>
348    <table>
349    <tr>
350      <th>Name</th>
351      <td><a href="<%=root%>views/experiments/index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=experiment.getId()%>"><%=HTML.encodeTags(experiment.getName())%></a></td>
352      </tr>
353      <tr>
354      <th>Description</th>
355      <td><%=HTML.encodeTags(experiment.getDescription())%></td>
356    </tr>
357    </table>
358    </div>
359    </t:tab>
360   
361    <t:tab id="bioassays" title="Bioassays">
362      <form>
363        <input type="hidden" name="ID" value="<%=ID%>">
364        <input type="hidden" name="experiment_id" value="<%=experimentId%>">
365        <input type="hidden" name="item_id" value="<%=itemId%>">
366        <input type="hidden" name="tabId" value="bioassays">
367        <select name="bioassay_id" onChange="this.form.submit()">
368          <option value="0">Select bioassay</option>
369        <% 
370        ItemQuery<BioAssay> baQuery = bas.getBioAssays();
371        baQuery.include(Include.REMOVED);
372        baQuery.include(Include.OTHERS);
373        ItemResultList<BioAssay> baList = baQuery.list(dc);
374        for(BioAssay ba : baList) {%>
375          <option value="<%=ba.getId()%>" <%=(bioassayId == ba.getId()) ? "selected=selected": ""%>><%=HTML.encodeTags(ba.getName())%>[<%=ba.getNumSpots()%>]</option>
376        <%}%>
377        </select>
378      </form>
379    <% if(bioassayId != 0) {%>
380    <tbl:table 
381      id="expressionData" 
382      clazz="itemlist" 
383      columns="<%=cc.getSetting("columns")%>"
384      sortby="<%=cc.getSortProperty()%>" 
385      direction="<%=cc.getSortDirection()%>"
386      title="Expression data"
387      action="index.jsp"
388      sc="<%=sc%>"
389      item="<%=basType%>"
390      >
391      <tbl:hidden 
392        name="mode" 
393        value="<%=mode.getName()%>" 
394      />
395      <tbl:hidden 
396        name="bioassay_id" 
397        value="<%=""+bioassayId%>" 
398      />
399      <tbl:hidden 
400        name="experiment_id" 
401        value="<%=""+experimentId%>" 
402      />
403      <tbl:hidden 
404        name="item_id" 
405        value="<%=""+itemId%>" 
406      />
407      <tbl:hidden 
408        name="tabId" 
409        value="bioassays" 
410      />
411      <%
412      BioAssay ba = BioAssay.getById(dc,bioassayId);
413      int index = cc.getPage()*cc.getRowsPerPage()+1;
414      DynamicSpotQuery dynQuery = ba.getSpotData();
415     
416      /*
417        $ --> raw data, eg. $x, $y
418        @ --> reporter, eg. @externalId
419        # --> extra value, not implemented
420        % --> channel, eg. %1, %2
421      */
422      List<String> selectionList = new LinkedList<String>();
423      List<TableColumn> cols = new LinkedList<TableColumn>();
424      cols.add( new TableColumn("position", "POSITION", "int", "Position") );
425      cols.add( new TableColumn("ch1", "%1", "float", "Ch 1") );
426      cols.add( new TableColumn("ch2", "%2", "float", "Ch 2") );
427      cols.add( new TableColumn("externalId", "@externalId", "string", "External Id") );
428     
429      for(TableColumn c : cols)
430      {
431        selectionList.add(c.getProperty());
432        %>
433        <tbl:columndef 
434          id="<%=c.getId()%>"
435          property="<%=c.getProperty()%>"
436          datatype="<%=c.getDatatype()%>"
437          title="<%=c.getTitle()%>"
438          sortable="<%=c.getSortable()%>" 
439          filterable="<%=c.getFilterable()%>"
440          exportable="<%=c.getExportable()%>"
441          show="<%=c.getShow()%>" 
442        />
443     
444      <%}
445      cc.configureQuery(dynQuery, selectionList);
446      DynamicResultIterator spots = dynQuery.iterate(dc);
447      %>
448      <tbl:navigator
449        page="<%=cc.getPage()%>" 
450        rowsperpage="<%=cc.getRowsPerPage()%>" 
451        totalrows="<%=spots.getTotalCount()%>" 
452        visible="<%=mode.hasNavigator()%>"
453      />
454      <tbl:data>
455        <tbl:columns>
456          <tbl:presetselector 
457            clazz="columnheader"
458            colspan="3"
459            onchange="presetOnChange()"
460          />
461        </tbl:columns>
462        <tr>         
463        <th colspan="3" class="index">&nbsp;</th>
464         
465          <tbl:propertyfilter />
466        </tr>
467        <tbl:rows>
468          <%
469         
470          int reporter_i = spots.getIndex("externalId");
471          int ch1 = spots.getIndex("ch1");
472          int ch2 = spots.getIndex("ch2");
473          int position_i = spots.getIndex("position");
474          while(spots.hasNext())
475          {
476           
477            SqlResult r = spots.next();
478            %>
479            <tbl:row>
480                <th colspan="3" class="index">&nbsp;</th>
481              <tbl:cell column="externalId"><%=r.getString(reporter_i) == null ? "" : r.getString(reporter_i)%></tbl:cell>
482              <tbl:cell column="ch1"><%=r.getFloat(ch1)%></tbl:cell>
483              <tbl:cell column="ch2"><%=r.getFloat(ch2)%></tbl:cell>
484              <tbl:cell column="position"><%=r.getInt(position_i)%></tbl:cell>
485            </tbl:row>
486          <%
487          index++;
488          }
489          spots.close();
490          %>
491        </tbl:rows>
492      </tbl:data>
493      <tbl:navigator
494        page="<%=cc.getPage()%>" 
495        rowsperpage="<%=cc.getRowsPerPage()%>" 
496        totalrows="<%=spots.getTotalCount()%>" 
497        visible="<%=mode.hasNavigator()%>"
498        locked="true"
499      />
500    </tbl:table>
501    <%}%>
502    </t:tab>
503    </t:tabcontrol>
504    <%}%>
505       
506    <br clear="all"/>
507   
508    <tbl:table 
509      id="bioassaysets" 
510      clazz="itemlist" 
511    >
512      <tbl:hidden 
513        name="experiment_id" 
514        value="<%=String.valueOf(experimentId)%>" 
515      />
516      <tbl:hidden 
517        name="item_id" 
518        value="<%=String.valueOf(itemId)%>" 
519      />
520
521      <tbl:toolbar>
522       
523        <%if(bas == null){%>
524        <tbl:button 
525          disabled="<%=writePermission ? false : true%>" 
526          image="<%=writePermission ? "new.gif" : "new_disabled.gif"%>" 
527          onclick="newRootBioAssaySet()" 
528          title="New root bioassayset&hellip;" 
529          tooltip="<%=writePermission ? "Start a new analysis chain from raw data" : "You do not have permission to analyze this experiment"%>" 
530        />
531        <%}%>
532          <tbl:button 
533          disabled="<%=writePermission ? false : true%>" 
534          image="<%=writePermission ? "delete.gif" : "delete_disabled.gif"%>" 
535          onclick="deleteItems()" 
536          title="Delete&hellip;" 
537          tooltip="<%=writePermission ? "Delete this bioassayset" : "You do not have permission to remove bioassaysets"%>" 
538        /> 
539            <tbl:button 
540          disabled="<%=writePermission ? false : true%>" 
541          image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
542          onclick="restoreItems()" 
543          title="Restore&hellip;" 
544          tooltip="<%=writePermission ? "Restore this bioassayset" : "You do not have permission to restore bioassaysets"%>" 
545        /> 
546                <%/*%>
547          <tbl:button 
548          disabled="<%=writePermission ? false : true%>" 
549          image="<%=writePermission ? "" : ""%>" 
550          onclick="runPlugin()" 
551          title="Run plugin&hellip;" 
552          tooltip="<%=writePermission ? "Run plugin on the selected bioassayset" : "You do not have permission to analyze this experiment"%>" 
553        /><%*/%> 
554         
555      </tbl:toolbar>
556
557      <tr>
558        <td class="data">         
559     
560          <%/* writeTransformations is a recursive method building up the output for BioAssaySets and transformations */
561          index = 1;
562          ItemResultIterator<BioAssaySet> iterator = null;
563          if(bas == null)
564          {
565            ItemQuery<BioAssaySet> basQuery = experiment.getBioAssaySets();
566            basQuery.restrict(
567              Restrictions.eq(
568                  Hql.property("transformation.source"), 
569                  null
570              )
571            );
572            basQuery.include(Include.REMOVED);
573            iterator = basQuery.iterate(dc);
574          }
575         
576          if( bas != null || iterator.hasNext())
577          {%>
578
579            <table id="treeLine" border="0" cellspacing="0" width="100%" cellpadding="0">
580            <tr>
581              <td class="columnheader" width="20">&nbsp;</td>
582              <th class="columnheader" width="20">&nbsp;</th>
583              <td class="columnheader" width="100%" style="text-align: center">BioAssaySet</td>
584              <td class="columnheader" width="100%" style="text-align: right">Transformation</td>
585              <td class="columnheader">Spots</td>
586              <td class="columnheader">Date</td>
587            </tr>
588         
589            <%
590            if(bas != null)
591            {%>
592              <%=writeChildTransformations( dc, bas, 0 )%>
593            <%}
594            else
595            {
596              while(iterator.hasNext())
597              {
598                BioAssaySet b = iterator.next();
599                %>
600                <%=writeChildTransformations( dc, b, 0 )%>
601              <%}%>
602            <%}%> 
603          <%} else {%>
604          <table border="0" cellspacing="0">
605            <tr>
606              <td class="cell">
607                No root bioassay sets where found
608              </td>
609            </tr>
610          </table>
611          <%}%>
612          </table>
613        </td>
614      </tr>
615    </tbl:table>
616    </base:body>
617  </base:page>
618  <%
619}
620finally
621{ 
622  if (dc != null) dc.close();
623}
624%>
Note: See TracBrowser for help on using the repository browser.