Changeset 5886


Ignore:
Timestamp:
Nov 23, 2011, 2:32:22 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #1616: Clone reporter information to per-experiment tables in the dynamic database

Added possibility to clone reporters based on all reporters that are references by raw data in the experiment.

Allow a "null" template to be used which means that all reporter properties are cloned.

Added some more tests to the test programs.

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/test/roles/index.html

    r5813 r5886  
    698698    <p>
    699699  </li>
     700
     701  <li>
     702    Create a reporter clone template:
     703    <table class="listing" cellspacing="0" cellpadding="2" border="0">
     704    <tr>
     705      <th>Name</th>
     706      <th>Properties</th>
     707    </tr>
     708    <tr>
     709      <td>Template A</td>
     710      <td>External ID, ID, Version, Sequence, Gene symbol</td>
     711    </tr>
     712    </table>
     713    <p>
     714  </li>
    700715 
    701716  <li>
     
    22222237   
    22232238  <li>
    2224     Go to the <code>Experiment A</code> experiment and select
    2225     the <code>Bioassay sets</code> tab.
    2226     <p>
    2227   </li>
    2228  
    2229   <li>
    2230     Create a new root bioassay set:
     2239    Go to the <code>Experiment A</code> experiment.
     2240    <p>
     2241  </li>
     2242 
     2243  <li>
     2244    Clone the reporters:
     2245    <table class="listing" cellspacing="0" cellpadding="2" border="0">
     2246    <tr>
     2247      <th>Clone template</th>
     2248      <th>Clone source</th>
     2249    </tr>
     2250    <tr>
     2251      <td>Template A</td>
     2252      <td>Raw data</td>
     2253    </tr>
     2254    </table>
     2255    Click on "Next" and wait for the plug-in to finish. It should
     2256    report that 35,912 reporters has been cloned.
     2257    <p>
     2258  </li>
     2259 
     2260  <li>
     2261    Switch to the "Bioassay sets" tab. Create a new root bioassay set:
    22312262    <table class="listing" cellspacing="0" cellpadding="2" border="0">
    22322263    <tr>
  • trunk/src/clients/web/net/sf/basedb/clients/web/DynamicUtil.java

    r5885 r5886  
    131131  }
    132132
    133   public static void addReporterColumns(List<TableColumn> columns, DbControl dc, String idPrefix, String propertyPrefix, String titlePrefix)
    134   {
    135     SessionControl sc = dc.getSessionControl();
    136     Formatter<String> stringFormatter = FormatterFactory.getStringFormatter(sc);
    137     Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
    138     Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
    139     columns.add(new TableColumn(idPrefix + "id", propertyPrefix+"id", "rep('id')",
    140       Type.INT, titlePrefix + "Internal ID", "Reporter internal ID", "auto", true, true, true,
    141       Formula.AverageMethod.NONE, null));
    142     columns.add(new TableColumn(idPrefix + "name", propertyPrefix+"name", "rep('name')",
    143       Type.STRING, titlePrefix + "Name", "Reporter name", "auto", true, true, true,
    144       Formula.AverageMethod.NONE, stringFormatter));
    145     columns.add(new TableColumn(idPrefix + "externalId", propertyPrefix+"externalId", "rep('externalId')",
    146       Type.STRING, titlePrefix + "External ID", "Reporter ID", "auto", true, true, true,
    147       Formula.AverageMethod.NONE, stringFormatter));
    148     columns.add(new TableColumn(idPrefix + "symbol", propertyPrefix+"symbol", "rep('symbol')",
    149       Type.STRING, titlePrefix + "Gene symbol", "Gene symbol", "auto", true, true, true,
    150       Formula.AverageMethod.NONE, stringFormatter));
    151     columns.add(new TableColumn(idPrefix + "description", propertyPrefix+"description", "rep('description')",
    152       Type.STRING, titlePrefix + "Description", "Reporter description", "auto", true, true, true,
    153       Formula.AverageMethod.NONE, stringFormatter));
    154     columns.add(new TableColumn(idPrefix + "entryDate", propertyPrefix+"entryDate", "rep('entryDate')",
    155         Type.DATE, titlePrefix + "Registered", "Registered", "auto", true, true, true,
    156         Formula.AverageMethod.NONE, dateFormatter));
    157     columns.add(new TableColumn(idPrefix + "lastUpdate", propertyPrefix+"lastUpdate", "rep('lastUpdate')",
    158       Type.TIMESTAMP, titlePrefix + "Last update", "Last updateded", "auto", true, true, true,
    159       Formula.AverageMethod.NONE, dateTimeFormatter));
    160 
    161     List<ExtendedProperty> extended = ExtendedProperties.getProperties("ReporterData");
    162     if (extended != null)
    163     {
    164       for (ExtendedProperty ep : extended)
    165       {
    166         String name = ep.getName();
    167         TableColumn tc = new TableColumn(idPrefix + name, propertyPrefix + name, "rep('"+name+"')",
    168           ep.getType(), titlePrefix + ep.getTitle(), ep.getDescription(), "auto", true, true, true,
    169           ep.getAverageMethod(), FormatterFactory.getExtendedPropertyFormatter(sc, ep));
    170         columns.add(tc);
    171       }
    172     }
     133  public static void addReporterColumns(List<TableColumn> columns, DbControl dc,
     134    String idPrefix, String propertyPrefix, String titlePrefix)
     135  {
     136    addReporterColumns(columns, dc, null, idPrefix, propertyPrefix, titlePrefix);
    173137  }
    174138 
     
    176140      String idPrefix, String propertyPrefix, String titlePrefix)
    177141  {
    178     if (template == null)
    179     {
    180       addReporterColumns(columns, dc, idPrefix, propertyPrefix, titlePrefix);
    181       return;
    182     }
    183     SessionControl sc = dc.getSessionControl();
    184     for (ClonableProperty cp : template.getClonableProperties())
     142    List<ClonableProperty> properties = template == null ?
     143      ClonableProperty.getAll() : template.getClonableProperties();
     144   
     145    SessionControl sc = dc.getSessionControl();
     146    for (ClonableProperty cp : properties)
    185147    {
    186148      String name = cp.getName();
  • trunk/src/core/net/sf/basedb/core/ClonableProperty.java

    r5885 r5886  
    129129    else if (SYMBOL.equals(name))
    130130    {
    131       property = new ClonableProperty(SYMBOL, "Symbol", "The gene symbol for the reporter", "symbol",
     131      property = new ClonableProperty(SYMBOL, "Gene symbol", "The gene symbol for the reporter", "symbol",
    132132        Type.STRING, ReporterData.MAX_SYMBOL_LENGTH, NULLABLE, AverageMethod.NONE, !MANDATORY);
    133133    }
     
    355355  */
    356356  /**
    357     Sort mandatory properties before, nonmadatory.
     357    Sort by title, but mandatory properties before non-madatory.
    358358  */
    359359  @Override
     
    364364      return isMandatory() ? -1 : 1;
    365365    }
    366     return getName().compareTo(o.getName());
     366    return getTitle().compareTo(o.getTitle());
    367367  }
    368368  // -----------------------------
  • trunk/src/core/net/sf/basedb/core/DynamicRawDataQuery.java

    r4889 r5886  
    2323package net.sf.basedb.core;
    2424
     25import java.util.HashSet;
     26import java.util.Set;
     27
     28import net.sf.basedb.core.query.Dynamic;
     29import net.sf.basedb.core.query.JoinType;
    2530import net.sf.basedb.core.query.Select;
    2631
     
    4651{
    4752
    48   private final RawBioAssay rawBioAssay;
    4953  private final RawDataType rawDataType;
    5054  private final RealTable rootTable;
     55  private final Set<Object> joinedItems;
     56  private RawBioAssay rawBioAssay;
    5157
    5258  /**
     
    5662  DynamicRawDataQuery(RawBioAssay rawBioAssay)
    5763  {
    58     super(rawBioAssay.getRawDataType().getRealTable().getQualifiedTableName());
    59     this.rawDataType = rawBioAssay.getRawDataType();
     64    this(rawBioAssay.getRawDataType());
    6065    this.rawBioAssay = rawBioAssay;
     66  }
     67 
     68  /**
     69    Create a new dynamic query for raw data.
     70    @param rawDataType The raw data type
     71    @since 3.1
     72  */
     73  DynamicRawDataQuery(RawDataType rawDataType)
     74  {
     75    super(rawDataType.getRealTable().getQualifiedTableName());
     76    this.rawDataType = rawDataType;
    6177    this.rootTable = rawDataType.getRealTable();
     78    joinedItems = new HashSet<Object>();
    6279    if (!rawDataType.isStoredInDb())
    6380    {
     
    112129  }
    113130 
     131  /**
     132    Join information about reporters in the query.
     133    @param joinType The type of join. Can not be null.
     134    @throws InvalidDataException If joinType parameter is null.
     135    @see Dynamic#selectReporter(String)
     136    @see Dynamic#reporter(String)
     137    @since 3.1
     138  */
     139  public void joinReporters(JoinType joinType)
     140  {
     141    if (joinType == null) throw new InvalidUseOfNullException("joinType");
     142    if (!joinedItems.contains(RealTable.REPORTERS))
     143    {
     144      join(new RealJoin(joinType, getRootTable(), RealTable.REPORTERS, "reporter_id"));
     145      joinedItems.add(RealTable.REPORTERS);
     146    }
     147  }
     148
    114149}
  • trunk/src/core/net/sf/basedb/core/RealJoin.java

    r5320 r5886  
    3434/**
    3535  Represents a join from one virtual table in the dynamic database to
    36   a table in the regular database.
     36  a table in the regular database or between two tables in the
     37  regular database.
    3738  <code>virtualTable vt JOIN regularTable rt ON rt.id = vt.leftColumn</code>.
    3839  <p>
    39   Note that the join is always done to the id of the items in the regular table.
     40  Note that the join is always done to the 'id' of the items in the regular table.
    4041
    4142  @author Nicklas
     
    4950 
    5051  private final JoinType joinType;
    51   private final VirtualTable left;
    5252  private final RealTable right;
    53   private final VirtualColumn leftColumn;
    54  
    55   /**
    56     Create a new join to a regular table.
     53   
     54  private VirtualTable vLeft;
     55  private VirtualColumn vLeftColumn;
     56 
     57  private RealTable rLeft;
     58  private String rLeftColumn;
     59 
     60  /**
     61    Create a new join between a virtual and a regular table.
    5762    <code><i>SELECT ... FROM left</i> JOIN right ON right.id = left.column</code>.
    5863
     
    6772  {
    6873    this.joinType = joinType;
    69     this.left = left;
    7074    this.right = right;
    71     this.leftColumn = leftColumn;
     75    this.vLeft = left;
     76    this.vLeftColumn = leftColumn;
     77  }
     78
     79  /**
     80    Create a new join between two regular tables.
     81    <code><i>SELECT ... FROM left</i> JOIN right ON right.id = left.column</code>.
     82 
     83    @param joinType The type of join
     84    @param left The left table to join from, if not specified we join
     85      from the root table
     86    @param right The table to join to
     87    @param leftColumn The column in the left table to join from, we always
     88      join to the id of the real table
     89  */
     90  RealJoin(JoinType joinType, RealTable left, RealTable right, String leftColumn)
     91  {
     92    this.joinType = joinType;
     93    this.right = right;
     94    this.rLeft = left;
     95    this.rLeftColumn = leftColumn;
    7296  }
    7397
     
    81105    if (query.getQueryType() == QueryType.SQL)
    82106    {
    83       String leftAlias = left == null ? query.getRootAlias() : left.getAlias();
     107      String leftAlias = getLeftTableAlias(query);
    84108      String rightAlias = right.getAlias();
    85109     
     
    89113      sb.append(" ON ");
    90114     
    91       String qualifiedLeftColumn = HibernateUtil.quote(leftColumn.getColumn());
     115      String qualifiedLeftColumn = HibernateUtil.quote(getLeftTableColumn());
    92116      sb.append(rightAlias).append(".id = ").append(leftAlias).append(".").append(qualifiedLeftColumn);
    93117      return sb.toString();
     
    131155    if (query.getQueryType() == QueryType.SQL)
    132156    {
    133       String leftAlias = left == null ? query.getRootAlias() : HibernateUtil.quote(left.getAlias());
     157      String leftAlias = getLeftTableAlias(query);
    134158      String rightAlias = HibernateUtil.quote(right.getAlias());
    135159      StringBuilder sb = new StringBuilder();
    136160
    137       String qualifiedColumn = HibernateUtil.quote(leftColumn.getColumn());
     161      String qualifiedColumn = HibernateUtil.quote(getLeftTableColumn());
    138162      sb.append(leftAlias).append(".").append(qualifiedColumn);
    139163      sb.append(" = ").append(rightAlias).append(".").append(HibernateUtil.quote("id"));
     
    155179  {
    156180    return joinType.getJoinExpression()+" "+right.getTableName()+" AS "+right.getAlias()+
    157       " ON "+right.getAlias() + ".id = " + (left == null ? "" : left.getAlias() + ".") + leftColumn.getName();
     181      " ON "+right.getAlias() + ".id = " + getLeftTableAlias(null) + "." + getLeftTableColumn();
    158182  }
    159183  /**
     
    167191    if (other == null || this.getClass() != other.getClass()) return false;
    168192    RealJoin o = (RealJoin)other;
    169     return left == o.left && right == o.right && joinType == o.joinType &&
    170       EqualsHelper.equals(leftColumn, o.leftColumn);
     193    return vLeft == o.vLeft && rLeft == o.rLeft && right == o.right && joinType == o.joinType &&
     194      EqualsHelper.equals(vLeftColumn, o.vLeftColumn) && EqualsHelper.equals(rLeftColumn, o.rLeftColumn);
    171195  }
    172196  @Override
    173197  public int hashCode()
    174198  {
    175     return EqualsHelper.hashCode(left, right, joinType, leftColumn);
     199    return EqualsHelper.hashCode(vLeft, rLeft, right, joinType, vLeftColumn, rLeftColumn);
    176200  }
    177201  // -------------------------------------------
    178202
    179  
     203  private String getLeftTableAlias(Query query)
     204  {
     205    String alias = "";
     206    if (vLeft != null)
     207    {
     208      alias = vLeft.getAlias();
     209    }
     210    else if (rLeft != null)
     211    {
     212      alias = rLeft.getAlias();
     213    }
     214    else if (query != null)
     215    {
     216      alias = query.getRootAlias();
     217    }
     218    return alias;
     219  }
     220 
     221  private String getLeftTableColumn()
     222  {
     223    String column = null;
     224    if (vLeftColumn != null)
     225    {
     226      column = vLeftColumn.getColumn();
     227    }
     228    else
     229    {
     230      column = rLeftColumn;
     231    }
     232    return column;
     233  }
    180234}
  • trunk/src/core/net/sf/basedb/core/ReporterCloneBatcher.java

    r5885 r5886  
    2424import java.sql.PreparedStatement;
    2525import java.sql.SQLException;
     26import java.util.HashSet;
    2627import java.util.List;
    27 
     28import java.util.Set;
     29
     30import net.sf.basedb.core.data.RawBioAssayData;
    2831import net.sf.basedb.core.data.ReporterCloneTemplateData;
     32import net.sf.basedb.core.data.UserData;
    2933import net.sf.basedb.core.query.Dynamic;
     34import net.sf.basedb.core.query.Expressions;
    3035import net.sf.basedb.core.query.JoinType;
    3136import net.sf.basedb.core.query.Orders;
     37import net.sf.basedb.core.query.Restrictions;
    3238import net.sf.basedb.core.query.Selects;
    3339import net.sf.basedb.core.query.SqlResult;
     
    174180    Create a reporter clone table in the dynamic database for this
    175181    experiment and populate it with the current reporter annotations
    176     for all reporters that are part of the experiment. This method will
    177     create an immutable copy of the template so that we can always know
     182    for all reporters that are part of the experiment.
     183    <p>
     184   
     185    To find out which reporters that are part of the experiment, the batcher
     186    can use either what has already been inserted into the {@link VirtualTable#POSITION}
     187    table (source={@link CloneSource#VIRTUAL}) or the reporters that are referenced
     188    by the {@link RawBioAssay}:s attached to the experiment (source={@link CloneSource#RAW}).
     189    The AUTO method uses the position table if it exists. The RAW method can't be used
     190    with raw data types that doesn't store raw data in the database.
     191   
     192    <p>
     193    This method will create an immutable copy of the template so that we can always know
    178194    which fields that have been cloned, even if the template is modified.
    179195    If there already is a cloned reporter information it will be removed.
    180    
    181     @param template The reporter clone template to use
     196    <p>
     197   
     198   
     199    @param template The reporter clone template to use or null to clone
     200      all properties
     201    @param source The source of the cloned reporters, null is the same as AUTO
    182202    @param progress An optional progress reporter
    183203    @return The number of cloned reporters
     
    187207      or read permission for reporters
    188208  */
    189   public int cloneReporters(ReporterCloneTemplate template, ProgressReporter progress)
    190   {
    191     if (template == null) throw new InvalidUseOfNullException("template");
     209  public int cloneReporters(CloneSource source, ReporterCloneTemplate template,
     210    ProgressReporter progress)
     211  {
    192212    // Permission checks
    193213    experiment.checkPermission(Permission.WRITE);
    194     template.checkPermission(Permission.USE);
     214    if (template != null) template.checkPermission(Permission.USE);
    195215    if (!getSessionControl().hasPermission(Permission.READ, Item.REPORTER))
    196216    {
    197217      throw new PermissionDeniedException(Permission.READ, "Reporter");
    198218    }
     219   
     220    if (source == null) source = CloneSource.AUTO;
     221    if (source == CloneSource.VIRTUAL)
     222    {
     223      if (!virtualDb.hasTable(VirtualTable.POSITION))
     224      {
     225        throw new InvalidDataException("Can't use VIRTUAL as source since there is no position-to-reporter data");
     226      }
     227    }
     228    if (source == CloneSource.AUTO)
     229    {
     230      if (virtualDb.hasTable(VirtualTable.POSITION))
     231      {
     232        source = CloneSource.VIRTUAL;
     233      }
     234      else
     235      {
     236        source = CloneSource.RAW;
     237      }
     238    }
     239    if (source == CloneSource.RAW)
     240    {
     241      if (!experiment.getRawDataType().isStoredInDb())
     242      {
     243        throw new InvalidDataException("Can't use RAW as source since raw data is not stored in database");
     244      }
     245    }
     246   
    199247   
    200248    DbControl dc = getDbControl();
     
    204252   
    205253    // Create a copy of the template
    206     ReporterCloneTemplateData copy = template.createLockedCopy();
     254    ReporterCloneTemplateData copy = template != null ?
     255      template.createLockedCopy() : ReporterCloneTemplate.createAllCopy("All");
     256    copy.setOwner(HibernateUtil.loadData(dc.getHibernateSession(), UserData.class, dc.getSessionControl().getLoggedInUserId()));
    207257    virtualDb.getData().setReporterCloneTemplate(copy);
    208258    HibernateUtil.saveData(dc.getHibernateSession(), copy);
     
    219269    try
    220270    {
    221       DynamicPositionQuery query = buildSelectQuery();
    222       long totalCount = query.count(dc);
     271      boolean useRawData = source == CloneSource.RAW;
     272     
     273      DynamicPositionQuery query = useRawData ? null : buildSelectQuery();
     274      DynamicRawDataQuery rawQuery = useRawData ? buildRawSelectQuery() : null;
     275     
     276      long totalCount = query != null ? query.count(dc) : rawQuery.count(dc);
    223277      int interval = (int)(totalCount / 50);
    224278      if (interval < 10) interval = 10;
     
    230284      PreparedStatement insertSql = buildInsertSql();
    231285   
    232       DynamicResultIterator it = query.iterate(dc);
     286      System.out.println("sql: " + (query != null ? query.toQl(dc) : rawQuery.toQl(dc)));
     287     
     288      DynamicResultIterator it = query != null ? query.iterate(dc) : rawQuery.iterate(dc);
    233289      while (it.hasNext())
    234290      {
     
    338394  }
    339395 
    340 
     396  private DynamicRawDataQuery buildRawSelectQuery()
     397  {
     398    List<ClonableProperty> cloned = virtualDb.getReporterCloneTemplate().getClonableProperties();
     399    parameterTypes = new int[cloned.size()+1];
     400
     401    DynamicRawDataQuery query = new DynamicRawDataQuery(experiment.getRawDataType());
     402    query.joinReporters(JoinType.INNER);
     403    query.setDistinct(true);
     404    query.order(Orders.asc(Dynamic.reporter("id")));
     405
     406    Set<Integer> ids = new HashSet<Integer>();
     407    for (RawBioAssayData rba : experiment.getData().getRawBioAssays())
     408    {
     409      ids.add(rba.getId());
     410    }
     411   
     412    query.restrict(Restrictions.in(Dynamic.rawData("rawBioAssay"), Expressions.parameter("rawBioAssays")));
     413    query.setParameter("rawBioAssays", ids, Type.INT);
     414   
     415    int index = 1;
     416    for (ClonableProperty cp : cloned)
     417    {
     418      query.select(Selects.expression(Dynamic.reporter(cp.getName()), "cp" + index, cp.getName().equals(ClonableProperty.ID)));
     419      parameterTypes[index] = cp.getType().getTypeWrapper().getSQLType();
     420      index++;
     421    }
     422
     423    return query;
     424  }
     425
     426  /**
     427    Specifies which source table to use for finding out which reporters
     428    that are part of the current experiment.
     429  */
     430  public static enum CloneSource
     431  {
     432    /**
     433      Select VIRTUAL if the experiment has position data in the virtual database,
     434      otherwise the RAW options used.
     435    */
     436    AUTO,
     437    /**
     438      Use the raw data for all raw bioassays in the experiment as the source for reporters.
     439    */
     440    RAW,
     441    /**
     442      Use the position-to-reporter mapping in the experiment.
     443    */
     444    VIRTUAL
     445   
     446  }
     447 
    341448}
  • trunk/src/core/net/sf/basedb/core/ReporterCloneTemplate.java

    r5885 r5886  
    3131import net.sf.basedb.core.data.ReporterClonePropertyData;
    3232import net.sf.basedb.core.data.ReporterCloneTemplateData;
     33import net.sf.basedb.core.data.UserData;
    3334import net.sf.basedb.core.query.Expressions;
    3435import net.sf.basedb.core.query.Hql;
     
    336337    Create a deep clone of this template. Modifications made to the template
    337338    after this call do not affect the copy. The returned copy is locked and
    338     cannot be modifed.
     339    cannot be modifed. Properties that are part of the original template,
     340    but no longer exists are not copied.
    339341  */
    340342  ReporterCloneTemplateData createLockedCopy()
     
    348350   
    349351    Map<String, ReporterClonePropertyData> propertiesCopy = copy.getProperties();
    350     for (Map.Entry<String, ReporterClonePropertyData> entry : getData().getProperties().entrySet())
    351     {
    352       ClonableProperty cp = new ClonableProperty(entry.getKey(), entry.getValue());
     352    List<ClonableProperty> all = ClonableProperty.getAll();
     353    for (ClonableProperty cp : all)
     354    {
     355      if (hasClonableProperty(cp.getName()))
     356      {
     357        propertiesCopy.put(cp.getName(), cp.toData());
     358      }
     359    }
     360    return copy;
     361  }
     362 
     363  static ReporterCloneTemplateData createAllCopy(String name)
     364  {
     365    ReporterCloneTemplateData copy = new ReporterCloneTemplateData();
     366    copy.setName(name);
     367    copy.setLocked(true);
     368    copy.setEntryDate(new Date());
     369   
     370    Map<String, ReporterClonePropertyData> propertiesCopy = copy.getProperties();
     371    List<ClonableProperty> all = ClonableProperty.getAll();
     372    for (ClonableProperty cp : all)
     373    {
    353374      propertiesCopy.put(cp.getName(), cp.toData());
    354375    }
    355376    return copy;
     377   
    356378  }
    357379 
  • trunk/src/plugins/core/net/sf/basedb/plugins/CloneReportersPlugin.java

    r5878 r5886  
    3636import net.sf.basedb.core.ReporterCloneBatcher;
    3737import net.sf.basedb.core.ReporterCloneTemplate;
     38import net.sf.basedb.core.ReporterCloneBatcher.CloneSource;
    3839import net.sf.basedb.core.plugin.AbstractPlugin;
    3940import net.sf.basedb.core.plugin.Permissions;
     
    4647/**
    4748  A plug-in that clone reporter annotations to an experiment. To use, create
    48   a {@link Job} and make sure the {@link Job#getExperiment()} is set, the
    49   set "template" parameter to a {@link ReporterCloneTemplate} item.
     49  a {@link Job} and make sure the {@link Job#getExperiment()} is set.
     50  Set the "template" parameter to a {@link ReporterCloneTemplate} item to use
     51  that as template for the cloning operation, or use null to clone all reporter
     52  annotations. Set the "cloneSource" parameter to a name from the {@link CloneSource}
     53  enumeration to use a specific reporter source.
    5054
    5155  @author Nicklas
     
    110114      Experiment experiment = theJob.getExperiment();
    111115      ReporterCloneTemplate template = dc.loadItem((ReporterCloneTemplate)job.getValue("template"));
     116      String tmp = (String)job.getValue("cloneSource");
     117      CloneSource source = tmp == null ? CloneSource.AUTO : CloneSource.valueOf(tmp);
    112118      ReporterCloneBatcher batcher = experiment.getReporterCloneBatcher(dc);
    113       int numReporters = batcher.cloneReporters(template, progress);
     119      int numReporters = batcher.cloneReporters(source, template, progress);
    114120      if (theJob.getDescription() != null)
    115121      {
  • trunk/src/test/TestReporterCloneTemplate.java

    r5885 r5886  
    2424import net.sf.basedb.core.ClonableProperty;
    2525import net.sf.basedb.core.DbControl;
     26import net.sf.basedb.core.DynamicReporterQuery;
     27import net.sf.basedb.core.DynamicResultIterator;
    2628import net.sf.basedb.core.Experiment;
    2729import net.sf.basedb.core.ExtendedProperties;
     
    3133import net.sf.basedb.core.ItemResultList;
    3234import net.sf.basedb.core.Permission;
     35import net.sf.basedb.core.Reporter;
    3336import net.sf.basedb.core.ReporterCloneBatcher;
    3437import net.sf.basedb.core.ReporterCloneTemplate;
     38import net.sf.basedb.core.ReporterCloneBatcher.CloneSource;
     39import net.sf.basedb.core.query.Dynamic;
     40import net.sf.basedb.core.query.SqlResult;
    3541import net.sf.basedb.util.ConsoleProgressReporter;
    3642
     
    7783      }
    7884
    79       test_clone_reporters(id, experimentId);
    80       //test_list_cloned_reporters(experimentId);
    81      
     85      test_clone_reporters(id, experimentId, CloneSource.VIRTUAL, 572);
     86      test_list_cloned_reporters(experimentId);
     87
     88      test_clone_reporters(id, experimentId, CloneSource.RAW, 572);
     89      test_list_cloned_reporters(experimentId);
     90
    8291      // Standard test: Delete
    8392      if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
     
    235244  }
    236245
    237   static void test_clone_reporters(int id, int experimentId)
     246  static void test_clone_reporters(int id, int experimentId, CloneSource source, int numClonedExpected)
    238247  {
    239248    if (id == 0 || experimentId == 0) return;
     
    242251    {
    243252      dc = TestUtil.getDbControl();
    244       ReporterCloneTemplate rct = ReporterCloneTemplate.getById(dc, id);
     253      ReporterCloneTemplate template = ReporterCloneTemplate.getById(dc, id);
    245254      Experiment exp = Experiment.getById(dc, experimentId);
    246255     
    247256      ReporterCloneBatcher batcher = exp.getReporterCloneBatcher(dc);
    248       batcher.cloneReporters(rct, TestUtil.getSilent() ? null : new ConsoleProgressReporter());
     257      int numCloned = batcher.cloneReporters(source, template,
     258        TestUtil.getSilent() ? null : new ConsoleProgressReporter());
     259      if (numCloned != numClonedExpected && numClonedExpected >= 0)
     260      {
     261        throw new BaseException("Expected "+numClonedExpected+" reporters, not "+numCloned);
     262      }
    249263     
    250264      dc.commit();
     
    291305  }
    292306
     307  static void test_list_cloned_reporters(int experimentId)
     308  {
     309    if (experimentId == 0) return;
     310    DbControl dc = null;
     311    try
     312    {
     313      dc = TestUtil.getDbControl();
     314      Experiment exp = Experiment.getById(dc, experimentId);
     315     
     316      DynamicReporterQuery query = Reporter.getDynamicQuery(exp);
     317      ReporterCloneTemplate template = exp.getVirtualDb().getReporterCloneTemplate();
     318     
     319      StringBuilder header = new StringBuilder("  ");
     320      int numProperties = 0;
     321      for (ClonableProperty cp : template.getClonableProperties())
     322      {
     323        header.append("\t").append(cp.getTitle());
     324        query.select(Dynamic.selectReporter(cp.getName()));
     325        numProperties++;
     326      }
     327      if (!TestUtil.getSilent())
     328      {
     329        write(header.toString());
     330        write(header.toString().replaceAll("[^\t]", "-"));
     331      }
     332     
     333      DynamicResultIterator it = query.iterate(dc);
     334      int num = 1;
     335      while (it.hasNext() && num < 50)
     336      {
     337        SqlResult row = it.next();
     338        StringBuilder data = new StringBuilder();
     339        data.append(num);
     340        for (int index = 1; index <= numProperties; index++)
     341        {
     342          data.append("\t").append(row.getString(index));
     343        }
     344        num++;
     345        if (!TestUtil.getSilent()) write(data.toString());
     346      }
     347      dc.commit();
     348      write("--List cloned reporters OK");
     349    }
     350    catch (Throwable ex)
     351    {
     352      write("--List cloned FAILED");
     353      ex.printStackTrace();
     354      ok = false;
     355    }
     356    finally
     357    {
     358      if (dc != null) dc.close();
     359    }
     360  }
     361
    293362}
  • trunk/src/test/net/sf/basedb/test/roles/AnalysisTest.java

    r5813 r5886  
    3232import net.sf.basedb.core.ItemParameterType;
    3333import net.sf.basedb.core.Job;
     34import net.sf.basedb.core.Permission;
    3435import net.sf.basedb.core.PluginDefinition;
    3536import net.sf.basedb.core.Project;
    3637import net.sf.basedb.core.RawBioAssay;
    3738import net.sf.basedb.core.RawDataTypes;
     39import net.sf.basedb.core.ReporterCloneTemplate;
    3840import net.sf.basedb.core.StringParameterType;
    3941import net.sf.basedb.test.PluginUtil;
     
    7274      dc = TestUtil.getDbControl();
    7375      Experiment experiment = Util.findExperiment(dc, "Experiment A");
     76      boolean hasClonedReporters = experiment.getVirtualDb().hasClonedReporters();
    7477      Experiment affyExperiment = Util.findExperiment(dc, "Affymetrix A");
    7578      Experiment seqExperiment = Util.findExperiment(dc, "Sequence A");
     
    100103      Formula fpkmFormula = Util.findFormula(dc, RawDataTypes.getSafeRawDataType("cufflinks"),
    101104          Formula.Type.INTENSITY_EXPRESSION, "FPKM");
     105
     106      ReporterCloneTemplate template = Util.findReporterCloneTemplate(dc, "Template A");
    102107      dc.close();
     108     
     109      if (!hasClonedReporters && experiment.hasPermission(Permission.WRITE))
     110      {
     111        cloneReporters(experiment, template);
     112      }
    103113     
    104114      BioAssaySet root = createRootBioAssaySet(experiment,
     
    131141  }
    132142
     143  /**
     144    Clone reporter annotations to the experiment dynamic database using the given template.
     145    @since 3.1
     146  */
     147  public static void cloneReporters(Experiment experiment, ReporterCloneTemplate template)
     148  {
     149    TestUtil.write("--Cloning reporters in " + experiment.getName() + " using template: " + template.getName() + "\n");
     150    DbControl dc = TestUtil.getDbControl();
     151    try
     152    {
     153      PluginDefinition plugin = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.CloneReportersPlugin");
     154      experiment = Experiment.getById(dc, experiment.getId());
     155      Job job = Job.getNew(dc, plugin, null, experiment);
     156      job.setName("Cloning reporters: " + template.getName());
     157      job.setParameterValue("template",
     158        new ItemParameterType<ReporterCloneTemplate>(ReporterCloneTemplate.class, null), template);
     159      dc.saveItem(job);
     160      dc.commit();
     161      PluginUtil.executeJob(job);
     162    }
     163    finally
     164    {
     165      if (dc != null) dc.close();
     166    }
     167  }
     168 
    133169  /**
    134170    Create a root bioassay set.
  • trunk/src/test/net/sf/basedb/test/roles/PowerUserTest.java

    r5827 r5886  
    3333import net.sf.basedb.core.BioPlateType;
    3434import net.sf.basedb.core.BioWell;
     35import net.sf.basedb.core.ClonableProperty;
    3536import net.sf.basedb.core.DataFileType;
    3637import net.sf.basedb.core.DbControl;
     
    5758import net.sf.basedb.core.RawDataType;
    5859import net.sf.basedb.core.RawDataTypes;
     60import net.sf.basedb.core.ReporterCloneTemplate;
    5961import net.sf.basedb.core.Software;
    6062import net.sf.basedb.core.StringParameterType;
     
    161163      Software cufflinks = Util.findSoftware(dc, "Cufflinks");
    162164      Software topHat = Util.findSoftware(dc, "TopHat");
    163      
     165
     166      ReporterCloneTemplate cloneTemplate = createReporterCloneTemplate(dc, "Template A", "externalId", "symbol", "sequence");
     167
    164168      PlateType plateType = createPlateType(dc, "Plate type A", 16, 24);
    165169      BioPlateType bioPlateType = createBioPlateType(dc, "Bioplate type A", null, BioWell.LockMode.UNLOCKED);
     
    188192      PluginDefinition arrayBatchImporter = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.batchimport.ArrayBatchImporter");
    189193      PluginDefinition arraySlideImporter = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.batchimport.ArraySlideImporter");
    190            
     194     
    191195      dc.commit();
    192196     
     
    345349 
    346350  /**
     351    Create a reporter clone template.
     352  */
     353  public static ReporterCloneTemplate createReporterCloneTemplate(DbControl dc, String name, String... properties)
     354  {
     355    TestUtil.write("--Creating reporter clone template: " + name + "\n");
     356    ReporterCloneTemplate t = ReporterCloneTemplate.getNew(dc);
     357    t.setName(name);
     358    if (properties != null)
     359    {
     360      for (String property : properties)
     361      {
     362        t.addClonableProperty(ClonableProperty.create(property));
     363      }
     364    }
     365    dc.saveItem(t);
     366    return t;
     367  }
     368 
     369  /**
    347370    Create a hardware.
    348371  */
  • trunk/src/test/net/sf/basedb/test/roles/Util.java

    r5778 r5886  
    5151import net.sf.basedb.core.RawBioAssay;
    5252import net.sf.basedb.core.RawDataType;
     53import net.sf.basedb.core.ReporterCloneTemplate;
    5354import net.sf.basedb.core.Role;
    5455import net.sf.basedb.core.Sample;
     
    300301
    301302  /**
     303    Find a reporter clone template with a matching name.
     304    @since 3.1
     305  */
     306  public static ReporterCloneTemplate findReporterCloneTemplate(DbControl dc, String name)
     307  {
     308    ItemQuery<ReporterCloneTemplate> query = ReporterCloneTemplate.getQuery();
     309    query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(name)));
     310    query.include(Include.SHARED);
     311    return query.list(dc).get(0);
     312  }
     313 
     314  /**
    302315    Returns the first raw bioassay that was found with a certain name
    303316   */
  • trunk/www/views/experiments/clone_reporters.jsp

    r5878 r5886  
    2828  import="net.sf.basedb.core.Permission"
    2929  import="net.sf.basedb.core.Experiment"
     30  import="net.sf.basedb.core.VirtualDb"
     31  import="net.sf.basedb.core.VirtualTable"
    3032  import="net.sf.basedb.core.ReporterCloneTemplate"
    3133  import="net.sf.basedb.core.ItemQuery"
     
    6567  Experiment experiment = Experiment.getById(dc, itemId);
    6668  experiment.checkPermission(Permission.WRITE);
     69  VirtualDb virtualDb = experiment.getVirtualDb();
     70  boolean canCloneFromRaw = experiment.getRawDataType().isStoredInDb();
     71  boolean canCloneFromVirtual = virtualDb.hasTable(VirtualTable.POSITION);
     72 
     73  if (!canCloneFromRaw && !canCloneFromVirtual)
     74  {
     75    throw new BaseException("Can't clone reporters for experiment since it has no raw data or analyzed data");
     76  }
    6777 
    6878  List<ReporterCloneTemplate> recentTemplates = (List<ReporterCloneTemplate>)cc.getRecent(dc, Item.REPORTERCLONETEMPLATE);
    69 
    7079 
    7180  final String clazz = "class=\"text\"";
     
    104113      var frm = document.forms['clone'];
    105114      var url = '../../admin/reporterclonetemplates/index.jsp?ID=<%=ID%>&mode=selectone&callback=setTemplateCallback';
    106       if (frm.reporterclonetemplate_id.length > 0)
     115      if (frm.reporterclonetemplate_id.length > 1)
    107116      {
    108117        var id = Math.abs(parseInt(frm.reporterclonetemplate_id[0].value));       
     
    115124      var frm = document.forms['clone'];
    116125      var list = frm.reporterclonetemplate_id;
    117       if (list.length < 1 || list[0].value == '0') // >
    118       {
    119         Forms.addListOption(list, 0, new Option());
    120       }
    121       list[0].value = id;
    122       list[0].text = name;
    123       list.selectedIndex = 0;
     126      if (list.length < 2 || list[1].value == '0') // >
     127      {
     128        Forms.addListOption(list, 1, new Option());
     129      }
     130      list[1].value = id;
     131      list[1].text = name;
     132      list.selectedIndex = 1;
    124133    }
    125134
     
    137146
    138147    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
    139     <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*280)+"px;"%>"
     148    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*360)+"px;"%>"
    140149      position="bottom" remember="true">
    141150    <t:tab id="info" title="Experiment" validate="validateExperiment()" helpid="experiment.edit">
     
    148157            id="reporterclonetemplate_id"
    149158            clazz="selectionlist"
    150             required="true"
     159            required="false"
    151160            current="<%=null%>"
    152161            denied="<%=false%>"
    153162            recent="<%=recentTemplates%>"
    154163            newitem="<%=false%>"
     164            unselectedtext="- all properties -"
    155165            onselect="selectTemplateOnClick()"
    156166          />
    157167        </td>
    158168      </tr>
     169      <tr>
     170        <td class="prompt">Clone source</td>
     171        <td>
     172          <select name="cloneSource">
     173          <%
     174          if (canCloneFromRaw && canCloneFromVirtual)
     175          {
     176            %>
     177            <option value="AUTO">Auto
     178            <%
     179          }
     180          if (canCloneFromVirtual)
     181          {
     182            %>
     183            <option value="VIRTUAL">Analyzed data
     184            <%
     185          }
     186          if (canCloneFromRaw)
     187          {
     188            %>
     189            <option value="RAW">Raw data
     190            <%
     191          }
     192          %>
     193          </select>
     194        </td>
     195      </tr>
     196     
    159197      <tr valign=top>
    160198        <td class="prompt">Description</td>
     
    175213    <table align="center">
    176214    <tr>
    177       <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
     215      <td width="50%"><base:button onclick="saveSettings()" title="Next" /></td>
    178216      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
    179217    </tr>
  • trunk/www/views/experiments/index.jsp

    r5878 r5886  
    2424  @version 2.0
    2525--%>
     26<%@page import="net.sf.basedb.core.StringParameterType"%>
    2627<%@ page pageEncoding="UTF-8" session="false"
    2728  import="net.sf.basedb.core.SessionControl"
     
    419420   
    420421    dc = sc.newDbControl();
    421     ReporterCloneTemplate template = ReporterCloneTemplate.getById(dc, Values.getInt(request.getParameter("reporterclonetemplate_id")));
    422     cc.setRecent(template, maxRecent);
     422    int templateId = Values.getInt(request.getParameter("reporterclonetemplate_id"));
     423    ReporterCloneTemplate template = null;
     424    if (templateId > 0)
     425    {
     426      template = ReporterCloneTemplate.getById(dc, templateId);
     427      cc.setRecent(template, maxRecent);
     428    }
    423429   
    424430    Experiment exp = Experiment.getById(dc, Values.getInt(itemId));
     
    426432    PluginDefinition clonePlugin = PluginDefinition.getByClassName(dc, CloneReportersPlugin.class.getName());
    427433    Job cloneJob = Job.getNew(dc, clonePlugin, null, exp);
    428     cloneJob.setName("Cloning reporters using template '" + template.getName() + "'");
     434    if (template == null)
     435    {
     436      cloneJob.setName("Cloning all reporter properties");
     437    }
     438    else
     439    {
     440      cloneJob.setName("Cloning reporters using template '" + template.getName() + "'");
     441    }
    429442    cloneJob.setDescription(Values.getStringOrNull(request.getParameter("description")));
    430443    cloneJob.setParameterValue("template", "Reporter clone template", null,
    431444      new ItemParameterType<ReporterCloneTemplate>(ReporterCloneTemplate.class, null), template);
     445    cloneJob.setParameterValue("cloneSource", "Clone source", null,
     446      new StringParameterType(), request.getParameter("cloneSource"));
    432447    dc.saveItem(cloneJob);
    433448    dc.commit();
  • trunk/www/views/experiments/view_experiment.jsp

    r5878 r5886  
    278278    function cloneReporters()
    279279    {
    280       Main.openPopup('clone_reporters.jsp?ID=<%=ID%>&item_id=<%=itemId%>', 'CloneReporters', 600, 500);
     280      Main.openPopup('clone_reporters.jsp?ID=<%=ID%>&item_id=<%=itemId%>', 'CloneReporters', 640, 480);
    281281    }
    282282    function removeClonedReporters()
     
    339339      />
    340340      <tbl:button
    341         visible="<%=writePermission && virtualDb.hasTable(VirtualTable.POSITION) %>"
     341        visible="<%=writePermission && (virtualDb.hasTable(VirtualTable.POSITION) || experiment.getRawDataType().isStoredInDb()) %>"
    342342        image="copy.gif"
    343343        onclick="cloneReporters()"
Note: See TracChangeset for help on using the changeset viewer.