source: branches/filedb/www/views/experiments/edit_experiment.jsp @ 3814

Last change on this file since 3814 was 3814, checked in by Nicklas Nordborg, 16 years ago

References #721: Store data in files instead of in the database

  • Experiments are now aware of file-only raw data types
  • Fixed test programs
  • A few remaining Affymetrix issues


  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 20.1 KB
Line 
1<%-- $Id: edit_experiment.jsp 3814 2007-10-10 12:57:07Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg, Martin Svensson
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
26  @author Nicklas
27  @version 2.0
28--%>
29<%@ page session="false"
30  import="net.sf.basedb.core.SessionControl"
31  import="net.sf.basedb.core.DbControl"
32  import="net.sf.basedb.core.Item"
33  import="net.sf.basedb.core.ItemContext"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.Experiment"
36  import="net.sf.basedb.core.RawBioAssay"
37  import="net.sf.basedb.core.AnnotationType"
38  import="net.sf.basedb.core.RawDataType"
39  import="net.sf.basedb.core.RawDataTypes"
40  import="net.sf.basedb.core.Directory"
41  import="net.sf.basedb.core.ItemQuery"
42  import="net.sf.basedb.core.ItemResultList"
43  import="net.sf.basedb.core.Include"
44  import="net.sf.basedb.core.Type"
45  import="net.sf.basedb.core.query.Restrictions"
46  import="net.sf.basedb.core.query.Expressions"
47  import="net.sf.basedb.core.query.Orders"
48  import="net.sf.basedb.core.query.Hql"
49  import="net.sf.basedb.core.PermissionDeniedException"
50  import="net.sf.basedb.core.BaseException"
51  import="net.sf.basedb.core.Project"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.WebException"
54  import="net.sf.basedb.clients.web.util.HTML"
55  import="net.sf.basedb.util.Values"
56  import="net.sf.basedb.util.Enumeration"
57  import="net.sf.basedb.util.formatter.Formatter"
58  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
59  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
60  import="java.util.Arrays"
61  import="java.util.Date"
62  import="java.util.List"
63%>
64<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
65<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
66<%
67final Item itemType = Item.EXPERIMENT;
68final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
69final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
70final int itemId = cc.getId();
71final String ID = sc.getId();
72final float scale = Base.getScale(sc);
73final DbControl dc = sc.newDbControl();
74try
75{
76  String title = null;
77  Experiment experiment = null;
78  RawDataType currentRawDataType = null;
79  RawDataType defaultRawDataType = null;
80  ItemQuery<RawBioAssay> rbaQuery = null;
81  ItemQuery<AnnotationType> efQuery = null;
82 
83  boolean readCurrentDirectory = true;
84  Directory currentDirectory = null;
85
86  List<Directory> recentDirectories = (List<Directory>)cc.getRecent(dc, Item.DIRECTORY);
87
88  int activeProjectId = sc.getActiveProjectId();
89  if (activeProjectId > 0)
90  {
91    Project activeProject = Project.getById(dc, activeProjectId);   
92    defaultRawDataType = activeProject.getDefaultRawDataType();
93  } 
94  if (itemId == 0)
95  {
96    title = "Create experiment";
97    currentRawDataType = RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType"));
98    if (currentRawDataType == null)
99    {
100      currentRawDataType = RawDataTypes.getRawDataType(cc.getRecent("RawDataType", 0));
101    }
102    if (cc.getPropertyFilter("directory.name") != null)
103    {
104      currentDirectory = Base.getFirstMatching(dc, Directory.getQuery(), "name", cc.getPropertyFilter("directory.name"));
105    }
106    cc.removeObject("item");
107    String[] selected = request.getParameterValues("rawbioassay_id");
108    if (selected != null)
109    {
110      rbaQuery = RawBioAssay.getQuery();
111      rbaQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("selected")));
112      rbaQuery.setParameter("selected", Arrays.asList(Values.getInt(selected)), Type.INT);
113    }   
114  }
115  else
116  {
117    experiment = Experiment.getById(dc, itemId);
118    rbaQuery = experiment.getRawBioAssays();
119    efQuery = experiment.getExperimentalFactors();
120    cc.setObject("item", experiment);
121    currentRawDataType = experiment.getRawDataType();
122    title = "Edit experiment -- " + HTML.encodeTags(experiment.getName());
123    try
124    {
125      currentDirectory = experiment.getDirectory();
126    }
127    catch (PermissionDeniedException ex)
128    {
129      readCurrentDirectory = false;
130    }
131  }
132  if (experiment != null) experiment.checkPermission(Permission.WRITE);
133 
134  final String clazz = "class=\"text\"";
135  final String requiredClazz = "class=\"text required\"";
136  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
137  String dateFormat = FormatterSettings.getDateFormat(sc);
138  String jsDateFormat = HTML.javaScriptEncode(dateFormat);
139  String htmlDateFormat = HTML.encodeTags(dateFormat);
140  %>
141
142  <base:page type="popup" title="<%=title%>">
143  <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css">
144    <script language="JavaScript">
145    // Validate the "Experiment" tab
146    function validateExperiment()
147    {
148      var frm = document.forms['experiment'];
149      if (Main.trimString(frm.name.value) == '')
150      {
151        alert("You must enter a name");
152        frm.name.focus();
153        return false;
154      }
155      if (frm.rawdatatype)
156      {
157        if (frm.rawdatatype[frm.rawdatatype.selectedIndex].value == '')
158        {
159          alert("You must select a raw data type");
160          frm.rawdatatype.focus();
161          return false;
162        }
163      }
164      return true;
165    }
166   
167    // Validate the "Experimental factors" tab
168    function validateExperimentalFactors()
169    {
170      return true;
171    }
172
173    // Submit the form
174    function saveSettings()
175    {
176      var frm = document.forms['experiment'];
177      if (TabControl.validateActiveTab('settings'))
178      {
179        frm.addedRawBioAssays.value = Link.getActionIds(1, 'R').join(',');
180        frm.removedRawBioAssays.value = Link.getActionIds(-1, 'R').join(',');
181
182        frm.addedAnnotationTypes.value = Link.getActionIds(1, 'A').join(',');
183        frm.removedAnnotationTypes.value = Link.getActionIds(-1, 'A').join(',');
184       
185        frm.submit();
186      }
187    }
188   
189    function addRawBioAssaysOnClick()
190    {
191      var frm = document.forms['experiment'];
192      var ids = Link.getListIds(frm.rawBioAssays, 'R');
193      var excludes = ids.join(',');
194      var rawDataType = <%=experiment == null ? "frm.rawdatatype[frm.rawdatatype.selectedIndex].value" : "'"+currentRawDataType.getId()+"'"%>;
195      var url = '../rawbioassays/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addRawBioAssayCallback';
196      url += "&exclude="+excludes;
197      url += '&filter:STRING:rawDataType='+rawDataType;
198      url += '&filter:BOOLEAN:hasData=true';
199      Main.openPopup(url, 'AddRawBioAssays', 1000, 700);
200    }
201    function addRawBioAssayCallback(rawBioAssayId, name)
202    {
203      var item = Link.getItem('R', rawBioAssayId);
204      if (!item) item = new Item('R', rawBioAssayId, name);
205      Link.addItem(document.forms['experiment'].rawBioAssays, item);
206    }
207    function removeRawBioAssaysOnClick()
208    {
209      Link.removeSelected(document.forms['experiment'].rawBioAssays);
210    }
211   
212    function addAnnotationTypesOnClick()
213    {
214      var frm = document.forms['experiment'];
215      var ids = Link.getListIds(frm.annotationTypes, 'A');
216      var excludes = ids.join(',');
217      var url = '../../admin/annotationtypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addAnnotationTypeCallback';
218      url += "&exclude="+excludes;
219      Main.openPopup(url, 'AddAnnotationTypes', 1000, 700);
220    }
221    function addAnnotationTypeCallback(annotationTypeId, name)
222    {
223      var item = Link.getItem('A', annotationTypeId);
224      if (!item) item = new Item('A', annotationTypeId, name);
225      Link.addItem(document.forms['experiment'].annotationTypes, item);
226    }
227    function removeAnnotationTypesOnClick()
228    {
229      Link.removeSelected(document.forms['experiment'].annotationTypes);
230    }
231    function selectDirectoryOnClick()
232    {
233      var frm = document.forms['experiment'];
234      var url = '../../filemanager/directories/index.jsp?ID=<%=ID%>&mode=selectonedirectory&callback=setDirectoryCallback';
235      if (frm.directory_id.length > 1)
236      {
237        var id = Math.abs(parseInt(frm.directory_id[1].value));       
238        url += '&directory_id='+id;
239      }
240      Main.openPopup(url, 'SelectDirectory', 350, 500);
241    }
242    function setDirectoryCallback(id, name)
243    {
244      var frm = document.forms['experiment'];
245      var list = frm.directory_id;
246      if (list.length < 2 || list[1].value == '0') // >
247      {
248        Forms.addListOption(list, 1, new Option());
249      }
250      list[1].value = id;
251      list[1].text = name;
252      list.selectedIndex = 1;
253    }
254
255    function init()
256    {
257      var frm = document.forms['experiment'];
258      <%
259      if (experiment == null)
260      {
261        %>
262        frm.name.focus();
263        frm.name.select();
264        <%
265      }
266      if (rbaQuery != null)
267      {
268        %>
269        var rawBioAssays = frm.rawBioAssays;
270        <%
271        rbaQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT);
272        rbaQuery.order(Orders.asc(Hql.property("name")));
273        ItemResultList<RawBioAssay> rawBioAssays = rbaQuery.list(dc);
274        for (RawBioAssay rba : rawBioAssays)
275        {
276          RawDataType rbaDataType = rba.getRawDataType();
277          if (currentRawDataType == null) 
278          {
279            currentRawDataType = rbaDataType;
280          }
281          String linkMethod = "addNewItem";
282          if (experiment == null)
283          {
284            linkMethod = "addItem";
285            // Checks for new experiment
286            if (rbaDataType != currentRawDataType)
287            {
288              throw new WebException("popup", "Raw data types doesn't match",
289                "The raw data type of the selected raw bioassays are not the same. " + 
290                "It is not possible to mix raw data types in an experiment.");
291            }
292            else if (!rba.hasData())
293            {
294              throw new WebException("popup", "Raw bioassay has no raw data",
295                "The raw bioassay {1} doesn't have any raw data. It can't be used " +
296                "in an experiment.", rba.getName());
297            }
298          }
299          %>
300          Link.<%=linkMethod%>(rawBioAssays, new Item('R', <%=rba.getId()%>, '<%=HTML.javaScriptEncode(rba.getName())%>'));
301          <%
302        }
303      }
304      if (efQuery != null)
305      {
306        %>
307        var annotationTypes = frm.annotationTypes;
308        <%
309        efQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT);
310        efQuery.order(Orders.asc(Hql.property("name")));
311        ItemResultList<AnnotationType> experimentalFactors = efQuery.list(dc);
312        for (AnnotationType at : experimentalFactors)
313        {
314          %>
315          Link.addNewItem(annotationTypes, new Item('A', <%=at.getId()%>, '<%=HTML.javaScriptEncode(at.getName())%>'));
316          <%
317        }
318      }
319      %>
320    }
321    </script>
322  </base:head>
323  <base:body onload="init()">
324    <p>
325    <form action="index.jsp?ID=<%=ID%>" method="post" name="experiment" onsubmit="return false;">
326    <input type="hidden" name="cmd" value="UpdateItem">
327
328    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
329    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
330      position="bottom" remember="<%=experiment != null%>">
331    <t:tab id="info" title="Experiment" validate="validateExperiment()" helpid="experiment.edit">
332      <table class="form" cellspacing=0>
333      <tr>
334        <td class="prompt">Name</td>
335        <td><input <%=requiredClazz%> type="text" name="name" 
336          value="<%=HTML.encodeTags(experiment == null ? Values.getString(cc.getPropertyValue("name"), "New experiment") : experiment.getName())%>" 
337          size="40" maxlength="<%=Experiment.MAX_NAME_LENGTH%>"></td>
338      </tr>
339     
340      <tr>
341        <td class="prompt">Raw data type</td>
342        <td>
343          <%
344          if (experiment == null)
345          {
346            currentRawDataType = currentRawDataType != null ? 
347              currentRawDataType : defaultRawDataType;
348            Enumeration<RawDataType, String> rawEnumeration = 
349              new Enumeration<RawDataType, String>();
350            for (RawDataType rdt : RawDataTypes.getRawDataTypes())
351            {
352              rawEnumeration.add(rdt, rdt.getName());
353            }
354            for (RawDataType rdt : RawDataTypes.getFileOnlyRawDataTypes())
355            {
356              rawEnumeration.add(rdt, rdt.getName());
357            }
358            rawEnumeration.sortValues();           
359            %>
360            <select name="rawdatatype" class="required unchangeable">
361            <%
362            for (int i = 0; i < rawEnumeration.size(); ++i)
363            {
364              RawDataType rdt = rawEnumeration.getKey(i);
365              String selected = rdt.equals(currentRawDataType) ? "selected" : "";
366              %>
367              <option value="<%=rdt.getId()%>" <%=selected%>><%=HTML.encodeTags(rdt.getName())%>
368              <%
369            }
370            %>
371            </select>
372            <%
373          }
374          else
375          {
376            %>
377            <%=HTML.encodeTags(currentRawDataType.getName())%>
378            <%
379          }
380          %>
381       
382        </td>
383      </tr>
384      <tr>
385        <td class="prompt">Directory</td>
386        <td>
387          <base:select 
388            id="directory_id"
389            clazz="selectionlist"
390            required="false"
391            current="<%=currentDirectory%>"
392            denied="<%=!readCurrentDirectory%>"
393            recent="<%=recentDirectories%>"
394            newitem="<%=experiment == null%>"
395            onselect="selectDirectoryOnClick()"
396          />
397        </td>
398      </tr>
399      <tr valign="top">
400        <td class="prompt">Raw bioassays</td>
401        <td>
402          <table border="0" cellspacing="0" cellpadding="0">
403          <tr valign="top">
404          <td>
405            <select name="rawBioAssays" size="5" multiple style="width: 20em;">
406            </select>
407            <input type="hidden" name="addedRawBioAssays" value="">
408            <input type="hidden" name="removedRawBioAssays" value="">
409          </td>
410          <td>
411            <table border="0">
412            <tr><td width="150"><base:button 
413              onclick="addRawBioAssaysOnClick()" 
414              title="Add&nbsp;raw bioassays&hellip;" 
415              tooltip="Add raw bioassays"
416              /></td></tr>
417            <tr><td width="150"><base:button 
418              onclick="removeRawBioAssaysOnClick()" 
419              title="Remove" 
420              tooltip="Remove the selected raw bioassays"
421            /></td></tr>
422            </table>
423          </td>
424          </tr>
425          </table>
426        </td>
427      </tr>
428      <tr valign=top>
429        <td class="prompt">Description</td>
430        <td nowrap>
431          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
432            ><%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("description") : experiment.getDescription())%></textarea>
433          <a href="javascript:Main.zoom('Description', 'rawbioassay', 'description')"
434            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
435        </td>
436      </tr>
437      </table>
438      <div align=right>
439        &nbsp;<i><base:icon image="required.gif" /> = required information</i>
440        <%if (experiment == null) {%><br>
441        <i><base:icon image="unchangeable.gif" /> = can't be changed later</i>
442        <%}%>
443        </div>
444    </t:tab>
445   
446    <t:tab id="publication" title="Publication"  helpid="experiment.edit.publication">
447      <table class="form" cellspacing=0>
448      <tr>
449        <td class="prompt">PubMedId</td>
450        <td><input <%=clazz%> type="text" name="pubMedId" 
451          value="<%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("pubMedId") : experiment.getPubMedId())%>" 
452          size="40" maxlength="<%=Experiment.MAX_PUBMEDID_LENGTH%>"></td>
453      </tr>
454        <td class="prompt">Title</td>
455        <td nowrap>
456          <textarea <%=clazz%> rows="4" cols="40" name="title" wrap="virtual"
457            ><%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("title") : experiment.getTitle())%></textarea>
458          <a href="javascript:Main.zoom('Title', 'experiment', 'title')"
459            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
460        </td>
461      </tr>
462      <tr>
463        <td class="prompt">Publication date</td>
464        <td>
465          <table border="0" cellspacing="0" cellpadding="0">
466          <tr>
467          <td>
468            <input <%=clazz%> type="text" name="publicationDate" 
469              value="<%=HTML.encodeTags(dateFormatter.format(experiment == null ? 
470                (Date)cc.getPropertyObject("publicationDate") : experiment.getPublicationDate()))%>" 
471              size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>">
472            &nbsp;
473          </td>
474          <td>
475          <base:button 
476            onclick="<%="Dates.selectDate('Publication date', 'experiment', 'publicationDate', null, '"+jsDateFormat+"')"%>"
477            image="calendar.png"
478            title="Calendar&hellip;" 
479            tooltip="Select a date from a calendar" 
480          />
481          </td>
482          </tr>
483          </table>
484        </td>
485      </tr>
486      <tr valign=top>
487        <td class="prompt">Abstract</td>
488        <td nowrap>
489          <textarea <%=clazz%> rows="4" cols="40" name="abstract" wrap="virtual"
490            ><%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("abstract") : experiment.getAbstract())%></textarea>
491          <a href="javascript:Main.zoom('Abstract', 'experiment', 'abstract')"
492            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
493        </td>
494      </tr>
495      <tr valign=top>
496        <td class="prompt">Experiment design</td>
497        <td nowrap>
498          <textarea <%=clazz%> rows="4" cols="40" name="experimentDesign" wrap="virtual"
499            ><%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("experimentDesign") : experiment.getExperimentDesign())%></textarea>
500          <a href="javascript:Main.zoom('Experiment design', 'experiment', 'experimentDesign')"
501            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
502        </td>
503      </tr>
504      <tr valign=top>
505        <td class="prompt">Experiment type</td>
506        <td nowrap>
507          <textarea <%=clazz%> rows="4" cols="40" name="experimentType" wrap="virtual"
508            ><%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("experimentType") : experiment.getExperimentType())%></textarea>
509          <a href="javascript:Main.zoom('Experiment type', 'experiment', 'experimentType')"
510            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
511        </td>
512      </tr>
513      <tr valign=top>
514        <td class="prompt">Affiliations</td>
515        <td nowrap>
516          <textarea <%=clazz%> rows="4" cols="40" name="affiliations" wrap="virtual"
517            ><%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("affiliations") : experiment.getAffiliations())%></textarea>
518          <a href="javascript:Main.zoom('Affiliations', 'experiment', 'affiliations')"
519            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
520        </td>
521      </tr>
522      <tr valign=top>
523        <td class="prompt">Authors</td>
524        <td nowrap>
525          <textarea <%=clazz%> rows="4" cols="40" name="authors" wrap="virtual"
526            ><%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("authors") : experiment.getAuthors())%></textarea>
527          <a href="javascript:Main.zoom('Authors', 'experiment', 'authors')"
528            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
529        </td>
530      </tr>
531      <tr valign=top>
532        <td class="prompt">Publication</td>
533        <td nowrap>
534          <textarea <%=clazz%> rows="4" cols="40" name="publication" wrap="virtual"
535            ><%=HTML.encodeTags(experiment == null ? cc.getPropertyValue("publication") : experiment.getPublication())%></textarea>
536          <a href="javascript:Main.zoom('Publication', 'experiment', 'publication')"
537            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
538        </td>
539      </tr>
540      </table>
541      </t:tab>
542     
543      <t:tab id="experimentalFactors" title="Experimental factors" 
544        validate="validateExperimentalFactors()" helpid="experiment.edit.factors">
545      <table class="form" cellspacing=0>
546
547      <tr valign="top">
548        <td class="prompt">Annotation types</td>
549        <td>
550          <table border="0" cellspacing="0" cellpadding="0">
551          <tr valign="top">
552          <td>
553            <select name="annotationTypes" size="10" multiple style="width: 20em;">
554            </select>
555            <input type="hidden" name="addedAnnotationTypes" value="">
556            <input type="hidden" name="removedAnnotationTypes" value="">
557          </td>
558          <td>
559            <table border="0">
560            <tr><td width="150"><base:button 
561              onclick="addAnnotationTypesOnClick()" 
562              title="Add annotation types&hellip;" 
563              tooltip="Add annotation types"
564              /></td></tr>
565            <tr><td width="150"><base:button 
566              onclick="removeAnnotationTypesOnClick()" 
567              title="Remove" 
568              tooltip="Remove the selected annotation types"
569            /></td></tr>
570            </table>
571          </td>
572          </tr>
573          </table>
574        </td>
575      </tr>
576      </table>
577      </t:tab>
578
579    </t:tabcontrol>
580
581    <table align="center">
582    <tr>
583      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
584      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
585    </tr>
586    </table>
587    </form>
588  </base:body>
589  </base:page>
590  <%
591}
592finally
593{
594  if (dc != null) dc.close();
595}
596%>
Note: See TracBrowser for help on using the repository browser.