Changeset 1575


Ignore:
Timestamp:
Nov 7, 2005, 4:05:24 PM (18 years ago)
Author:
Nicklas Nordborg
Message:

Added IntensityCalculatorUtil? and other classes needed by it:
IntensityCalculator?, IntensityFormula?
Added Java Math Expression Parser package
Changed raw-data-types.xml file and it's dtd

Location:
trunk
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/base2.license.txt

    r1478 r1575  
    4444* This product includes software developed by the
    4545  The JDOM(TM) Project (http://www.jdom.org)
     46
     47* This product includes software developed by
     48  Singular Systems (http://www.singularsys.com/)
  • trunk/doc/3rd-party-components.txt

    r1478 r1575  
    134134            commons-collections-2.1.1.jar, commons-logging-1.0.4.jar
    135135
     136
     137Java Math Expression Parser
     138---------------------------
     139Parses and evaluates mathematical expressions in string. Supports
     140most operators and funcations as well as variables.
     141
     142More info : http://www.singularsys.com/jep/
     143Version   : 2.3.0
     144License   : GPL (gpl.license.txt)
     145Jar files : jep-2.3.0.jar
     146
  • trunk/src/core/net/sf/basedb/core/RawDataType.java

    r1544 r1575  
    2525package net.sf.basedb.core;
    2626import java.util.List;
    27 import java.util.ArrayList;
     27import java.util.Map;
     28import java.util.HashMap;
    2829import java.util.Collections;
    2930
     
    5152  private final String table;
    5253  private final List<RawDataProperty> properties;
     54  private final Map<String, RawDataProperty> namedProperties;
     55  private final List<IntensityFormula> formulas;
     56  private final Map<String, IntensityFormula> namedFormulas;
    5357 
    5458  private final RealTable realTable;
     
    5963  */
    6064  RawDataType(String id, String name, String description, int channels,
    61     String table, List<RawDataProperty> properties)
     65    String table, List<RawDataProperty> properties, List<IntensityFormula> formulas)
    6266  {
    6367    this.id = id;
     
    6771    this.table = table;
    6872    this.properties = Collections.unmodifiableList(properties);
     73    this.formulas = formulas;
    6974    this.realTable = new RealTable(table, "raw");
     75   
     76    this.namedProperties = new HashMap<String, RawDataProperty>(properties.size());
     77    for (RawDataProperty property : properties)
     78    {
     79      if (namedProperties.put(property.getName(), property) != null)
     80      {
     81        throw new BaseException("RawDataProperty[name="+property.getName()+"] is already defined for raw data type: "+name);
     82      }
     83    }
     84    this.namedFormulas = new HashMap<String, IntensityFormula>(formulas.size());
     85    for (IntensityFormula formula : formulas)
     86    {
     87      if (namedFormulas.put(formula.getName(), formula) != null)
     88      {
     89        throw new BaseException("IntensityFormula[name="+formula.getName()+"] is already defined for raw data type: "+name);
     90      }
     91    }
     92   
    7093  }
    7194
     
    157180    return properties;
    158181  }
     182 
     183  public RawDataProperty getProperty(String name)
     184  {
     185    return namedProperties.get(name);
     186  }
     187
     188  public List<IntensityFormula> getIntensityFormulas()
     189  {
     190    return formulas;
     191  }
     192 
     193  public IntensityFormula getIntensityFormula(String name)
     194  {
     195    return namedFormulas.get(name);
     196  }
    159197
    160198}
  • trunk/src/core/net/sf/basedb/core/RawDataTypes.java

    r1136 r1575  
    130130      int channels = XMLUtil.getIntAttribute(el, "channels", 2);
    131131      List<RawDataProperty> properties = loadProperties(el);
    132       RawDataType rdt = new RawDataType(id, name, description, channels, table, properties);
     132      List<IntensityFormula> formulas = loadIntensityFormulas(el, channels);
     133      RawDataType rdt = new RawDataType(id, name, description, channels, table, properties, formulas);
    133134      rawDataTypes.put(id, rdt);
    134135    }
     
    159160    return properties;
    160161  }
     162 
     163  /**
     164    Load the intensity formulas for the specified raw data type node and
     165    return a list of {@link IntensityFormula} objects.
     166  */
     167  @SuppressWarnings({"unchecked"})
     168  private static List<IntensityFormula> loadIntensityFormulas(Element rawDataTypeElement, int channels)
     169  {
     170    List<IntensityFormula> formulas = new ArrayList<IntensityFormula>();
     171    List<Element> children = rawDataTypeElement.getChildren("intensity-formula");
     172    for (Element formula : children)
     173    {
     174      String name = formula.getAttributeValue("name");
     175      String title = formula.getAttributeValue("title");
     176      if (title == null) title = name;
     177      String description = formula.getAttributeValue("description");
     178      String[] expressions = new String[channels];
     179      for (Element expression :  (List<Element>)formula.getChildren("formula"))
     180      {
     181        int channel = XMLUtil.getIntAttribute(expression, "channel", 0);
     182        if (channel <= 0 || channel > channels)
     183        {
     184          throw new BaseException("Invalid channel number for expression: "+expression);
     185        }
     186        if (expressions[channel-1] != null)
     187        {
     188          throw new BaseException("Expression for channel "+channel+" has already been defined: " +expression);
     189        }
     190        expressions[channel-1] = expression.getAttributeValue("expression");
     191      }
     192      formulas.add(new IntensityFormula(name, title, description, expressions));
     193    }
     194    return formulas;
     195  }
     196 
    161197}
  • trunk/src/core/net/sf/basedb/core/dtd/raw-data-types.dtd

    r1108 r1575  
    2525<!ELEMENT raw-data-types (raw-data-type+) >
    2626
    27 <!ELEMENT raw-data-type (property+) >
     27<!ELEMENT raw-data-type (property+,intensity-formula*) >
    2828
    2929<!ATTLIST raw-data-type
     
    4747  channel CDATA #IMPLIED
    4848>
     49
     50<!ELEMENT intensity-formula (formula+) >
     51
     52<!ATTLIST intensity-formula
     53  name CDATA #REQUIRED
     54  title CDATA #IMPLIED
     55  description CDATA #IMPLIED
     56>
     57
     58<!ELEMENT formula EMPTY >
     59
     60<!ATTLIST formula
     61  channel CDATA #REQUIRED
     62  expression CDATA #REQUIRED
     63>
  • trunk/src/install/includes

    r1478 r1575  
    7070CP=$CP:$WEBINF/lib/jai_core.jar
    7171CP=$CP:$WEBINF/lib/mlibwrapper_jai.jar
     72
     73# Java Math Expression Parser
     74CP=$CP:$WEBINF/lib/jep-2.3.0.jar
     75
  • trunk/src/install/initdb.bat

    r1478 r1575  
    7171SET CP=%CP%;%WEBINF%/lib/mlibwrapper_jai.jar
    7272
     73REM Java Math Expression Parser
     74SET CP=%CP%;%WEBINF%/lib/jep-2.3.0.jar
     75
     76
    7377REM Execute install class
    7478java -cp %CP% net.sf.basedb.install.InitDB %1 %2 %3 %4 %5 %6 %7 %8 %9
  • trunk/src/raw-data-types.xml

    r1108 r1575  
    243243      type="float"
    244244    />
    245 
     245    <intensity-formula
     246      name="mean"
     247      title="Mean FG - Mean BG"
     248      description="Subtract mean background from mean foreground"
     249      >
     250      <formula
     251        channel="1"
     252        expression="ch1FgMean - ch1BgMean"
     253      />
     254      <formula
     255        channel="2"
     256        expression="ch2FgMean - ch2BgMean"
     257      />
     258    </intensity-formula>
     259    <intensity-formula
     260      name="median"
     261      title="Median FG - Median BG"
     262      description="Subtract meadian background from median foreground"
     263      >
     264      <formula
     265        channel="1"
     266        expression="ch1FgMedian - ch1BgMedian"
     267      />
     268      <formula
     269        channel="2"
     270        expression="ch2FgMedian - ch2BgMedian"
     271      />
     272    </intensity-formula>
    246273  </raw-data-type>
    247274
  • trunk/src/test/TestExperiment.java

    r1567 r1575  
    3434import net.sf.basedb.core.query.Selects;
    3535
     36import net.sf.basedb.util.IntensityCalculatorUtil;
     37import net.sf.basedb.util.IntensityCalculator;
     38
    3639import java.util.Date;
    3740import java.util.Set;
     
    8285    test_list_rawbioassays(id, 2);
    8386   
    84     int rootBasId = test_create_root_bioassayset(id, rbaId1, rbaId2);
     87    int rootBasId = test_create_root_bioassayset(id, "mean", rbaId1, rbaId2);
    8588    int filterBasId = test_filter_bioassayset(rootBasId);
    8689    int basId = test_create_bioassayset(filterBasId);
     
    413416  }
    414417 
    415   static int test_create_root_bioassayset(int experimentId, int... rawBioAssays)
     418
     419  static int test_create_root_bioassayset(int experimentId, String intensityFormulaName, int... rawBioAssays)
    416420  {
    417421    if (experimentId == 0) return 0;
    418422    int id = 0;
    419423    DbControl dc = null;
     424    long time;
    420425    try
    421426    {
     
    429434      }
    430435     
    431       Transformation t = e.newTransformation(null, rbaCollection);
    432       BioAssaySet bas = t.newProduct(null, null);
    433       bas.setName("Root bioassayset");
    434       dc.saveItem(t);
    435       dc.saveItem(bas);
    436 
    437       boolean first = true;
    438       PositionBatcher posBatcher = bas.getPositionBatcher();
    439       SpotBatcher spotBatcher = bas.getSpotBatcher();
    440       MappingBatcher rawBatcher = bas.getMappingBatcher();
    441       int numSpots = 0;
    442       for (RawBioAssay rba : rbaCollection)
    443       {
    444         BioAssay ba = bas.newRootBioAssay(Collections.singleton(rba));
    445         short column = ba.getDataCubeColumnNo();
    446         DataResultIterator<RawData> rawData = rba.getRawData().iterate(dc);
    447         while (rawData.hasNext())
    448         {
    449           RawData rd = rawData.next();
    450           int position = rd.getPosition();
    451           float[] intensities = new float[2];
    452           intensities[0] = (Float)rd.getExtended("ch1FgMean") - (Float)rd.getExtended("ch1BgMean");
    453           intensities[1] = (Float)rd.getExtended("ch2FgMean") - (Float)rd.getExtended("ch2BgMean");
    454           if (first)
    455           {
    456             posBatcher.insert(position, rd.getReporter());
    457           }
    458           rawBatcher.insert(column, position, rd);
    459           spotBatcher.insert(column, position, intensities);
    460           numSpots++;
    461         }
    462         dc.saveItem(ba);
    463         first = false;
    464       }
    465       posBatcher.close();
    466       spotBatcher.close();
    467       rawBatcher.close();
    468 
     436      RawDataType rdt = e.getRawDataType();
     437      IntensityCalculator iCalc = IntensityCalculatorUtil.createJepIntensityCalculator(
     438        rdt, rdt.getIntensityFormula(intensityFormulaName).getExpressions());
     439     
     440      time = System.currentTimeMillis();
     441      BioAssaySet root = IntensityCalculatorUtil.createRootBioAssaySet(
     442        dc, e, rbaCollection, null, iCalc);
    469443      dc.commit();
    470       id = bas.getId();
    471       dc = TestUtil.getDbControl();
    472       dc.reattachItem(bas);
    473       write_item(0, bas);
    474       write("--Create root bioassayset OK ("+numSpots+" spots inserted)");
     444     
     445      time = System.currentTimeMillis()-time;
     446      int numSpots = root.getNumSpots();
     447      id = root.getId();
     448      dc = TestUtil.getDbControl();
     449      dc.reattachItem(root);
     450      write_item(0, root);
     451      write("--Create root bioassayset OK ("+numSpots+" spots inserted; "+time+" ms)");
    475452    }
    476453    catch (Throwable ex)
     
    486463    return id;
    487464  }
    488 
     465 
    489466  static int test_create_bioassayset(int bioAssaySetId)
    490467  {
  • trunk/src/test/run.bat

    r1478 r1575  
    6464SET CP=%CP%;../../lib/compile/mlibwrapper_jai.jar
    6565
     66REM Java Math Expression Parser
     67SET CP=%CP%;../../lib/compile/jep-2.3.0.jar
     68
    6669REM Execute test class
    6770java -ea -cp %CP% %1 %2 %3 %4 %5 %6 %7 %8 %9
  • trunk/src/test/run.sh

    r1478 r1575  
    6363CP=$CP:../../lib/compile/mlibwrapper_jai.jar
    6464
     65# Java Math Expression Parser
     66CP=$CP:../../lib/compile/jep-2.3.0.jar
     67
    6568# Execute test class
    6669java -ea -cp $CP $*
Note: See TracChangeset for help on using the changeset viewer.