Changeset 2993


Ignore:
Timestamp:
Dec 1, 2006, 3:34:35 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #215: Incorrect use of DynamicSpotQuery? in table view, plot function, filter function, etc.

Location:
trunk
Files:
34 edited

Legend:

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

    r2942 r2993  
    172172  }
    173173 
    174   public static void addFormulaColumns(List<TableColumn> columns, DbControl dc, RawDataType rawDataType, Formula.Type type, String idPrefix, String titlePrefix)
     174  public static void addFormulaColumns(List<TableColumn> columns, DbControl dc,
     175    RawDataType rawDataType, Formula.Type type, String idPrefix, String titlePrefix, boolean allowRawFunction)
    175176  {
    176177    ItemQuery<Formula> query = Formula.getQuery(type, rawDataType);
     
    184185      Formula f = result.next();
    185186      String jepExpression = f.getFormula(0);
    186       TableColumn tc = new TableColumn(idPrefix+f.getId(), "="+jepExpression, jepExpression, Type.FLOAT,
    187         titlePrefix + f.getName(), f.getDescription());
    188       tc.setFormatter(FormatterFactory.getColorFormatter(sc, f.getColoring(), numberFormatter));
    189       columns.add(tc);
     187      if (allowRawFunction || !jepExpression.contains("raw("))
     188      {
     189        TableColumn tc = new TableColumn(idPrefix+f.getId(), "="+jepExpression, jepExpression, Type.FLOAT,
     190            titlePrefix + f.getName(), f.getDescription());
     191        tc.setFormatter(FormatterFactory.getColorFormatter(sc, f.getColoring(), numberFormatter));
     192        columns.add(tc);
     193      }
    190194    }
    191195    result.close();
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/PlotServlet.java

    r2942 r2993  
    376376        // Filter
    377377        Restriction filter = filterFormula == null ?
    378           null : BioAssaySetUtil.createJepRestriction(dc, bas, filterFormula);
     378          null : BioAssaySetUtil.createJepRestriction(dc, bas, filterFormula, false);
    379379       
    380380        // Convert formulas to Expression:s
     
    386386          for (int i = 0; i < xFormulas.length; ++i)
    387387          {
    388             x[i] = BioAssaySetUtil.createJepExpression(dc, bas, xFormulas[i]);
     388            x[i] = BioAssaySetUtil.createJepExpression(dc, bas, xFormulas[i], false);
    389389            if (xLog) x[i] = Expressions.log2(x[i]);
    390390          }
     
    394394          for (int i = 0; i < yFormulas.length; ++i)
    395395          {
    396             y[i] = BioAssaySetUtil.createJepExpression(dc, bas, yFormulas[i]);
     396            y[i] = BioAssaySetUtil.createJepExpression(dc, bas, yFormulas[i], false);
    397397            if (yLog) y[i] = Expressions.log2(y[i]);
    398398          }
  • trunk/src/core/common-queries.xml

    r2929 r2993  
    24852485  </query>
    24862486
     2487  <query id="SET_MAX_MAPPING_ON_DATACUBES" type="HQL">
     2488    <sql>
     2489      UPDATE DataCubeData dcd
     2490      SET dcd.maxRawMappingsForSpot = -1
     2491      WHERE dcd.maxRawMappingsForSpot IS NULL
     2492    </sql>
     2493    <description>
     2494      A HQL query that sets the maxRawMappingsForSpot on all data cubes with a
     2495      null value to -1. This is required so we can load them by Hibernate.
     2496    </description>
     2497  </query>
     2498
     2499
     2500  <query id="SET_MAX_MAPPING_ON_DATACUBE" type="HQL">
     2501    <sql>
     2502      UPDATE DataCubeData dcd
     2503      SET dcd.maxRawMappingsForSpot = :mapCount
     2504      WHERE dcd.id = :dataCube
     2505    </sql>
     2506    <description>
     2507      A HQL query that sets the maxRawMappingsForSpot on a data cube.
     2508    </description>
     2509  </query>
     2510
    24872511</predefined-queries>
  • trunk/src/core/net/sf/basedb/core/BioAssaySet.java

    r2981 r2993  
    414414  {
    415415    return getData().getNumSpots();
     416  }
     417 
     418  /**
     419    Get the number of mappings to raw data spots for the spot with
     420    the most number of mappings. For most bioassay sets this value is
     421    probably 1. After a merge, the count can be higher which may require some
     422    plugins to behave differently when using values from the raw data table.
     423    @since 2.2
     424  */
     425  public int getMaxRawMappingsForSpot()
     426  {
     427    return getData().getDataCubeLayer().getDataCube().getMaxRawMappingsForSpot();
    416428  }
    417429 
  • trunk/src/core/net/sf/basedb/core/DataCube.java

    r2962 r2993  
    2424package net.sf.basedb.core;
    2525
     26import java.sql.SQLException;
     27
    2628import net.sf.basedb.core.data.DataCubeData;
    2729import net.sf.basedb.core.data.SharedData;
     30import net.sf.basedb.core.query.Aggregations;
     31import net.sf.basedb.core.query.Dynamic;
     32import net.sf.basedb.core.query.Expression;
     33import net.sf.basedb.core.query.Orders;
     34import net.sf.basedb.core.query.Select;
     35import net.sf.basedb.core.query.Selects;
     36import net.sf.basedb.core.query.SqlResult;
    2837
    2938/**
     
    160169    {
    161170      getData().setBytes(addedBytes);
     171      getData().setMaxRawMappingsForSpot(countSpotMappings());
    162172    }
    163173    else if (action == Transactional.Action.UPDATE && addedBytes != 0)
     
    559569 
    560570  /**
     571    Get the number of mappings to raw data spots for the spot with
     572    the most number of mappings. For most data cubes this value is
     573    probably 1. After a merge, the count can be higher which may require some
     574    plugins to behave differently when using values from the raw data table.
     575    @since 2.2
     576  */
     577  public int getMaxRawMappingsForSpot()
     578  {
     579    return getData().getMaxRawMappingsForSpot();
     580  }
     581 
     582  /**
    561583      Gets the number of bytes the analysed data in this cube occupies on disk.
    562584  */
     
    627649  }
    628650
     651  /**
     652    Count the number of raw data mappings for the spot with the most
     653    mappings.
     654    @since 2.2
     655  */
     656  int countSpotMappings()
     657  {
     658    DynamicQuery query = new RawMappingQuery(this);
     659    Expression count = Aggregations.count(null, false);
     660    query.select(
     661      Selects.expression(count, "mapCount")
     662    );
     663    query.group(Dynamic.column(VirtualColumn.COLUMN));
     664    query.group(Dynamic.column(VirtualColumn.POSITION));
     665    query.order(Orders.desc(count));
     666    query.setMaxResults(1);
     667    /*
     668      SELECT COUNT(*) AS mapCount
     669      FROM Dymamic#RawParents raw
     670      WHERE raw.cube = ?
     671      GROUP BY raw.column, raw.position
     672      ORDER BY COUNT(*) DESC
     673      LIMIT 1
     674    */
     675    DynamicResultIterator result = query.iterate(getDbControl());
     676    try
     677    {
     678      int maxCount = 0;
     679      if (result.hasNext())
     680      {
     681        SqlResult r = result.next();
     682        maxCount = r.getInt(result.getIndex("mapCount"));
     683      }
     684      return maxCount;
     685    }
     686    catch (SQLException ex)
     687    {
     688      throw new BaseException(ex);
     689    }
     690    finally
     691    {
     692      result.close();
     693    }
     694  }
     695
     696  /**
     697    Select data from Dynamic#RawParents table. Used for counting
     698    number of mappings between spots and raw data.
     699 
     700    @version 2.2
     701  */
     702  private static final class RawMappingQuery
     703    extends DynamicQuery
     704  {
     705   
     706    private RawMappingQuery(DataCube dataCube)
     707    {
     708      super(dataCube, VirtualTable.RAWPARENTS);
     709    }
     710   
     711    /*
     712      From the AbstractSqlQuery class
     713      -------------------------------------------
     714    */
     715    Select[] getDefaultSelects()
     716    {
     717      return null;
     718    }
     719    // -------------------------------------------
     720  }
     721 
    629722}
  • trunk/src/core/net/sf/basedb/core/Install.java

    r2941 r2993  
    102102    method.
    103103  */
    104   public static final int NEW_SCHEMA_VERSION = 27;
     104  public static final int NEW_SCHEMA_VERSION = 28;
    105105
    106106  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/ItemContext.java

    r2981 r2993  
    159159  // For parsing JEP expressions
    160160  private static final JepFunction ch = new ChannelFunction();
    161   private static final JepFunction raw = new RawFunction();
     161  private static final JepFunction raw = new RawFunction(true);
    162162  private static final JepFunction rep = new ReporterFunction();
    163163 
  • trunk/src/core/net/sf/basedb/core/Update.java

    r2981 r2993  
    3333import org.hibernate.mapping.Table;
    3434
     35import net.sf.basedb.core.data.DataCubeData;
    3536import net.sf.basedb.core.data.FormulaData;
    3637import net.sf.basedb.core.data.PlateData;
     
    326327      <li>Added {@link net.sf.basedb.core.data.ProjectData#getProjectDefaults()}.
    327328      </ul>
     329    </td>
     330  </tr>
     331 
     332  <tr>
     333    <td>28</td>
     334    <td>
     335      <ul>
     336      <li>Added {@link net.sf.basedb.core.data.DataCubeData#getMaxRawMappingsForSpot()}.
     337      </ul>
     338      The update must query the dynamic database and set this value for
     339      all existing data cubes.
    328340    </td>
    329341  </tr>
     
    442454      }
    443455
     456      // Schemaversion 20-23 only updates the version number
    444457      if (schemaVersion < 23)
    445458      {
     
    464477      if (schemaVersion < 26)
    465478      {
    466         if (progress != null) progress.display((int)(25*progress_factor), "--Updating schema version: " + schemaVersion + " -> 26...");
    467         schemaVersion = setSchemaVersionInTransaction(session, 26);
    468       }
    469      
    470       if (schemaVersion < 27)
    471       {
    472         if (progress != null) progress.display((int)(26*progress_factor), "--Updating schema version: " + schemaVersion + " -> 27...");
     479        if (progress != null) progress.display((int)(25*progress_factor), "--Updating schema version: " + schemaVersion + " -> 27...");
    473480        schemaVersion = setSchemaVersionInTransaction(session, 27);
    474481      }
    475482     
     483      if (schemaVersion < 28)
     484      {
     485        if (progress != null) progress.display((int)(27*progress_factor), "--Updating schema version: " + schemaVersion + " -> 28...");
     486        updateToSchemaVersion28(sc);
     487      }
     488     
    476489      /*
    477       if (schemaVersion < 28)
    478       {
    479         if (progress != null) progress.display((int)(27*progress_factor), "--Updating schema version: " + schemaVersion + " -> 28...");
    480         schemaVersion = setSchemaVersionInTransaction(session, 28);
     490      if (schemaVersion < 29)
     491      {
     492        if (progress != null) progress.display((int)(28*progress_factor), "--Updating schema version: " + schemaVersion + " -> 29...");
     493        schemaVersion = setSchemaVersionInTransaction(session, 29);
    481494        - or -
    482         schemaVersion = updateToSchemaVersion28(session);
     495        schemaVersion = updateToSchemaVersion29(session);
    483496      }
    484497      ... etc...
     
    756769    finally
    757770    {
    758       if (dc != null) dc.close(); 
     771      if (dc != null) dc.close();
    759772    }
    760773    return schemaVersion;
     
    981994      log.error("updateToSchemaVersion25: FAILED", ex);
    982995      throw ex;
     996    }
     997    return schemaVersion;
     998  }
     999
     1000  /**
     1001    Find the number of raw mappings for the spot with the maximum number
     1002    for each data cube
     1003    @return The new schema version (=28)
     1004  */
     1005  private static int updateToSchemaVersion28(SessionControl sc)
     1006    throws BaseException
     1007  {
     1008    final int schemaVersion = 28;
     1009    DbControl dc = null;
     1010    try
     1011    {
     1012      dc = sc.newDbControl();
     1013      org.hibernate.Session session = dc.getHibernateSession();
     1014     
     1015      // Query for loading all data cubes
     1016      org.hibernate.Query query = HibernateUtil.createQuery(session,
     1017        "FROM DataCubeData dcd WHERE dcd.maxRawMappingsForSpot = -1");
     1018      org.hibernate.Query updateQuery = HibernateUtil.getPredefinedQuery(session,
     1019        "SET_MAX_MAPPING_ON_DATACUBE");
     1020      /*
     1021        UPDATE DataCubeData dcd
     1022        SET dcd.maxRawMappingsForSpot = :mapCount
     1023        WHERE dcd.id = :dataCube
     1024      */
     1025      for (DataCubeData cubeData : HibernateUtil.loadList(DataCubeData.class, query))
     1026      {
     1027        DataCube cube = dc.getItem(DataCube.class, cubeData);
     1028        int mapCount = cube.countSpotMappings();
     1029        updateQuery.setInteger("mapCount", mapCount);
     1030        updateQuery.setInteger("dataCube", cube.getId());
     1031        HibernateUtil.executeUpdate(updateQuery);
     1032      }
     1033
     1034      // Update the shcema version number
     1035      setSchemaVersion(session, schemaVersion);
     1036 
     1037      // Commit the changes
     1038      dc.commit();
     1039      log.info("updateToSchemaVersion28: OK");
     1040    }
     1041    catch (BaseException ex)
     1042    {
     1043      log.error("updateToSchemaVersion28: FAILED", ex);
     1044      throw ex;
     1045    }
     1046    finally
     1047    {
     1048      if (dc != null) dc.close();
    9831049    }
    9841050    return schemaVersion;
     
    12001266        }
    12011267     
     1268        if (schemaVersion < 28)
     1269        {
     1270          // Set maxRawMappingsForSpot to -1 for all data cubes with a null value
     1271          org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     1272              "SET_MAX_MAPPING_ON_DATACUBES");
     1273          /*
     1274            UPDATE DataCubeData dcd
     1275            SET dcd.maxRawMappingsForSpot = -1
     1276            WHERE dcd.maxRawMappingsForSpot IS NULL
     1277          */
     1278          HibernateUtil.executeUpdate(query);
     1279        }
     1280       
    12021281        //  Commit the changes
    12031282        HibernateUtil.commit(tx);
  • trunk/src/core/net/sf/basedb/core/data/DataCubeData.java

    r2962 r2993  
    161161    this.numPositions = numPositions;
    162162  }
     163 
     164  private int maxRawMappings;
     165  /**
     166    The maximum number of raw data spots a single spot in this data cube
     167    is mapped to.
     168    @hibernate.property column="`max_raw_spots`" type="int" not-null="true" update="false"
     169  */
     170  public int getMaxRawMappingsForSpot()
     171  {
     172    return maxRawMappings;
     173  }
     174  public void setMaxRawMappingsForSpot(int maxRawMappings)
     175  {
     176    this.maxRawMappings = maxRawMappings;
     177  }
    163178
    164179  private Set<DataCubeLayerData> layers;
  • trunk/src/core/net/sf/basedb/util/BioAssaySetUtil.java

    r2992 r2993  
    140140    by JEP (see {@link Jep#getFunctions()}) this method defines the following functions:
    141141    <ul>
    142     <li>all functions defined by the {@link #createJepExpression(DbControl, BioAssaySet, String)}
    143       method
     142    <li>all functions defined by the {@link #createJepExpression(DbControl, BioAssaySet,
     143      String, boolean)} method
    144144    <li>inList(list): Checks if the reporter is included in the specified list
    145145    <li>notInList(list): Checks if the reporter isn't included in the specified list
     
    147147    @see net.sf.basedb.util.jep.Jep
    148148  */
    149   public static Restriction createJepRestriction(DbControl dc, BioAssaySet bioAssaySet, String formula)
     149  public static Restriction createJepRestriction(DbControl dc, BioAssaySet bioAssaySet,
     150    String formula, boolean allowRawIfMultipleMappings)
    150151    throws InvalidDataException, BaseException
    151152  {
    152153    if (bioAssaySet == null) throw new InvalidUseOfNullException("bioAssaySet");
    153154    if (formula == null) throw new InvalidUseOfNullException("formula");
    154     RawFunction raw = new RawFunction();
     155    RawFunction raw = new RawFunction(bioAssaySet.getMaxRawMappingsForSpot() == 1 ||
     156      allowRawIfMultipleMappings);
    155157    ChannelFunction ch = new ChannelFunction();
    156158    ReporterFunction reporter = new ReporterFunction();
     
    167169    by JEP (see {@link Jep#getFunctions()}) this method defines the following functions:
    168170    <ul>
    169     <li>raw(property): The value of the specified raw data property
     171    <li>raw(property): The value of the specified raw data property. The use of this function
     172      can be denied if the bioassayset contains spots that are mapped to more than one
     173      raw data spot. The <code>allowRawIfMultipleMappings</code> parameter controls
     174      this.
    170175    <li>rep(property): The value of the specified reporter property
    171176    <li>pos: The position of a spot. Note that this is not the same as raw(position)
     
    178183    @see net.sf.basedb.util.jep.Jep
    179184  */
    180   public static Expression createJepExpression(DbControl dc, BioAssaySet bioAssaySet, String formula)
     185  public static Expression createJepExpression(DbControl dc, BioAssaySet bioAssaySet,
     186    String formula, boolean allowRawIfMultipleMappings)
    181187    throws InvalidDataException, BaseException
    182188  {
    183189    if (bioAssaySet == null) throw new InvalidUseOfNullException("bioAssaySet");
    184190    if (formula == null) throw new InvalidUseOfNullException("formula");
    185     RawFunction raw = new RawFunction();
     191    RawFunction raw = new RawFunction(bioAssaySet.getMaxRawMappingsForSpot() == 1 ||
     192      allowRawIfMultipleMappings);
    186193    ChannelFunction ch = new ChannelFunction();
    187194    PositionFunction pos = new PositionFunction();
  • trunk/src/core/net/sf/basedb/util/IntensityCalculatorUtil.java

    r2790 r2993  
    485485    }
    486486    JEP[] jeps = new JEP[channels];
    487     RawFunction raw = new RawFunction(dc, rawDataType);
     487    RawFunction raw = new RawFunction(dc, rawDataType, true);
    488488    MeanFunction mean = new MeanFunction(dc);
    489489    for (int i = 0; i < channels; ++i)
     
    501501  {
    502502    Expression[] expressions = new Expression[formulas.length];
    503     RawFunction raw = new RawFunction(dc, rawDataType);
     503    RawFunction raw = new RawFunction(dc, rawDataType, true);
    504504    MeanFunction mean = new MeanFunction(dc);
    505505    for (int i = 0; i < formulas.length; ++i)
  • trunk/src/core/net/sf/basedb/util/jep/ChannelFunction.java

    r2981 r2993  
    7070  @base.modified $Date$
    7171  @see Jep
    72   @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String)
     72  @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String, boolean)
    7373*/
    7474public class ChannelFunction
  • trunk/src/core/net/sf/basedb/util/jep/ExtraValueFunction.java

    r2981 r2993  
    5555  @base.modified $Date$
    5656  @see Jep
    57   @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String)
     57  @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String, boolean)
    5858*/
    5959public class ExtraValueFunction
  • trunk/src/core/net/sf/basedb/util/jep/InReporterListFunction.java

    r2981 r2993  
    5151  @base.modified $Date$
    5252  @see Jep
    53   @see BioAssaySetUtil#createJepRestriction(DbControl, BioAssaySet, String)
     53  @see BioAssaySetUtil#createJepRestriction(DbControl, BioAssaySet, String, boolean)
    5454*/
    5555public class InReporterListFunction
  • trunk/src/core/net/sf/basedb/util/jep/NotInReporterListFunction.java

    r2981 r2993  
    5151  @base.modified $Date$
    5252  @see Jep
    53   @see BioAssaySetUtil#createJepRestriction(DbControl, BioAssaySet, String)
     53  @see BioAssaySetUtil#createJepRestriction(DbControl, BioAssaySet, String, boolean)
    5454*/
    5555public class NotInReporterListFunction
  • trunk/src/core/net/sf/basedb/util/jep/RawFunction.java

    r2981 r2993  
    2626import net.sf.basedb.core.BaseException;
    2727import net.sf.basedb.core.BioAssaySet;
     28import net.sf.basedb.core.PermissionDeniedException;
    2829import net.sf.basedb.core.RawDataType;
    2930import net.sf.basedb.core.DbControl;
     
    7273  @base.modified $Date$
    7374  @see Jep
    74   @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String)
     75  @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String, boolean)
    7576*/
    7677public class RawFunction
     
    8182  private final Metadata<RawData> metaData;
    8283  private final DbControl dc;
     84  private final boolean allowUse;
    8385  private int numParameters;
    8486  private RawData rawData;
     
    9092    @see Jep#formulaToExpression(String, JepFunction[])
    9193  */
    92   public RawFunction()
     94  public RawFunction(boolean allowUse)
    9395  {
    9496    this.dc = null;
    9597    this.metaData = null;
    9698    this.rawDataType = null;
     99    this.allowUse = allowUse;
    97100  }
    98101 
     
    102105    @param rawDataType The type of raw data this function uses
    103106  */
    104   public RawFunction(DbControl dc, RawDataType rawDataType)
     107  public RawFunction(DbControl dc, RawDataType rawDataType, boolean allowUse)
    105108  {
    106109    this.dc = dc;
    107110    this.rawDataType = rawDataType;
    108111    this.metaData = Metadata.getInstance(RawData.class, rawDataType.getEntityName());
     112    this.allowUse = allowUse;
    109113  }
    110114 
     
    131135  public Expression toExpression(Node node)
    132136  {
     137    if (!allowUse)
     138    {
     139      throw new PermissionDeniedException("Not allowed to use 'raw' function with merged data");
     140    }
    133141    int numChildren = node.jjtGetNumChildren();
    134142    if (numChildren != 1)
  • trunk/src/core/net/sf/basedb/util/jep/ReporterFunction.java

    r2981 r2993  
    7171  @base.modified $Date$
    7272  @see Jep
    73   @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String)
     73  @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String, boolean)
    7474*/
    7575public class ReporterFunction
  • trunk/src/core/net/sf/basedb/util/jep/ScoreFunction.java

    r2981 r2993  
    5252  @base.modified $Date$
    5353  @see Jep
    54   @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String)
     54  @see BioAssaySetUtil#createJepExpression(DbControl, BioAssaySet, String, boolean)
    5555*/
    5656public class ScoreFunction
  • trunk/src/plugins/core/net/sf/basedb/plugins/BioAssaySetExporter.java

    r2992 r2993  
    253253        {
    254254          ++aliasIndex;
    255           query.select(Selects.expression(BioAssaySetUtil.createJepExpression(dc, bas, field), aliasIndex.toString()));
     255          query.select(Selects.expression(BioAssaySetUtil.createJepExpression(dc, bas, field, true), aliasIndex.toString()));
    256256          aliases.put(field, aliasIndex.toString());
    257257        }
     
    259259        {
    260260          ++aliasIndex;
    261           query.select(Selects.expression(BioAssaySetUtil.createJepExpression(dc, bas, field),
     261          query.select(Selects.expression(BioAssaySetUtil.createJepExpression(dc, bas, field, true),
    262262            aliasIndex.toString()));
    263263          aliases.put(field, aliasIndex.toString());
  • trunk/src/plugins/core/net/sf/basedb/plugins/FormulaFilter.java

    r2981 r2993  
    176176     
    177177      // Parse filter expression
    178       Restriction filter = BioAssaySetUtil.createJepRestriction(dc, source, expression);
     178      Restriction filter = BioAssaySetUtil.createJepRestriction(dc, source, expression, false);
    179179
    180180      if (includeLimit != null || excludeLimit != null)
  • trunk/src/plugins/core/net/sf/basedb/plugins/JepExtraValueCalculator.java

    r2733 r2993  
    160160      query.select(Dynamic.select(VirtualColumn.COLUMN));
    161161      query.select(Dynamic.select(VirtualColumn.POSITION));
    162       Expression extraExpression = BioAssaySetUtil.createJepExpression(dc, source, expression);
     162      Expression extraExpression = BioAssaySetUtil.createJepExpression(dc, source, expression, false);
    163163      query.select(Selects.expression(extraExpression, "xtra"));
    164164
  • trunk/src/plugins/core/net/sf/basedb/plugins/JepIntensityTransformer.java

    r2722 r2993  
    171171        if (expression != null)
    172172        {
    173           chExpression = BioAssaySetUtil.createJepExpression(dc, source, expression);
     173          chExpression = BioAssaySetUtil.createJepExpression(dc, source, expression, false);
    174174        }
    175175        else
  • trunk/src/plugins/core/net/sf/basedb/plugins/LowessNormalization.java

    r2749 r2993  
    388388        message = "Lowess normalization requires 2-channel data, not " + channels + "-channel.";
    389389      }
     390      if (bas.getMaxRawMappingsForSpot() != 1)
     391      {
     392        message = "Lowess normalization can't be done on merged data.";
     393      }
    390394    }
    391395    return message;
  • trunk/src/plugins/core/net/sf/basedb/plugins/MedianRatioNormalization.java

    r2749 r2993  
    373373        message = "Normalization requires 2-channel data, not " + channels + "-channel.";
    374374      }
     375      if (bas.getMaxRawMappingsForSpot() != 1)
     376      {
     377        message = "Normalization can't be done on merged data.";
     378      }
    375379    }
    376380    return message;
  • trunk/src/test/TestExperiment.java

    r2959 r2993  
    570570      RawDataType rdt = e.getRawDataType();
    571571      String[] formulas = rdt.getIntensityFormula(intensityFormulaName).getExpressions();
    572       RawFunction raw = new RawFunction(dc, e.getRawDataType());
     572      RawFunction raw = new RawFunction(dc, e.getRawDataType(), true);
    573573      Expression ch1 = Jep.formulaToExpression(formulas[0], raw);
    574574      Expression ch2 = Jep.formulaToExpression(formulas[1], raw);
  • trunk/src/test/TestJep.java

    r2304 r2993  
    7171    try
    7272    {
    73       Jep.newJep(formula, new RawFunction(null, RawDataTypes.getRawDataType("genepix")));
     73      Jep.newJep(formula, new RawFunction(null, RawDataTypes.getRawDataType("genepix"), true));
    7474      write("--Parse formula: "+formula+" OK");
    7575    }
     
    8686    try
    8787    {
    88       Expression e = Jep.formulaToExpression(formula, new RawFunction(null, RawDataTypes.getRawDataType("genepix")));
     88      Expression e = Jep.formulaToExpression(formula, new RawFunction(null, RawDataTypes.getRawDataType("genepix"), true));
    8989      write(e);
    9090      write("--Jep to Expression: "+formula+" OK");
     
    102102    try
    103103    {
    104       Restriction r = Jep.formulaToRestriction(formula, new RawFunction(null, RawDataTypes.getRawDataType("genepix")));
     104      Restriction r = Jep.formulaToRestriction(formula,
     105        new RawFunction(null, RawDataTypes.getRawDataType("genepix"), true));
    105106      write(r);
    106107      write("--Jep to Restriction: "+formula+" OK");
  • trunk/www/common/expression_builder.jsp

    r2978 r2993  
    6868  {
    6969    BioAssaySet bas = bioAssaySetId == -1 ? null : BioAssaySet.getById(dc, bioAssaySetId);
     70    int maxRawMappings = bas == null ? 1 : bas.getMaxRawMappingsForSpot();
    7071
    7172    List<TableColumn> spotProperties = new LinkedList<TableColumn>();
     
    7475    if (rawDataType != null)
    7576    {
    76       DynamicUtil.addFormulaColumns(spotProperties, dc, rawDataType, Formula.Type.COLUMN_EXPRESSION, "", "");
     77      DynamicUtil.addFormulaColumns(spotProperties, dc, rawDataType, Formula.Type.COLUMN_EXPRESSION, "", "", maxRawMappings == 1);
    7778      if (bas != null) DynamicUtil.addExtraColumns(spotProperties, dc, bas, "", "", "[Xtra] ");
    78       DynamicUtil.addRawDataColumns(rawProperties, dc, rawDataType, "", "", "");
     79      if (maxRawMappings == 1) DynamicUtil.addRawDataColumns(rawProperties, dc, rawDataType, "", "", "");
    7980    }
    8081    List<TableColumn> reporterProperties = new LinkedList<TableColumn>();
     
    206207    function raw(property)
    207208    {
     209      <%
     210      if (maxRawMappings != 1)
     211      {
     212        %>
     213        throw 'Cannot use function raw() for bioassayset that has multiple mappings to raw data';
     214        <%
     215      }
     216      %>
    208217      var rdt = '<%=rawDataType == null ? "" : rawDataType.getId()%>';
    209218      if (!property) throw 'Property must be specified for function raw()';
     
    412421          </td>
    413422          <%
    414           if (rawDataType != null && rawDataType.isStoredInDb())
     423          if (rawDataType != null && rawDataType.isStoredInDb() && rawProperties.size() > 0)
    415424          {
    416425            %>
  • trunk/www/plugins/net/sf/basedb/plugins/jep_extra_value_calculator.jsp

    r2978 r2993  
    7575  if (source == null) throw new WebException("popup", "No current bioassay set",
    7676    "Could not find any current bioassay set. Please select a bioassay set before trying again");
     77  int maxRawMappings = source.getMaxRawMappingsForSpot();
    7778
    7879  RawDataType rdt = source.getRawDataType();
     
    9192  for (Formula f : formulas)
    9293  {
    93     addFormulaOption(formulaOptions, f.getFormula(0), f.getName(), f.getDescription());
     94    String formula = f.getFormula(0);
     95    if (maxRawMappings == 1 || !formula.contains("raw("))
     96    {
     97      addFormulaOption(formulaOptions, formula, f.getName(), f.getDescription());
     98    }
    9499  }
    95100 
    96101  // Load recently used items
    97102  List<ExtraValueType> recentExtraValueTypes = (List<ExtraValueType>)cc.getRecent(dc, Item.EXTRAVALUETYPE);
    98  
    99103  %>
    100104  <base:page type="popup" title="Calculate extra value">
     
    143147    function openExpressionBuilder()
    144148    {
    145       Main.expressionBuilder('<%=ID%>', 'Expression', 'extraValue', 'parameter:expression', 'COLUMN_EXPRESSION', '<%=rdt.getId()%>', <%=rdt.getChannels()%>, false);
     149      Main.expressionBuilder('<%=ID%>', 'Expression', 'extraValue', 'parameter:expression', 'COLUMN_EXPRESSION', '<%=rdt.getId()%>', <%=rdt.getChannels()%>, false, <%=source.getId()%>);
    146150    }
    147151    function validate()
     
    159163        return false;
    160164      }
     165      <%
     166      if (maxRawMappings != 1)
     167      {
     168        %>
     169        else if (frm['parameter:expression'].value.search(/raw\(/) != -1)
     170        {
     171          alert('Can\'t use function raw() for bioassaysets with multiple mappings to raw data');
     172          frm['parameter:expression'].focus();
     173          return false;
     174        }
     175        <%
     176      }
     177      %>
    161178      return true;
    162179    }
  • trunk/www/plugins/net/sf/basedb/plugins/jep_filter.jsp

    r2978 r2993  
    8282  RawDataType rdt = source.getRawDataType();
    8383  long numBioAssays = source.getBioAssays().count(dc);
     84  int maxRawMappings = source.getMaxRawMappingsForSpot();
    8485 
    8586  // Find selected bioassays
     
    117118  for (Formula f : formulas)
    118119  {
    119     addFormulaOption(formulaOptions, f.getFormula(0), f.getName(), f.getDescription());
     120    String formula = f.getFormula(0);
     121    if (maxRawMappings == 1 || !formula.contains("raw("))
     122    {
     123      addFormulaOption(formulaOptions, formula, f.getName(), f.getDescription());
     124    }
    120125  }
    121126  %>
     
    167172        return false;
    168173      }
     174      <%
     175      if (maxRawMappings != 1)
     176      {
     177        %>
     178        else if (frm['parameter:expression'].value.search(/raw\(/) != -1)
     179        {
     180          alert('Can\'t use function raw() for bioassayset with multiple mappings to raw data');
     181          frm['parameter:expression'].focus();
     182          return false;
     183        }
     184        <%
     185      }
     186      %>
    169187      else if (exclude != '' || include != '')
    170188      {
  • trunk/www/plugins/net/sf/basedb/plugins/jep_intensity_transformer.jsp

    r2978 r2993  
    7070  if (source == null) throw new WebException("popup", "No current bioassay set",
    7171    "Could not find any current bioassay set. Please select a bioassay set before trying again");
     72  int maxRawMappings = source.getMaxRawMappingsForSpot();
    7273
    7374  RawDataType rdt = source.getRawDataType();
     
    110111    function openExpressionBuilder(title, inputName)
    111112    {
    112       Main.expressionBuilder('<%=ID%>', title, 'transformation', inputName, 'INTENSITY_TRANSFORMATION', '<%=rdt.getId()%>', <%=rdt.getChannels()%>, false);
     113      Main.expressionBuilder('<%=ID%>', title, 'transformation', inputName, 'INTENSITY_TRANSFORMATION', '<%=rdt.getId()%>', <%=rdt.getChannels()%>, false, '<%=source.getId()%>');
    113114    }
    114115    function validate()
     
    124125          return false;
    125126        }
     127        else if (<%=maxRawMappings != 1 ? "true" : "false"%> && frm[inputName].value.search(/raw\(/) != -1)
     128        {
     129          alert('Can\'t use function raw() for bioassaysets with multiple mappings to raw data');
     130          frm[inputName].focus();
     131          return false;
     132        }
    126133      }
    127134      return true;
     
    144151        for (int ch = 1; ch <= rdt.getChannels(); ++ch)
    145152        {
     153          String formula = f.getFormula(ch-1);
    146154          %>
    147           formulas['<%=f.getId()%>.<%=ch%>'] = '<%=HTML.javaScriptEncode(f.getFormula(ch-1))%>';
     155          formulas['<%=f.getId()%>.<%=ch%>'] = '<%=HTML.javaScriptEncode(formula)%>';
    148156          <%
    149157        }
     
    234242            for (Formula f : formulas)
    235243            {
    236               %>
    237               <option value="<%=f.getId()%>" title="<%=HTML.encodeTags(f.getDescription())%>"
    238                 ><%=HTML.encodeTags(f.getName())%>
    239               <%
     244              boolean ok = true;
     245              if (maxRawMappings != 1)
     246              {
     247                for (String formula : f.getFormulas())
     248                {
     249                  ok &= !formula.contains("raw(");
     250                }
     251              }
     252              if (ok)
     253              {
     254                %>
     255                <option value="<%=f.getId()%>" title="<%=HTML.encodeTags(f.getDescription())%>"
     256                  ><%=HTML.encodeTags(f.getName())%>
     257                <%
     258              }
    240259            }
    241260            %>
  • trunk/www/views/experiments/bioassaysets/index.jsp

    r2978 r2993  
    6969<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    7070<%!
    71   private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,transformation,spots,reporters,date,tools");
     71  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,spots,reporters,date,tools");
    7272  private static final Item itemType = Item.BIOASSAYSET;
    7373 
  • trunk/www/views/experiments/explorer/view/view.jsp

    r2978 r2993  
    104104  final int channels = rawDataType.getChannels();
    105105  final boolean hasRatio = channels == 2;
     106  final int maxRawMappings = bioAssaySet.getMaxRawMappingsForSpot();
    106107 
    107108  final ExperimentExplorer explorer = ExperimentExplorer.getExplorer(bioAssaySet);
     
    111112 
    112113  List<TableColumn> columns = new LinkedList<TableColumn>();
    113   DynamicUtil.addFormulaColumns(columns, dc, rawDataType, Formula.Type.COLUMN_EXPRESSION, "frm.", "");
     114  DynamicUtil.addFormulaColumns(columns, dc, rawDataType, Formula.Type.COLUMN_EXPRESSION,
     115    "frm.", "", maxRawMappings == 1);
    114116  DynamicUtil.addExtraColumns(columns, dc, bioAssaySet, "ev", "#", "[Xtra] ");
    115   DynamicUtil.addRawDataColumns(columns, dc, rawDataType, "raw.", "$", "[Raw] ");
    116   columns.add(new TableColumn("raw.spotimage", "$id", "raw('id')", Type.INT,
    117     "[Raw] Spotimage", "", "auto", false, false, false, false,
    118     new SpotImageFormatter(dc, rawDataType, root)));
     117  if (maxRawMappings == 1)
     118  {
     119    DynamicUtil.addRawDataColumns(columns, dc, rawDataType, "raw.", "$", "[Raw] ");
     120    columns.add(new TableColumn("raw.spotimage", "$id", "raw('id')", Type.INT,
     121      "[Raw] Spotimage", "", "auto", false, false, false, false,
     122      new SpotImageFormatter(dc, rawDataType, root)));
     123  }
    119124
    120125  final int matchingReporters = explorer.getMatchingReporters(dc);
  • trunk/www/views/experiments/plotter/index.jsp

    r2978 r2993  
    7878  RawDataType rdt = bas.getRawDataType();
    7979  Experiment experiment = bas.getExperiment();
     80  int maxRawMappings = bas.getMaxRawMappingsForSpot();
    8081 
    8182  List<TableColumn> formulas = new LinkedList<TableColumn>();
    8283  DynamicUtil.addSpotColumns(formulas, dc, rdt.getChannels());
    83   DynamicUtil.addFormulaColumns(formulas, dc, rdt, Formula.Type.COLUMN_EXPRESSION, "", "");
     84  DynamicUtil.addFormulaColumns(formulas, dc, rdt, Formula.Type.COLUMN_EXPRESSION, "", "", maxRawMappings == 1);
    8485  DynamicUtil.addExtraColumns(formulas, dc, bas, "ev", "#", "[Xtra] ");
    85   DynamicUtil.addRawDataColumns(formulas, dc, rdt, "", "", "[Raw] ");
     86  if (maxRawMappings == 1)
     87  {
     88    DynamicUtil.addRawDataColumns(formulas, dc, rdt, "", "", "[Raw] ");
     89  }
    8690 
    8791  StringBuilder formulaOptions = new StringBuilder();
     
    9094    if (tc.getJepExpression() != null && tc.getDatatype().isNumerical())
    9195    {
    92       addFormulaOption(formulaOptions, tc.getJepExpression(), tc.getTitle(), tc.getDescription());
     96      String jepExpression = tc.getJepExpression();
     97      addFormulaOption(formulaOptions, jepExpression, tc.getTitle(), tc.getDescription());
    9398    }
    9499  }
     
    100105  for (Formula formula : formulaQuery.list(dc))
    101106  {
    102     addFormulaOption(filterOptions, formula.getFormulas().get(0),
    103       formula.getName(), formula.getDescription());
     107    String f = formula.getFormulas().get(0);
     108    if (maxRawMappings == 1 || !f.contains("raw("))
     109    {
     110      addFormulaOption(filterOptions, f,
     111        formula.getName(), formula.getDescription());
     112    }
    104113  }
    105114 
  • trunk/www/views/experiments/spotdata/list_spotdata.jsp

    r2978 r2993  
    9797  List<TableColumn> columns = new LinkedList<TableColumn>();
    9898  DynamicUtil.addSpotColumns(columns, dc, rawDataType.getChannels());
    99   DynamicUtil.addFormulaColumns(columns, dc, rawDataType, Formula.Type.COLUMN_EXPRESSION, "frm.", "");
     99  DynamicUtil.addFormulaColumns(columns, dc, rawDataType, Formula.Type.COLUMN_EXPRESSION, "frm.", "", true);
    100100  DynamicUtil.addExtraColumns(columns, dc, bioAssaySet, "ev", "#", "[Xtra] ");
    101101  DynamicUtil.addRawDataColumns(columns, dc, rawDataType, "raw.", "$", "[Raw] ");
Note: See TracChangeset for help on using the changeset viewer.