Changeset 4630


Ignore:
Timestamp:
Nov 7, 2008, 9:36:37 AM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1133: Experimental factors - inherit annotations

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/AnnotationSet.java

    r4517 r4630  
    2323package net.sf.basedb.core;
    2424
     25import java.util.Collections;
    2526import java.util.LinkedList;
    2627import java.util.List;
     
    3738import net.sf.basedb.core.data.AnnotationSetData;
    3839import net.sf.basedb.core.data.AnnotationTypeData;
     40import net.sf.basedb.util.AnnotationUtil;
     41import net.sf.basedb.util.filter.Filter;
    3942
    4043/**
     
    220223    throws PermissionDeniedException, BaseException
    221224  {
     225    return getItem(null);
     226  }
     227 
     228  /**
     229    Get the item this annotation set belongs to using a specific
     230    DbControl for database access. If the item has already been loaded
     231    it is re-loaded by the given DbControl.
     232   
     233    @param dc An open DbControl, or null to use the current DbControl associated
     234      with this annotation set
     235    @return The <code>Annotatable</code> item
     236    @since 2.9
     237  */
     238  public Annotatable getItem(DbControl dc)
     239    throws PermissionDeniedException, BaseException
     240  {
    222241    if (item == null)
    223242    {
     243      if (dc == null) dc = getDbControl();
    224244      Item type = getItemType();
    225       DbControl dc = getDbControl();
    226245      String hql = "SELECT item"+
    227246        " FROM "+type.getDataClass().getName()+" item"+
     
    230249      query.setEntity("annotationSet", this.getData());
    231250      item = (Annotatable)dc.getItem(type.getItemClass(), HibernateUtil.loadData(type.getDataClass(), query));
     251    }
     252    else if (dc != null)
     253    {
     254      item = (Annotatable)getItemType().getById(dc, item.getId());
    232255    }
    233256    return item;
     
    355378  {
    356379    if (annotationType == null) throw new InvalidUseOfNullException("annotationType");
     380    if (!isInDatabase()) return Collections.emptyList();
    357381    // List for storing the result
    358382    List<Annotation> annotations = new LinkedList<Annotation>();
     
    612636  }
    613637
     638  /**
     639    Automatically inherit all annotations of the specified annotation
     640    type from parent items unless this annotation set already contains
     641    an annotation of the specified type.
     642    <p>
     643    This method will only consider parent items that the logged in user
     644    has access to with USE permission.
     645    <p>
     646    This method may result in inheriting multiple annotations (from different
     647    parent items) of the specified annotation type.
     648   
     649    @param dc The DbControl to use for database access
     650    @param annotationType The annotation type to look for
     651    @param preferAnnotationSet If TRUE, the entire annotation set containing the
     652      found annotation is inherited, otherwise only the found annotation is inherited
     653    @since 2.9
     654  */
     655  public int autoInherit(DbControl dc, final AnnotationType annotationType, boolean preferAnnotationSet)
     656  {
     657    if (findAnnotations(dc, annotationType, null).size() > 0) return 0;
     658    int numInherited = 0;
     659    Annotatable item = getItem(dc);
     660   
     661    // Filter that only returns items that are annotated with the specified
     662    // annotation type and for which the logged in user has USE permission
     663    Filter<Annotatable> filter = new Filter<Annotatable>()
     664    {
     665      @Override
     666      public boolean evaluate(Annotatable a)
     667      {
     668        return a.isAnnotated() &&
     669          a.hasPermission(Permission.USE) &&
     670          a.getAnnotationSet().hasAnnotation(annotationType);
     671      }
     672    };
     673   
     674    // This will find all parent items that we should inherit from
     675    Set<Annotatable> allParents = AnnotationUtil.getAllAnnotatableParentItems(dc, item, filter);
     676    for (Annotatable parent : allParents)
     677    {
     678      AnnotationSet pas = parent.getAnnotationSet();
     679      numInherited++;
     680      if (preferAnnotationSet)
     681      {
     682        inheritAnnotationSet(pas);
     683      }
     684      else
     685      {
     686        inheritAnnotation(pas.getAnnotation(annotationType));
     687      }
     688    }
     689    return numInherited;
     690  }
     691 
    614692  /**
    615693    Copy annotations from another annotatable item to this annotation set.
  • trunk/www/views/experiments/index.jsp

    r4619 r4630  
    341341    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
    342342  }
     343  else if ("AutoInherit".equals(cmd))
     344  {
     345    // Display the edit page for a single item (should be opened in a popup)
     346    dc = sc.newDbControl();
     347    Experiment exp = Experiment.getById(dc, Values.getInt(itemId));
     348    AnnotationType at = AnnotationType.getById(dc, Values.getInt(request.getParameter("annotationtype_id")));
     349    ItemQuery<RawBioAssay> query = exp.getRawBioAssays();
     350    query.include(Include.ALL);
     351    query.setItemPermission(Permission.WRITE);
     352    int numInherited = 0;
     353    int numRawBioAssays = 0;
     354    for (RawBioAssay rba : query.list(dc))
     355    {
     356      numRawBioAssays++;
     357      numInherited += rba.getAnnotationSet().autoInherit(dc, at, false);
     358    }
     359    dc.commit();
     360    message = numInherited + " annotation(s) inherited by " + numRawBioAssays + " raw bioassay(s)";
     361  }
    343362  else
    344363  {
  • trunk/www/views/experiments/view_experiment.jsp

    r4619 r4630  
    103103  Map<AnnotationType, Set<Object>> usedFactorValues =
    104104    new HashMap<AnnotationType, Set<Object>>();
     105  Map<AnnotationType, Integer> factorValuesCount = new HashMap<AnnotationType, Integer>();
    105106  %>
    106107
     
    193194      var div = document.getElementById('usedvalues.'+annotationTypeId);
    194195      div.innerHTML = values;
     196    }
     197    function showStatus(annotationTypeId, numTotal, numInherited)
     198    {
     199      var sss = document.getElementById('status.'+annotationTypeId);
     200      var html;
     201      if (numTotal == numInherited)
     202      {
     203        html = '<img src="../../images/ok.gif" title="All ' + numTotal +
     204          ' raw bioassays have a value for this experimental factor">';
     205      }
     206      else
     207      {
     208        var numMissing = numTotal - numInherited;
     209        html = '<a href="javascript:autoInherit('+annotationTypeId+')"' +
     210          ' title="Click for automatic inheritation of annotations from parents"';
     211        html += '<img src="../../images/warning.gif" border="0">&nbsp;' + numMissing + ' missing</a>';
     212      }
     213      sss.innerHTML = html;
     214    }
     215    function autoInherit(annotationTypeId)
     216    {
     217      var url = 'index.jsp?ID=<%=ID%>&cmd=AutoInherit&item_id=<%=itemId%>&annotationtype_id=' + annotationTypeId;
     218      Main.openPopup(url, 'AutoInherit', 400, 200);
    195219    }
    196220    </script>
     
    424448          title="Description"
    425449        />
     450        <tbl:columndef
     451          id="status"
     452          title="Status"
     453        />
    426454        <tbl:data>
    427455          <tbl:columns>
     
    433461            Type valueType = item.getValueType();
    434462            usedFactorValues.put(item, new HashSet<Object>());
     463            factorValuesCount.put(item, 0);
    435464            Formatter formatter = FormatterFactory.getTypeFormatter(sc, valueType);
    436465            %>
     
    462491                %>
    463492              </tbl:cell>
     493              <tbl:cell column="status"><div id="status.<%=item.getId()%>"></div></tbl:cell>
    464494            </tbl:row>
    465495            <%
     
    469499        </tbl:data>
    470500        </tbl:table>
     501        <base:icon image="warning.gif" /> = Some raw bioassays are missing this factor value;
     502          click to automatically try to inherit annotations from parents<br>
     503        <base:icon image="ok.gif" /> = All raw bioassays have a value for this factor
    471504        </base:section>
    472505        <%
     
    552585                    List values = a.getValues();
    553586                    usedFactorValues.get(at).addAll(values);
     587                    factorValuesCount.put(at, factorValuesCount.get(at)+1);
    554588                    Annotatable aItem = null;
    555589                    try
     
    715749    {
    716750      <%
     751      int numRawBioAssays = rawBioAssays.size();
    717752      for (Map.Entry<AnnotationType, Set<Object>> entry : usedFactorValues.entrySet())
    718753      {
    719754        AnnotationType at = entry.getKey();
     755        int numRawBioAssaysWithFactor = factorValuesCount.get(at);
    720756        Type valueType = at.getValueType();
    721757        if (at.isEnumeration() || (valueType != Type.TEXT && valueType != Type.STRING))
     
    728764          %>
    729765          setUsedFactorValue(<%=at.getId()%>, '<%=HTML.javaScriptEncode(formattedValues)%>');
     766          showStatus(<%=at.getId()%>, <%=numRawBioAssays%>, <%=numRawBioAssaysWithFactor%>);
    730767          <%
    731768        }
Note: See TracChangeset for help on using the changeset viewer.