Changeset 3562


Ignore:
Timestamp:
Jul 16, 2007, 2:35:29 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #649 and #674

Location:
trunk
Files:
11 edited

Legend:

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

    r2993 r3562  
    7070    Formatter<Number> intFormatter = FormatterFactory.getIntFormatter(sc);
    7171    columns.add(new TableColumn("POSITION", "POSITION", null, Type.INT,
    72       "Position", "Spot position", "always", true, true, true, false, intFormatter));
     72      "Position", "Spot position", "always", true, true, true,
     73      Formula.AverageMethod.NONE, intFormatter));
    7374    for (int channel = 1; channel <= channels; ++channel)
    7475    {
    7576      TableColumn tc = new TableColumn("ch"+channel, "%"+channel, "ch("+channel+")",
    76         Type.FLOAT, "Ch "+channel, "Channel " + channel + " intensity");
    77       tc.setFormatter(numberFormatter);
     77        Type.FLOAT, "Ch "+channel, "Channel " + channel + " intensity", "auto", true, true, true,
     78        Formula.AverageMethod.ARITHMETIC_MEAN, numberFormatter);
    7879      columns.add(tc);
    7980    }
     
    8788      Formatter<Number> intFormatter = FormatterFactory.getIntFormatter(sc);
    8889      columns.add(new TableColumn(idPrefix + "position", propertyPrefix+"position", "raw('position')",
    89         Type.INT, titlePrefix+"Position", "Raw spot position", "auto", true, true, true, false, intFormatter));
     90        Type.INT, titlePrefix+"Position", "Raw spot position", "auto", true, true, true,
     91        Formula.AverageMethod.NONE, intFormatter));
    9092      columns.add(new TableColumn(idPrefix + "block", propertyPrefix+"block", "raw('block')",
    91         Type.INT, titlePrefix+"Block", "Block number", "auto", true, true, true, false, intFormatter));
     93        Type.INT, titlePrefix+"Block", "Block number", "auto", true, true, true,
     94        Formula.AverageMethod.NONE, intFormatter));
    9295      columns.add(new TableColumn(idPrefix + "metaGridX", propertyPrefix+"metaGridX", "raw('metaGridX')",
    93         Type.INT, titlePrefix+"Meta grid X", "Meta X coordinate", "auto", true, true, true, false, intFormatter));
     96        Type.INT, titlePrefix+"Meta grid X", "Meta X coordinate", "auto", true, true, true,
     97        Formula.AverageMethod.NONE, intFormatter));
    9498      columns.add(new TableColumn(idPrefix + "metaGridY", propertyPrefix+"metaGridY", "raw('metaGridY')",
    95         Type.INT, titlePrefix+"Meta grid Y", "Meta Y coordinate", "auto", true, true, true, false, intFormatter));
     99        Type.INT, titlePrefix+"Meta grid Y", "Meta Y coordinate", "auto", true, true, true,
     100        Formula.AverageMethod.NONE, intFormatter));
    96101      columns.add(new TableColumn(idPrefix + "row", propertyPrefix+"row", "raw('row')", Type.INT,
    97         titlePrefix+"Row", "Row number", "auto", true, true, true, false, intFormatter));
     102        titlePrefix+"Row", "Row number", "auto", true, true, true,
     103        Formula.AverageMethod.NONE, intFormatter));
    98104      columns.add(new TableColumn(idPrefix + "column", propertyPrefix+"column", "raw('column')",
    99         Type.INT, titlePrefix+"Column", "Column number", "auto", true, true, true, false, intFormatter));
     105        Type.INT, titlePrefix+"Column", "Column number", "auto", true, true, true,
     106        Formula.AverageMethod.NONE, intFormatter));
    100107      columns.add(new TableColumn(idPrefix + "x", propertyPrefix+"x", "raw('x')", Type.INT,
    101         titlePrefix+"X", "X coordinate", "auto", true, true, true, false, intFormatter));
     108        titlePrefix+"X", "X coordinate", "auto", true, true, true,
     109        Formula.AverageMethod.NONE, intFormatter));
    102110      columns.add(new TableColumn(idPrefix + "y", propertyPrefix+"y", "raw('y')", Type.INT,
    103         titlePrefix+"Y", "Y coordinate", "auto", true, true, true, false, intFormatter));
     111        titlePrefix+"Y", "Y coordinate", "auto", true, true, true,
     112        Formula.AverageMethod.NONE, intFormatter));
    104113 
    105114      List<RawDataProperty> rdpList = rawDataType.getProperties();
     
    109118        TableColumn tc = new TableColumn(idPrefix+rdpName, propertyPrefix+rdpName, "raw('"+rdpName+"')", rdp.getType(),
    110119          titlePrefix + rdp.getTitle(), rdp.getDescription(), "auto", true, true, true,
    111           rdp.isAveragable(), FormatterFactory.getExtendedPropertyFormatter(sc, rdp));
     120          rdp.getAverageMethod(), FormatterFactory.getExtendedPropertyFormatter(sc, rdp));
    112121        columns.add(tc);
    113122      }
     
    121130    Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
    122131    columns.add(new TableColumn(idPrefix + "name", propertyPrefix+"name", "rep('name')",
    123       Type.STRING, titlePrefix + "Name", "Reporter name", "auto", true, true, true, false, stringFormatter));
     132      Type.STRING, titlePrefix + "Name", "Reporter name", "auto", true, true, true,
     133      Formula.AverageMethod.NONE, stringFormatter));
    124134    columns.add(new TableColumn(idPrefix + "externalId", propertyPrefix+"externalId", "rep('externalId')",
    125       Type.STRING, titlePrefix + "ID", "Reporter ID", "auto", true, true, true, false, stringFormatter));
     135      Type.STRING, titlePrefix + "ID", "Reporter ID", "auto", true, true, true,
     136      Formula.AverageMethod.NONE, stringFormatter));
    126137    columns.add(new TableColumn(idPrefix + "symbol", propertyPrefix+"symbol", "rep('symbol')",
    127       Type.STRING, titlePrefix + "Gene symbol", "Gene symbol", "auto", true, true, true, false, stringFormatter));
     138      Type.STRING, titlePrefix + "Gene symbol", "Gene symbol", "auto", true, true, true,
     139      Formula.AverageMethod.NONE, stringFormatter));
    128140    columns.add(new TableColumn(idPrefix + "description", propertyPrefix+"description", "rep('description')",
    129       Type.STRING, titlePrefix + "Description", "Reporter description", "auto", true, true, true, false, stringFormatter));
     141      Type.STRING, titlePrefix + "Description", "Reporter description", "auto", true, true, true,
     142      Formula.AverageMethod.NONE, stringFormatter));
    130143    columns.add(new TableColumn(idPrefix + "lastUpdate", propertyPrefix+"lastUpdate", "rep('lastUpdate')",
    131       Type.DATE, titlePrefix + "Last update", "Last updateded", "auto", true, true, true, false, dateFormatter));
     144      Type.DATE, titlePrefix + "Last update", "Last updateded", "auto", true, true, true,
     145      Formula.AverageMethod.NONE, dateFormatter));
    132146
    133147    List<ExtendedProperty> extended = ExtendedProperties.getProperties("ReporterData");
     
    138152        String name = ep.getName();
    139153        TableColumn tc = new TableColumn(idPrefix + name, propertyPrefix + name, "rep('"+name+"')",
    140           ep.getType(), titlePrefix + ep.getTitle(), ep.getDescription());
    141         tc.setFormatter(FormatterFactory.getExtendedPropertyFormatter(sc, ep));
     154          ep.getType(), titlePrefix + ep.getTitle(), ep.getDescription(), "auto", true, true, true,
     155          ep.getAverageMethod(), FormatterFactory.getExtendedPropertyFormatter(sc, ep));
    142156        columns.add(tc);
    143157      }
     
    158172      int id = ev.getId();
    159173      TableColumn tc = new TableColumn(idPrefix+id, propertyPrefix + id, "xtra('" + evt.getExternalId() + "')", ev.getValueType(),
    160         titlePrefix+evt.getName(), evt.getDescription());
     174        titlePrefix+evt.getName(), evt.getDescription(), "auto", true, true, true, evt.getAverageMethod(), null);
    161175      Formatter<?> formatter = FormatterFactory.getTypeFormatter(sc, evt.getValueType());
    162176      if (evt.getValueType().isNumerical())
    163177      {
    164         // Numerical types *should* return a numberic formatter which is required by the color formatter
     178        // Numerical types *should* return a numeric formatter which is required by the color formatter
    165179        formatter = FormatterFactory.getColorFormatter(sc, evt.getColoring(),
    166180          (Formatter<Number>)formatter);
     
    188202      {
    189203        TableColumn tc = new TableColumn(idPrefix+f.getId(), "="+jepExpression, jepExpression, Type.FLOAT,
    190             titlePrefix + f.getName(), f.getDescription());
     204            titlePrefix + f.getName(), f.getDescription(), "auto", true, true, true,
     205            f.getAverageMethod(), null);
    191206        tc.setFormatter(FormatterFactory.getColorFormatter(sc, f.getColoring(), numberFormatter));
    192207        columns.add(tc);
     
    200215    List<String> selectedIds = new ArrayList<String>(columns.size());
    201216    List<String> selectedProperties = new ArrayList<String>(columns.size());
     217    List<TableColumn> selectedColumns = new ArrayList<TableColumn>(columns.size());
    202218   
    203219    String visibleColumns = cc.getSetting("columns");
     
    213229          selectedProperties.add(tc.getProperty());
    214230          selectedIds.add(tc.getId());
     231          selectedColumns.add(tc);
    215232        }
    216233      }
    217234    }
    218     return new SelectedInfo(selectedProperties, selectedIds);
     235    return new SelectedInfo(selectedProperties, selectedIds, selectedColumns);
    219236  }
    220237 
     
    223240    public final List<String> selectedProperties;
    224241    public final List<String> selectedIds;
     242    public final List<TableColumn> selectedColumns;
    225243   
    226     private SelectedInfo(List<String> properties, List<String> ids)
     244    private SelectedInfo(List<String> properties, List<String> ids, List<TableColumn> columns)
    227245    {
    228246      this.selectedIds = ids;
    229247      this.selectedProperties = properties;
     248      this.selectedColumns = columns;
    230249    }
    231250  }
  • trunk/src/clients/web/net/sf/basedb/clients/web/ExperimentExplorer.java

    r3520 r3562  
    3636import net.sf.basedb.util.Values;
    3737import net.sf.basedb.clients.web.formatter.FormatterFactory;
     38import net.sf.basedb.clients.web.taglib.table.TableColumn;
    3839import net.sf.basedb.core.AnnotationType;
    3940import net.sf.basedb.core.BaseException;
     
    712713    @return A query
    713714  */
    714   public DynamicSpotQuery getSpotQuery(DbControl dc, ReporterData reporter, int positionIndex, List<String> selectionList)
     715  public DynamicSpotQuery getSpotQuery(DbControl dc, ReporterData reporter, int positionIndex, List<TableColumn> selectionList)
    715716  {
    716717    BioAssaySet bioAssaySet = getBioAssaySet(dc);
     
    780781    // Set additional selected columns
    781782    int i = 0;
    782     for (String selectProperty : selectionList)
     783    for (TableColumn tc : selectionList)
    783784    {
    784785      // Skip channel intensities since they are already selected
    785       if (!selectProperty.startsWith("%"))
     786      if (!tc.getProperty().startsWith("%"))
    786787      {
    787         Expression select = ItemContext.getDynamicExpression(dc, selectProperty);
     788        Expression select = ItemContext.getDynamicExpression(dc, tc.getProperty());
    788789        if (select != null)
    789790        {
     
    791792          if (positionIndex == SPOT_AVG)
    792793          {
    793             select = Aggregations.mean(select);
     794            select = tc.getAverageMethod().getAverageExpression(select);
    794795          }
    795796          spotQuery.select(Selects.expression(select, "e" + i));
     
    809810        if (positionIndex == SPOT_AVG)
    810811        {
    811           sortby = Aggregations.mean(sortby);
     812          // Find TableColumn to know which average method to use
     813          boolean found = false;
     814          for (TableColumn tc : selectionList)
     815          {
     816            if (sortProperty.equals(tc.getProperty()))
     817            {
     818              sortby = tc.getAverageMethod().getAverageExpression(sortby);
     819              found = true;
     820              break;
     821            }
     822          }
     823          if (!found) sortby = null;
    812824        }
    813825        if (sortby != null)
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/TableColumn.java

    r3410 r3562  
    2525package net.sf.basedb.clients.web.taglib.table;
    2626
     27import net.sf.basedb.core.Formula;
    2728import net.sf.basedb.core.Type;
    2829import net.sf.basedb.util.formatter.Formatter;
     
    7172  private final boolean exportable;
    7273  private final String show;
    73   private final boolean averagable;
     74  private final Formula.AverageMethod averageMethod;
    7475  private Formatter<?> formatter;
    7576 
     77  /**
     78    Create TableColumn.
     79    @param id
     80    @param property
     81    @param jepExpression
     82    @param datatype
     83    @param title
     84    @param description
     85    @deprecated
     86   */
    7687  public TableColumn(String id, String property, String jepExpression, Type datatype, String title, String description)
    7788  {   
    78     this(id, property, jepExpression, datatype, title, description, "auto", true, true, true, datatype.isNumerical(), null);
     89    this(id, property, jepExpression, datatype, title, description, "auto", true, true, true,
     90      datatype.isNumerical() ? Formula.AverageMethod.ARITHMETIC_MEAN : null, null);
    7991  }
    8092 
    8193  public TableColumn(String id, String property, String jepExpression, Type datatype, String title, String description, String show,
    82     boolean sortable, boolean filterable, boolean exportable, boolean averagable, Formatter<?> formatter)
     94    boolean sortable, boolean filterable, boolean exportable, Formula.AverageMethod averageMethod, Formatter<?> formatter)
    8395  {   
    8496    this.id = id;
     
    92104    this.filterable = filterable;
    93105    this.exportable = exportable;
    94     this.averagable = datatype.isNumerical() && averagable;
     106    this.averageMethod = averageMethod;
    95107    this.formatter = formatter;
    96108  }
     
    148160  public boolean isAveragable()
    149161  {
    150     return averagable;
     162    return averageMethod != null && averageMethod != Formula.AverageMethod.NONE;
    151163  }
    152164
     165  /**
     166    @since 2.4
     167  */
     168  public Formula.AverageMethod getAverageMethod()
     169  {
     170    return averageMethod;
     171  }
     172 
    153173  /**
    154174     @since 2.0.2
  • trunk/src/core/net/sf/basedb/core/ExtendedProperties.java

    r2747 r3562  
    205205      if (type == Type.STRING && length > 255) type = Type.TEXT;
    206206      boolean nullable = XMLUtil.getBooleanAttribute(property, "null", true);
    207       boolean insertable = XMLUtil.getBooleanAttribute(property, "insert", true);;
    208       boolean updateable = XMLUtil.getBooleanAttribute(property, "update", true);;
     207      boolean insertable = XMLUtil.getBooleanAttribute(property, "insert", true);
     208      boolean updateable = XMLUtil.getBooleanAttribute(property, "update", true);
    209209      boolean averagable = XMLUtil.getBooleanAttribute(property, "averagable", type.isNumerical());
     210      String avgMethod = property.getAttributeValue("averagemethod");
     211      Formula.AverageMethod averageMethod = null;
     212      if (avgMethod != null)
     213      {
     214        averageMethod = Formula.AverageMethod.valueOf(avgMethod.toUpperCase());
     215      }
     216      else if (averagable)
     217      {
     218        averageMethod = Formula.AverageMethod.ARITHMETIC_MEAN;
     219      }
     220      else
     221      {
     222        averageMethod = Formula.AverageMethod.NONE;       
     223      }
    210224     
    211225      List<Element> links = (List<Element>)property.getChildren("link");
     
    221235        }
    222236      }
    223       properties.add(new ExtendedProperty(name, title, description, column, type, length, nullable, insertable, updateable, averagable, epLinks));
     237      properties.add(new ExtendedProperty(name, title, description, column, type, length, nullable, insertable, updateable, averageMethod, epLinks));
    224238    }
    225239    return properties;
  • trunk/src/core/net/sf/basedb/core/ExtendedProperty.java

    r3472 r3562  
    4646  private final boolean insertable;
    4747  private final boolean updateable;
    48   private final boolean isAveragable;
     48  private final Formula.AverageMethod averageMethod;
    4949  private final List<ExtendedPropertyLinker> linkers;
    5050
     
    5555  ExtendedProperty(String name, String title, String description, String column,
    5656    Type type, int length, boolean nullable, boolean insertable, boolean updateable,
    57     boolean isAveragable, List<ExtendedPropertyLinker> linkers)
     57    Formula.AverageMethod averageMethod, List<ExtendedPropertyLinker> linkers)
    5858  {
    5959    this.name = name;
     
    6666    this.insertable = insertable;
    6767    this.updateable = updateable;
    68     this.isAveragable = type.isNumerical() && isAveragable;
     68    this.averageMethod = averageMethod;
    6969    this.linkers = linkers;
    7070  }
     
    161161    values. By default all numerical values are averagable.
    162162    @return TRUE if it makes sense to take the average, FALSE otherwise
     163    @see #getAverageMethod()
    163164  */
    164165  public boolean isAveragable()
    165166  {
    166     return isAveragable;
     167    return averageMethod != null && averageMethod != Formula.AverageMethod.NONE;
     168  }
     169 
     170  /**
     171    Which method to use when calculating the average of a set of values.
     172    Prior to 2.4 only arithmetic mean was supported.
     173    @return The average method to use
     174    @since 2.4
     175  */
     176  public Formula.AverageMethod getAverageMethod()
     177  {
     178    return averageMethod;
    167179  }
    168180 
  • trunk/src/core/net/sf/basedb/core/RawDataProperty.java

    r2535 r3562  
    4242  */
    4343  RawDataProperty(String name, String title, String description, String column,
    44     Type type, int length, boolean nullable, boolean averagable, int channel)
     44    Type type, int length, boolean nullable, Formula.AverageMethod averageMethod, int channel)
    4545  {
    46     super(name, title, description, column, type, length, nullable, true, false, averagable, null);
     46    super(name, title, description, column, type, length, nullable, true, false, averageMethod, null);
    4747    this.channel = channel;
    4848  }
  • trunk/src/core/net/sf/basedb/core/RawDataTypes.java

    r2535 r3562  
    177177      boolean nullable = XMLUtil.getBooleanAttribute(property, "null", true);
    178178      boolean averagable = XMLUtil.getBooleanAttribute(property, "averagable", type.isNumerical());
     179      String avgMethod = property.getAttributeValue("averagemethod");
     180      Formula.AverageMethod averageMethod = null;
     181      if (avgMethod != null)
     182      {
     183        averageMethod = Formula.AverageMethod.valueOf(avgMethod.toUpperCase());
     184      }
     185      else if (averagable)
     186      {
     187        averageMethod = Formula.AverageMethod.ARITHMETIC_MEAN;
     188      }
     189      else
     190      {
     191        averageMethod = Formula.AverageMethod.NONE;       
     192      }
    179193      int channel = XMLUtil.getIntAttribute(property, "channel", 0);
    180       properties.add(new RawDataProperty(name, title, description, column, type, length, nullable, averagable, channel));
     194      properties.add(new RawDataProperty(name, title, description, column, type, length, nullable, averageMethod, channel));
    181195    }
    182196    return properties;
  • trunk/src/core/net/sf/basedb/core/data/ExtendableData.java

    r2601 r3562  
    4545         update="true"
    4646         insert="true"
    47          averagable="false"
     47         averagemethod="geometric_mean"
    4848         description="An extra property for all reporters"
    4949      /&gt;
     
    156156    <td>averagable</td>
    157157    <td>
     158      <b>This attribute has been deprecated and is replaced by <code>averagemethod</code>!</b>
     159      <br>
    158160      If it makes sense to take the average of multiple values for this
    159161      property. By default all numerical columns are averagable. For non-numerical
    160       columns, this attribute is ignored.
     162      columns, this attribute is ignored. The default method is to calculate the
     163      arithmetic mean.
    161164      <ul>
    162165      <li>true
     
    164167      </ul>
    165168      See {@link net.sf.basedb.core.ExtendedProperty#isAveragable()}.
     169    </td>
     170  </tr>
     171  <tr valign="top">
     172    <td>averagemethod</td>
     173    <td>
     174      The method to use when calculating the average of a set of values.
     175      This attribute replaces the <code>averagable</code> attribute.
     176      The following values can be used:
     177      <ul>
     178      <li>none: do not use this property when calculating averages
     179      <li>arithmetic_mean: calculate the arithmetic mean
     180      <li>geometric_mean: calculate the geometric mean
     181      <li>min: use the minimum value among the values in the set
     182      <li>max: use the maximum value among the values in the set
     183      </ul>
     184      If no value is given to this attribute the default is to use arithmetic
     185      mean for all numerical value types.
     186      See {@link net.sf.basedb.core.ExtendedProperty#getAverageMethod()}.
    166187    </td>
    167188  </tr>
  • trunk/src/core/net/sf/basedb/core/dtd/extended-properties.dtd

    r2535 r3562  
    4343  update (true|false) "true"
    4444  averagable (true|false) #IMPLIED
     45  averagemethod (none|arithmetic_mean|geometric_mean|min|max) #IMPLIED
    4546>
    4647
  • trunk/src/core/net/sf/basedb/core/dtd/raw-data-types.dtd

    r2535 r3562  
    4646  null (true|false) "true"
    4747  averagable (true|false) #IMPLIED
     48  averagemethod (none|arithmetic_mean|geometric_mean|min|max) #IMPLIED
    4849  channel CDATA #IMPLIED
    4950>
  • trunk/www/views/experiments/explorer/view/view.jsp

    r3520 r3562  
    120120    DynamicUtil.addRawDataColumns(columns, dc, rawDataType, "raw.", "$", "[Raw] ");
    121121    columns.add(new TableColumn("raw.spotimage", "$id", "raw('id')", Type.INT,
    122       "[Raw] Spotimage", "", "auto", false, false, false, false,
     122      "[Raw] Spotimage", "", "auto", false, false, false, null,
    123123      new SpotImageFormatter(dc, rawDataType, root)));
    124124  }
     
    162162    try
    163163    {
    164       DynamicSpotQuery spotQuery = explorer.getSpotQuery(dc, reporter, positionIndex, selected.selectedProperties);
     164      DynamicSpotQuery spotQuery = explorer.getSpotQuery(dc, reporter, positionIndex, selected.selectedColumns);
    165165      spotData = spotQuery.iterate(dc);
    166166    }
Note: See TracChangeset for help on using the changeset viewer.