Changeset 5130


Ignore:
Timestamp:
Oct 13, 2009, 12:44:33 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1403: Use cached annotations in experiment explorer, plot function, BASEfile exporter, and more...

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/ExperimentExplorer.java

    r5114 r5130  
    7676import net.sf.basedb.core.query.Selects;
    7777import net.sf.basedb.core.query.SqlResult;
     78import net.sf.basedb.core.snapshot.SnapshotManager;
    7879import net.sf.basedb.util.BioAssaySetUtil;
    7980import net.sf.basedb.util.formatter.Formatter;
     
    191192 
    192193  /**
     194    The snapshot manager that loads annotation values.
     195  */
     196  private final SnapshotManager snapshotManager;
     197 
     198  /**
    193199    Maps a bioassays cube column number to it's id for fast
    194200    loading by the {@link #getBioAssay(DbControl, short)} method.
     
    237243    this.bioAssaySet = bioAssaySet;
    238244    this.bioAssays = new HashMap<Short, Integer>();
     245    this.snapshotManager = new SnapshotManager();
    239246    this.summaryCache = new HashMap<AnnotationType, AnnotationSummary>();
    240247    for (BioAssay ba : bioAssaySet.getBioAssays().list(bioAssaySet.getDbControl()))
     
    254261    return BioAssaySet.getById(dc, bioAssaySet.getId());
    255262  }
     263 
     264  /**
     265    Get the snapshot manager that is used to load annotation
     266    values.
     267    @since 2.14
     268  */
     269  public SnapshotManager getSnapshotManager()
     270  {
     271    return snapshotManager;
     272  }
    256273 
    257274  /**
     
    10311048      for (BioAssay ba : bioAssaySet.getBioAssays().list(dc))
    10321049      {
    1033         Set<?> annotationValues = BioAssaySetUtil.getAnnotationValues(dc, ba, annotationType);
     1050        Set<?> annotationValues = BioAssaySetUtil.getAnnotationValues(dc, explorer.getSnapshotManager(), ba, annotationType);
    10341051        AnnotationGroup group = temp.get(annotationValues);
    10351052        if (group == null)
  • trunk/src/clients/web/net/sf/basedb/clients/web/plugins/BioAssayExperimentalFactorLoader.java

    r4978 r5130  
    2424import net.sf.basedb.core.BioAssay;
    2525import net.sf.basedb.core.DbControl;
     26import net.sf.basedb.core.snapshot.SnapshotManager;
    2627import net.sf.basedb.util.BioAssaySetUtil;
    2728
     
    3031  those that are present on the parent raw bioassay(s) without being
    3132  directly inherited by the bioassay. See
    32   {@link BioAssaySetUtil#getAnnotationValues(DbControl, BioAssay, net.sf.basedb.core.AnnotationType)}
     33  {@link BioAssaySetUtil#getAnnotationValues(DbControl, SnapshotManager, BioAssay, net.sf.basedb.core.AnnotationType)}
    3334 
    3435  @author Nicklas
     
    4041{
    4142
     43  private final SnapshotManager snapshotManager;
    4244  public BioAssayExperimentalFactorLoader()
    43   {}
     45  {
     46    this.snapshotManager = new SnapshotManager();
     47  }
     48 
     49  /**
     50    Creates an experimental factor loader that uses a specific snapshot manager
     51    for loading the annotation values.
     52    @since 2.14
     53  */
     54  public BioAssayExperimentalFactorLoader(SnapshotManager snapshotManager)
     55  {
     56    this.snapshotManager = snapshotManager;
     57  }
    4458 
    4559  @Override
     
    4761  {
    4862    DbControl dc = item.getDbControl();
    49     return BioAssaySetUtil.getAnnotationValues(dc, item, exportedProperty.annotationType);
     63    return BioAssaySetUtil.getAnnotationValues(dc, snapshotManager, item, exportedProperty.annotationType);
    5064  }
    5165
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/PlotServlet.java

    r5114 r5130  
    4545import net.sf.basedb.core.query.SqlResultIterator;
    4646import net.sf.basedb.core.query.WhenStatement;
     47import net.sf.basedb.core.snapshot.SnapshotManager;
    4748import net.sf.basedb.clients.web.formatter.FormatterFactory;
    4849import net.sf.basedb.clients.web.util.HTML;
     
    448449                Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
    449450                if (at.supportUnits()) formatter = at.getDefaultUnit().getFormatter(formatter);
     451                SnapshotManager snapshotManager = new SnapshotManager();
    450452                for (BioAssay bioAssay : bioAssays)
    451453                {
    452                   Set<?> values = BioAssaySetUtil.getAnnotationValues(dc, bioAssay, at);
     454                  Set<?> values = BioAssaySetUtil.getAnnotationValues(dc, snapshotManager, bioAssay, at);
    453455                  if (!groups.containsKey(values))
    454456                  {
  • trunk/src/core/net/sf/basedb/core/snapshot/SnapshotManager.java

    r5123 r5130  
    2323
    2424import java.util.ArrayList;
     25import java.util.Collections;
    2526import java.util.HashMap;
    2627import java.util.List;
    2728import java.util.Map;
    2829
     30import net.sf.basedb.core.Annotatable;
    2931import net.sf.basedb.core.AnnotationSet;
    3032import net.sf.basedb.core.AnnotationType;
     
    162164  }
    163165 
     166  /**
     167    Utility method for calling <code>getSnapshot</code> and <code>findAnnotations</code>
     168    in one go.
     169    @return A list with the annotation snapshots (an empty list is returned if the
     170      item doesn't have any annotations)
     171    @see #getSnapshot(DbControl, int)
     172    @see #findAnnotations(DbControl, AnnotationSetSnapshot, AnnotationType, boolean)
     173  */
     174  public List<AnnotationSnapshot> findAnnotations(DbControl dc, Annotatable item,
     175    AnnotationType at, boolean searchInherited)
     176  {
     177    if (!item.isAnnotated()) return Collections.emptyList();
     178    AnnotationSetSnapshot snapshot = getSnapshot(dc, item.getAnnotationSet().getId());
     179    return findAnnotations(dc, snapshot, at, searchInherited);
     180  }
    164181}
  • trunk/src/core/net/sf/basedb/util/BioAssaySetUtil.java

    r4912 r5130  
    2222package net.sf.basedb.util;
    2323
    24 import net.sf.basedb.core.Annotation;
    2524import net.sf.basedb.core.AnnotationType;
    2625import net.sf.basedb.core.BaseException;
     
    3635import net.sf.basedb.core.query.Expression;
    3736import net.sf.basedb.core.query.Restriction;
     37import net.sf.basedb.core.snapshot.AnnotationSnapshot;
     38import net.sf.basedb.core.snapshot.SnapshotManager;
    3839import net.sf.basedb.util.jep.ChannelFunction;
    3940import net.sf.basedb.util.jep.ExtraValueFunction;
     
    4748import net.sf.basedb.util.jep.ScoreFunction;
    4849
    49 import java.util.List;
    5050import java.util.Set;
    5151import java.util.TreeSet;
     
    7575    @param annotationType The annotation type of the annotations
    7676    @return A set containing all values
     77    @deprecated In BASE 2.14 due to performance problems, use
     78      {@link #getAnnotationValues(DbControl, SnapshotManager, BioAssay, AnnotationType)}
     79      instead
    7780  */
    7881  public static Set<?> getAnnotationValues(DbControl dc, BioAssay bioAssay, AnnotationType annotationType)
    7982  {
     83    return getAnnotationValues(dc, new SnapshotManager(), bioAssay, annotationType);
     84  }
     85
     86  /**
     87    Find the annotation values for a given annotation type on a bioassay.
     88    This method will only check annotations, primary and inherited, on the
     89    raw bioassays that the bioassay is a child of.
     90    <p>
     91    Since a bioassay may
     92    have more than one parent raw bioassay and each annotation may have
     93    multiple values it is possible that the set contains multiple values.
     94    Each value is only present once regardless of how many times it appears
     95    in the annotations.
     96   
     97    @param dc The DbControl for database access
     98    @param snapshotManager A snapshot manager that is used for loading the annotations
     99      from either the database or the file cache (if null, an internal, non-reusable
     100      snapshot manager is used)
     101    @param bioAssay The bioassay to get the annotations for
     102    @param annotationType The annotation type of the annotations
     103    @return A set containing all values
     104    @since 2.14
     105  */
     106  public static Set<?> getAnnotationValues(DbControl dc, SnapshotManager snapshotManager,
     107    BioAssay bioAssay, AnnotationType annotationType)
     108  {
     109    Set<Object> allValues = new TreeSet<Object>();
     110    if (snapshotManager == null) snapshotManager = new SnapshotManager();
     111    for (AnnotationSnapshot a : snapshotManager.findAnnotations(dc, bioAssay, annotationType, true))
     112    {
     113      if (a != null) allValues.addAll(a.getValues());
     114    }
    80115    ItemQuery<RawBioAssay> rbaQuery = bioAssay.getRawBioAssays();
    81116    rbaQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
    82     Set<Object> allValues = new TreeSet<Object>();
    83     if (bioAssay.isAnnotated())
     117    for (RawBioAssay rb : rbaQuery.list(dc))
    84118    {
    85       List<Annotation> all = bioAssay.getAnnotationSet().findAnnotations(dc, annotationType, true);
    86       for (Annotation a : all)
     119      for (AnnotationSnapshot a : snapshotManager.findAnnotations(dc, rb, annotationType, true))
    87120      {
    88121        if (a != null) allValues.addAll(a.getValues());
    89122      }
    90123    }
    91     for (RawBioAssay rb : rbaQuery.list(dc))
    92     {
    93       if (rb.isAnnotated())
    94       {
    95         List<Annotation> all =  rb.getAnnotationSet().findAnnotations(dc, annotationType, true);
    96         for (Annotation a : all)
    97         {
    98           if (a != null) allValues.addAll(a.getValues());
    99         }
    100       }
    101     }
    102124    return allValues;
    103125  }
    104126
     127 
    105128  /**
    106129    Find the values of parent properties for a given bioassay. This method
  • trunk/src/core/net/sf/basedb/util/export/spotdata/AbstractBioAssaySetExporter.java

    r4926 r5130  
    5252import net.sf.basedb.core.query.SqlResult;
    5353import net.sf.basedb.core.signal.SignalException;
     54import net.sf.basedb.core.snapshot.SnapshotManager;
    5455import net.sf.basedb.util.formatter.Formatter;
    5556import net.sf.basedb.util.formatter.ToStringFormatter;
     
    100101  private BioAssaySet source;
    101102  private DbControl dc;
     103  private SnapshotManager snapshotManager;
    102104  private ProgressReporter progress;
    103105 
     
    136138  {
    137139    return dc;
     140  }
     141 
     142  /**
     143    Set's the snapshot manager that should be used to load annotation values.
     144    If no snapshot manager is provided an internal, temporary one is used.
     145    @since 2.14
     146  */
     147  public void setSnapshotManager(SnapshotManager snapshotManager)
     148  {
     149    this.snapshotManager = snapshotManager;
     150  }
     151 
     152  /**
     153    Get the current snapshot manager.
     154    @since 2.14
     155  */
     156  public SnapshotManager getSnapshotManager()
     157  {
     158    return snapshotManager;
    138159  }
    139160 
     
    393414    Experiment exp = BioAssaySet.getById(dc, source.getId()).getExperiment();
    394415
     416    SnapshotManager sm = getSnapshotManager();
     417    if (sm == null) sm = new SnapshotManager();
     418   
    395419    // Load the experimental factors and register them
    396420    ItemQuery<AnnotationType> query = exp.getExperimentalFactors();
     
    401425      AnnotationAssayField af = new AnnotationAssayField();
    402426      af.setAnnotationType(at);
     427      af.setSnapshotManager(sm);
    403428      addAssayField(af);
    404429    }
  • trunk/src/core/net/sf/basedb/util/export/spotdata/AnnotationAssayField.java

    r4925 r5130  
    2727import net.sf.basedb.core.BioAssay;
    2828import net.sf.basedb.core.DbControl;
     29import net.sf.basedb.core.snapshot.SnapshotManager;
    2930import net.sf.basedb.util.BioAssaySetUtil;
    3031import net.sf.basedb.util.formatter.Formatter;
     
    4445  private AnnotationType at;
    4546  private Formatter<?> formatter;
     47  private SnapshotManager snapshotManager;
    4648 
    4749  /**
     
    7274  public Collection<?> getAssayValue(DbControl dc, BioAssay ba)
    7375  {
    74     return at == null ? null : BioAssaySetUtil.getAnnotationValues(dc, ba, at);
     76    return at == null ? null : BioAssaySetUtil.getAnnotationValues(dc, snapshotManager, ba, at);
    7577  }
    7678 
     
    105107    this.formatter = formatter;
    106108  }
     109 
     110  /**
     111    Set the snapshot manager that should be used to load annotation values.
     112    @since 2.14
     113  */
     114  public void setSnapshotManager(SnapshotManager snapshotManager)
     115  {
     116    this.snapshotManager = snapshotManager;
     117  }
    107118
    108119}
  • trunk/www/views/experiments/bioassays/index.jsp

    r5060 r5130  
    4545  import="net.sf.basedb.core.PermissionDeniedException"
    4646  import="net.sf.basedb.core.ItemAlreadyExistsException"
     47  import="net.sf.basedb.core.snapshot.SnapshotManager"
    4748  import="net.sf.basedb.util.RemovableUtil"
    4849  import="net.sf.basedb.util.ShareableUtil"
     
    6566 
    6667  private static void registerExportFormatters(ItemContext cc, List<AnnotationType> experimentalFactors)
    67   {   
     68  {
     69    SnapshotManager snapshotManager = new SnapshotManager();
    6870    for (AnnotationType at : experimentalFactors)
    6971    {
    70       cc.setObject("export.dataloader.#" + at.getId(), new BioAssayExperimentalFactorLoader());
     72      cc.setObject("export.dataloader.#" + at.getId(), new BioAssayExperimentalFactorLoader(snapshotManager));
    7173    }
    7274  }%>
  • trunk/www/views/experiments/bioassays/list_bioassays.jsp

    r4978 r5130  
    5151  import="net.sf.basedb.core.plugin.GuiContext"
    5252  import="net.sf.basedb.core.plugin.Plugin"
     53  import="net.sf.basedb.core.snapshot.SnapshotManager"
    5354  import="net.sf.basedb.util.Tree"
    5455  import="net.sf.basedb.util.Enumeration"
     
    119120  annotationTypes = annotationTypeQuery.list(dc);
    120121  experimentalFactors = experimentalFactorQuery.list(dc);
     122  final SnapshotManager snapshotManager = new SnapshotManager();
    121123  try
    122124  {
     
    572574                  <tbl:cell column="<%="ef"+at.getId()%>"
    573575                    ><tbl:cellvalue
    574                     list="<%=BioAssaySetUtil.getAnnotationValues(dc, item, at)%>"
     576                    list="<%=BioAssaySetUtil.getAnnotationValues(dc, snapshotManager, item, at)%>"
    575577                  /></tbl:cell>
    576578                  <%
Note: See TracChangeset for help on using the changeset viewer.