Changeset 4212


Ignore:
Timestamp:
Apr 10, 2008, 12:53:41 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #957: Base1PluginExecuter doesn't import plug-in generated BASEfiles as expected

The new code is in place. Also added better test cases for the the four cases:

  1. No change in parent mapping
  2. Merge assays
  3. New positions
  4. New positions + merge assays

Probably needs more testing with real plug-ins. A bit unsure about the performance when remapping raw data for large experiments.

Location:
branches/2.6-stable
Files:
3 added
11 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/2.6-stable/build.xml

    r4194 r4212  
    848848      jarfile="${test.build}/JarPlugin.jar"
    849849      basedir="${test.build}"
    850       includes="JarPlugin*,NullPlugin*,Base1NullPlugin*"
     850      includes="JarPlugin*,NullPlugin*,Base1*"
    851851      excludes="JarPlugin.jar,JarPluginAbout.*"
    852852      manifest="${test.src}/data/JarPluginManifest.txt"
  • branches/2.6-stable/src/core/net/sf/basedb/core/data/RawData.java

    r4080 r4212  
    4646{
    4747
    48   RawData()
     48  public RawData()
    4949  {}
    5050
  • branches/2.6-stable/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r4121 r4212  
    3535import net.sf.basedb.core.DbControl;
    3636import net.sf.basedb.core.Directory;
     37import net.sf.basedb.core.DynamicQuery;
     38import net.sf.basedb.core.DynamicResultIterator;
     39import net.sf.basedb.core.DynamicSpotQuery;
    3740import net.sf.basedb.core.Experiment;
    3841import net.sf.basedb.core.ExtraValue;
     
    4851import net.sf.basedb.core.ItemQuery;
    4952import net.sf.basedb.core.Job;
     53import net.sf.basedb.core.MappingBatcher;
    5054import net.sf.basedb.core.Path;
    5155import net.sf.basedb.core.PathParameterType;
     
    5559import net.sf.basedb.core.PositionBatcher;
    5660import net.sf.basedb.core.ProgressReporter;
    57 import net.sf.basedb.core.Reporter;
    5861import net.sf.basedb.core.RequestInformation;
    5962import net.sf.basedb.core.SpotBatcher;
     
    6366import net.sf.basedb.core.Type;
    6467import net.sf.basedb.core.User;
     68import net.sf.basedb.core.VirtualColumn;
     69import net.sf.basedb.core.VirtualTable;
     70import net.sf.basedb.core.data.RawData;
    6571import net.sf.basedb.core.data.ReporterData;
    6672import net.sf.basedb.core.plugin.About;
     
    7278import net.sf.basedb.core.plugin.Request;
    7379import net.sf.basedb.core.plugin.Response;
     80import net.sf.basedb.core.query.Dynamic;
    7481import net.sf.basedb.core.query.Hql;
     82import net.sf.basedb.core.query.JoinType;
    7583import net.sf.basedb.core.query.Orders;
     84import net.sf.basedb.core.query.SqlResult;
    7685import net.sf.basedb.core.signal.SignalException;
    7786import net.sf.basedb.core.signal.SignalHandler;
    7887import net.sf.basedb.core.signal.SignalTarget;
    7988import net.sf.basedb.core.signal.ThreadSignalHandler;
     89import net.sf.basedb.util.Diff3;
    8090import net.sf.basedb.util.Enumeration;
    8191import net.sf.basedb.util.Values;
     
    13311341  /**
    13321342    Imports the data from the file stdout.txt in the execution directory.
    1333    
    1334     @return The id of the transformation the data is connected to.
    13351343    @throws IOException if there is any error reading from stdout.txt
    13361344  */
    1337   private int importData(DbControl dc, File stdout, Transformation t)
    1338     throws IOException
    1339   {
    1340     BioAssaySet bas = null;
    1341     SpotBatcher spotBatcher = null;
    1342     Boolean doPositionBatch = null;
    1343 
    1344     HashMap<String, BioAssay> idMap = new HashMap<String, BioAssay>();
    1345     HashMap<Integer, ReporterData> posRepMap = new HashMap<Integer, ReporterData>();
    1346     HashMap<String, ExtraValueType> evtMap = new HashMap<String, ExtraValueType>();
    1347 
     1345  private void importData(DbControl dc, File stdout, Transformation t)
     1346    throws SQLException, IOException
     1347  {
     1348   
     1349    // Position -> ReporterID mapping for the parent bioassay set
     1350    Map<Integer, Integer> parentReporterPositions = new HashMap<Integer, Integer>();
     1351    // Position -> ReporterID mapping for the child bioassay set
     1352    Map<Integer, Integer> childReporterPositions = new HashMap<Integer, Integer>();
     1353    // BioAssayID -> Column no mapping for the child bioassay set
     1354    Map<Integer, Short> bioAssayColumns = new HashMap<Integer, Short>();
     1355    // Column mapping from parent -> child bioassay
     1356    Map<Short, Short> columnMapping = new HashMap<Short, Short>();
     1357    // If the "assays" section contains a child->parent mapping for bioassays
     1358    boolean hasParentAssayMapping = false;
     1359    // If all position->reporter mappings are the same on the child and parent bioassay set
     1360    boolean hasSamePositionReporterMapping = true;
     1361    // If at least one spot section was found
     1362    boolean hasSpotSection = false;
     1363    // Information about child bioassays
     1364    Map<Integer, ChildBioAssay> childBioAssays = new HashMap<Integer, ChildBioAssay>();
     1365   
     1366    // Load the position -> reporter mapping from the parent bioassay set
     1367    BioAssaySet source = t.getSource();
     1368    DynamicQuery positionQuery = source.getPositionData();
     1369    positionQuery.select(Dynamic.select(VirtualColumn.POSITION));
     1370    positionQuery.select(Dynamic.select(VirtualColumn.REPORTER_ID));
     1371    DynamicResultIterator positionQueryIterator = positionQuery.iterate(dc);
     1372    while (positionQueryIterator.hasNext())
     1373    {
     1374      SqlResult result = positionQueryIterator.next();
     1375      parentReporterPositions.put(result.getInt(1), (Integer)result.getObject(2));
     1376    }
     1377   
     1378    // Parse the stdout file to verify child mappings
    13481379    FlatFileParser ffp = getInitializedFlatFileParser(stdout.getDownloadStream(0));
    1349    
    13501380    while (ffp.hasMoreSections())
    13511381    {
     1382      checkInterrupted();
    13521383      FlatFileParser.Line section = ffp.nextSection();
    13531384      ffp.parseHeaders();
    13541385     
    1355       if (section.name().equals("assays"))
    1356       {
    1357         bas = t.newProduct("new", "new", false);
    1358         doPositionBatch = true;
    1359         bas.setName(getSourceBioAssaySet(dc).getName());
     1386      if ("assays".equals(section.name()))
     1387      {
     1388        /*
     1389          Optional section
     1390          If it exists it must define 'id' and 'name' of child bioassays
     1391          The 'id' must be the same as the id of a parent bioassay,
     1392          UNLESS a 'parents' column is present
     1393        */
    13601394        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
    1361         int idCol = columns.indexOf("id");
    1362         int nameCol = columns.indexOf("name");
    1363         int parentCol = columns.indexOf("parents");
    1364 
     1395        int parentIndex = columns.indexOf("parents");
     1396        int idIndex = columns.indexOf("id");
     1397        int nameIndex = columns.indexOf("name");
     1398        hasParentAssayMapping =  parentIndex != -1;
     1399        if (idIndex == -1)
     1400        {
     1401          throw new BaseException("Missing column 'id' in section 'assays' at line "
     1402              + ffp.getParsedLines() + " in file '" + stdout.getName() + "'");
     1403        }
     1404        if (nameIndex == -1)
     1405        {
     1406          throw new BaseException("Missing column 'name' in section 'assays' at line "
     1407              + ffp.getParsedLines() + " in file '" + stdout.getName() + "'"); 
     1408        }
     1409       
     1410        // Read data part of the 'assays' section
     1411        // Each line has ID, NAME and PARENTS (optional)
    13651412        ffp.setMinDataColumns(columns.size());
    1366 
    1367         FlatFileParser.Data dataline = ffp.nextData();
    1368         while (dataline != null)
    1369         {
    1370           String id = dataline.get(idCol);
    1371           String name = dataline.get(nameCol);
    1372           Set<BioAssay> baParents;
    1373           if (parentCol > -1)
    1374           {
    1375             String[] parentIds;
    1376             parentIds = dataline.get(parentCol).split("/");
    1377             baParents = new HashSet<BioAssay>(parentIds.length);
    1378             for (String parent : parentIds)
    1379             {
    1380               baParents.add(BioAssay.getById(dc, new Integer(parent)));
    1381             }
    1382           }
    1383           else
    1384           {
     1413        FlatFileParser.Data data;
     1414        while ((data = ffp.nextData()) != null)
     1415        {
     1416          int assayId = Values.getInt(data.get(idIndex));
     1417         
     1418          // Don't allow duplicate assay ID:s
     1419          if (childBioAssays.containsKey(assayId))
     1420          {
     1421            throw new BaseException("Duplicate assay id (" + assayId +
     1422                ") found in section 'assays' at line " + ffp.getParsedLines() +
     1423                " in file '" + stdout.getName() + "'");
     1424          }
     1425         
     1426          // Extract name and parents and store as ChildBioAssay objects
     1427          String name = data.get(nameIndex);
     1428          Set<Integer> parents = null;
     1429          if (hasParentAssayMapping)
     1430          {
     1431            parents = new HashSet<Integer>(Arrays.asList(Values.getInt(data.get(parentIndex).split("/"))));
     1432            Integer parentId = null;           
    13851433            try
    13861434            {
    1387               baParents = Collections.singleton(BioAssay.getById(dc, Integer.parseInt(id)));
     1435              Iterator<Integer> it = parents.iterator();
     1436              while (it.hasNext())
     1437              {
     1438                parentId = it.next();
     1439                BioAssay.getById(dc, parentId);
     1440              }
    13881441            }
    1389             catch (ItemNotFoundException e)
     1442            catch (ItemNotFoundException ex)
    13901443            {
    1391               throw new BaseException("Couldn't find any parent for bioassay "+name, e);
     1444              throw new BaseException("Can't find parent bioassay '" + parentId +
     1445                "' in section 'assays' at line " + ffp.getParsedLines() + " in file '" +
     1446                stdout.getName() + "'"
     1447                );
    13921448            }
    13931449          }
    1394           BioAssay ba = bas.newBioAssay(baParents);
    1395           ba.setName(name);
    1396           idMap.put(id, ba);
    1397           dataline = ffp.nextData();
    1398         }
     1450          else
     1451          {
     1452            try
     1453            {
     1454              BioAssay.getById(dc, assayId);
     1455            }
     1456            catch (ItemNotFoundException ex)
     1457            {
     1458              throw new BaseException("Can't find bioassay '" + assayId +
     1459                "' in section 'assays' at line " + ffp.getParsedLines() + " in file '" +
     1460                stdout.getName() + "'"
     1461                );
     1462            }
     1463          }
     1464          childBioAssays.put(assayId, new ChildBioAssay(assayId, name, parents));
     1465        }
     1466      }
     1467      else if ("spots".equals(section.name()))
     1468      {
     1469        checkInterrupted();
     1470        /*
     1471          Required section. May appear more than once.
     1472          'position' and 'reporter' are required columns in the 'columns' header.
     1473          'assays' is a required column header, that has the ID of the assays
     1474          that have spot data in this section.
     1475        */
     1476        hasSpotSection = true;
     1477
     1478        // Get the "position" and "reporter" columns from the "column" header
     1479        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
     1480        int positionIndex = columns.indexOf("position");
     1481        int reporterIndex = columns.indexOf("reporter");
     1482
     1483        // Error if the columns are missing
     1484        if (positionIndex == -1)
     1485        {
     1486          throw new BaseException("Missing column 'position' in section 'spots' at line " +
     1487              ffp.getParsedLines() + " in file '" + stdout.getName() + "'");
     1488        }
     1489        if (reporterIndex == -1)
     1490        {
     1491          throw new BaseException("Missing column 'reporter' in section 'spots' at line " +
     1492              ffp.getParsedLines() + " in file '" + stdout.getName() + "'");
     1493        }
     1494
     1495        // Get the "assays" header
     1496        List<Integer> assays = Arrays.asList(Values.getInt(ffp.getHeader("assays").split("\\t")));
     1497        if (assays == null || assays.size() == 0)
     1498        {
     1499          throw new BaseException("Missing header 'assays' in section 'spots' at line " +
     1500              ffp.getParsedLines() + " in file '" + stdout.getName() + "'");
     1501        }
     1502       
     1503        for (Integer assayId : assays)
     1504        {
     1505          if (!childBioAssays.containsKey(assayId))
     1506          {
     1507            try
     1508            {
     1509              BioAssay.getById(dc, assayId);
     1510            }
     1511            catch (ItemNotFoundException ex)
     1512            {
     1513              throw new BaseException("Can't find bioassay '" + assayId +
     1514                "' in section 'spots' at line " + ffp.getParsedLines() + " in file '" +
     1515                stdout.getName() + "'"
     1516                );
     1517            }
     1518            childBioAssays.put(assayId, new ChildBioAssay(assayId, null, null));
     1519          }
     1520        }
     1521       
     1522        // Parse data and check if each position has same reporter as before
     1523        FlatFileParser.Data data;
     1524        while ((data = ffp.nextData()) != null)
     1525        {
     1526          checkInterrupted();
     1527          Integer position = Values.getInteger(data.get(positionIndex), null);
     1528          Integer newReporterId = Values.getInteger(data.get(reporterIndex), null);
     1529         
     1530          // Error if position is missing
     1531          if (position == null)
     1532          {
     1533            throw new BaseException("Missing or invalid value for 'position' in section 'spots' at line " +
     1534                ffp.getParsedLines() + " in file '" + stdout.getName() + "'");
     1535          }
     1536         
     1537          // Is the new reporter the same as the existing?
     1538          // A 'null' reporter is considered the same as another 'null' reporter
     1539          if (hasSamePositionReporterMapping)
     1540          {     
     1541            Integer existingReporterId = parentReporterPositions.get(position);
     1542            if (!Diff3.isEqualOrNull(newReporterId, existingReporterId))
     1543            {
     1544              hasSamePositionReporterMapping = false;
     1545              parentReporterPositions.clear();
     1546            }
     1547          }
     1548         
     1549          // Is the new reporter already registered with the same position?
     1550          if (!childReporterPositions.containsKey(position))
     1551          {
     1552            childReporterPositions.put(position, newReporterId);
     1553          }
     1554          else
     1555          {
     1556            Integer registeredReporterId = childReporterPositions.get(position);
     1557            // Error if same position has different reporters in the stdout file
     1558            if (!Diff3.isEqualOrNull(newReporterId, registeredReporterId))
     1559            {
     1560              throw new BaseException("Invalid value for 'reporter' (" + newReporterId +
     1561                ") for position '" + position + "' in section 'spots' at line " +
     1562                ffp.getParsedLines() + " in file '" + stdout.getName() +
     1563                "'. Expected '" + registeredReporterId + "'");
     1564            }
     1565          }
     1566        }
     1567      }
     1568    }
     1569   
     1570    if (!hasSpotSection) return;
     1571   
     1572    // Create the child bioassay set
     1573    BioAssaySet child = null;
     1574    boolean useNewDataCube = hasParentAssayMapping || !hasSamePositionReporterMapping;
     1575    if (useNewDataCube)
     1576    {
     1577      child = t.newProduct("new", "new", false);
     1578    }
     1579    else
     1580    {
     1581      child = t.newProduct(null, "new", false);
     1582    }
     1583    dc.saveItem(child);
     1584
     1585    // Create child bioassays
     1586    for (ChildBioAssay childData : childBioAssays.values())
     1587    {
     1588      BioAssay childBa = null;
     1589      if (useNewDataCube)
     1590      {
     1591        Collection<BioAssay> parents = null;
     1592        if (childData.parents == null)
     1593        {
     1594          parents = Collections.singletonList(BioAssay.getById(dc, childData.id));
     1595        }
     1596        else
     1597        {
     1598          parents = new ArrayList<BioAssay>(childData.parents.size());
     1599          for (Integer parentId : childData.parents)
     1600          {
     1601            parents.add(BioAssay.getById(dc, parentId));
     1602          }
     1603        }
     1604        childBa = child.newBioAssay(parents);
     1605        // Put column mappings
     1606        short childColumn = childBa.getDataCubeColumnNo();
     1607        for (BioAssay parentBa : parents)
     1608        {
     1609          columnMapping.put(parentBa.getDataCubeColumnNo(), childColumn);
     1610        }
     1611      }
     1612      else
     1613      {
     1614        BioAssay parentBa = BioAssay.getById(dc, childData.id);
     1615        childBa = child.newBioAssay(parentBa);
     1616        // Columns should be identical... put in the mapping just be be sure
     1617        columnMapping.put(parentBa.getDataCubeColumnNo(), childBa.getDataCubeColumnNo());
     1618      }
     1619      if (childData.name != null) childBa.setName(childData.name);
     1620      dc.saveItem(childBa);
     1621      bioAssayColumns.put(childData.id, childBa.getDataCubeColumnNo());
     1622    }
     1623   
     1624    // Create new position -> reporter mapping
     1625    if (useNewDataCube)
     1626    {
     1627      // Create position -> reporter mapping from the new data
     1628      PositionBatcher posBatcher = child.getPositionBatcher();
     1629      ReporterProxy proxy = new ReporterProxy();
     1630      for (Map.Entry<Integer, Integer> entry : childReporterPositions.entrySet())
     1631      {
     1632        checkInterrupted();
     1633        int position = entry.getKey();
     1634        Integer reporterId = entry.getValue();
     1635        if (reporterId == null)
     1636        {
     1637          posBatcher.insert(position, null);
     1638        }
     1639        else
     1640        {
     1641          proxy.setTheId(reporterId);
     1642          posBatcher.insert(position, proxy);
     1643        }
     1644      }
     1645      posBatcher.flush();
     1646      posBatcher.close();
     1647     
     1648      if (hasSamePositionReporterMapping)
     1649      {
     1650        // Create raw data mapping
     1651        MappingBatcher mapBatcher = child.getMappingBatcher();
     1652        DynamicSpotQuery spotQuery = source.getSpotData();
     1653        spotQuery.joinRawData(JoinType.INNER);
     1654       
     1655        spotQuery.select(Dynamic.select(VirtualColumn.COLUMN));
     1656        spotQuery.select(Dynamic.select(VirtualColumn.POSITION));
     1657        spotQuery.select(Dynamic.select(VirtualTable.RAWPARENTS, VirtualColumn.RAWDATA_ID));
     1658       
     1659        DynamicResultIterator spotIterator = spotQuery.iterate(dc);
     1660        RawDataProxy rawProxy = new RawDataProxy();
     1661        while (spotIterator.hasNext())
     1662        {
     1663          SqlResult result = spotIterator.next();
     1664          short parentColumn = result.getShort(1);
     1665          int position = result.getInt(2);
     1666          int rawDataId = result.getInt(3);
     1667          Short childColumn = columnMapping.get(parentColumn);
     1668          if (childColumn != null)
     1669          {
     1670            rawProxy.setTheId(rawDataId);
     1671            mapBatcher.insert(childColumn, position, rawProxy);
     1672          }
     1673        }
     1674        mapBatcher.flush();
     1675        mapBatcher.close();
     1676      }
     1677    }
     1678   
     1679    // Clean up things that are no longer needed
     1680    childBioAssays.clear();
     1681    childReporterPositions.clear();
     1682    parentReporterPositions.clear();
     1683   
     1684   
     1685    // Old code below
     1686
     1687    SpotBatcher spotBatcher = child.getSpotBatcher();
     1688    HashMap<String, ExtraValueType> evtMap = new HashMap<String, ExtraValueType>();
     1689    ffp = getInitializedFlatFileParser(stdout.getDownloadStream(0));
     1690   
     1691    while (ffp.hasMoreSections())
     1692    {
     1693      checkInterrupted();
     1694      FlatFileParser.Line section = ffp.nextSection();
     1695      ffp.parseHeaders();
     1696     
     1697      if (section.name().equals("assays"))
     1698      {
     1699        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
     1700        ffp.setMinDataColumns(columns.size());
     1701        // Loop to the end of this section
     1702        while (ffp.nextData() != null)
     1703        {}
    13991704      }
    14001705      else if (section.name().equals("spots"))
    14011706      {
    14021707        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
    1403         List<String> assays = Arrays.asList(ffp.getHeader("assays").split("\\t"));
     1708        List<Integer> assays = Arrays.asList(Values.getInt(ffp.getHeader("assays").split("\\t")));
    14041709        List<String> assayFields = Arrays.asList(ffp.getHeader("assayFields").split("\\t"));
    14051710        List<String> setExtraFloats = new ArrayList<String>();
     
    14071712          setExtraFloats = Arrays.asList(ffp.getHeader("setExtraFloats").split("\\t"));
    14081713       
    1409         if (bas == null)
    1410         {
    1411           bas = t.newProduct(null, "new", false);
    1412           doPositionBatch = false;
    1413         }
    1414         spotBatcher = bas.getSpotBatcher();
    1415 
    1416         for (String assayId : assays)
    1417         {
    1418           if (idMap.get(assayId) == null)
    1419           {
    1420             try
    1421             {
    1422               BioAssay parent = BioAssay.getById(dc, Integer.parseInt(assayId));
    1423               BioAssay ba = bas.newBioAssay(parent);
    1424               idMap.put(assayId, ba);
    1425             }
    1426             catch (ItemNotFoundException e)
    1427             {
    1428               throw new BaseException("Couldn't find any parent for bioassay "+assayId);
    1429             }
    1430           }
    1431         }
    1432        
    14331714        ffp.setMinDataColumns(columns.size() - 1 + assays.size() * assayFields.size());
    14341715       
     
    14361717
    14371718        int posCol = columns.indexOf("position");
    1438         int repCol = columns.indexOf("reporter");
    14391719        int dataCol = columns.indexOf("assayData");
    1440         int[] intCol = new int[bas.getRawDataType().getChannels()];
     1720        int[] intCol = new int[child.getRawDataType().getChannels()];
    14411721        for (int i = 0; i < intCol.length; ++i)
    14421722        {
     
    15061786            evtMap.put(name, evt);
    15071787          }
    1508           evBatcher.add(i, bas.getSpotExtraValueBatcher(Float.class, evt, Job.getById(dc, job.getId())));
     1788          evBatcher.add(i, child.getSpotExtraValueBatcher(Float.class, evt, Job.getById(dc, job.getId())));
    15091789        }
    15101790       
    15111791        while (ffp.hasMoreData())
    15121792        {
     1793          checkInterrupted();
    15131794          FlatFileParser.Data dataline = ffp.nextData();
    15141795          int index = 0;
    1515           for (String assayId : assays)
    1516           {
    1517             BioAssay ba = idMap.get(assayId);
     1796          for (Integer assayId : assays)
     1797          {
     1798            short dataCubeColumn = bioAssayColumns.get(assayId);
    15181799            try
    15191800            {
    15201801              float[] intensities = new float[intCol.length];
    1521               Integer reporter = dataline.get(repCol) == null ? null : new Integer(dataline.get(repCol));
    15221802              Integer position = dataline.get(posCol) == null ? null : new Integer(dataline.get(posCol));
    15231803
     
    15381818              }
    15391819
    1540               spotBatcher.insert(ba.getDataCubeColumnNo(), position, intensities);
    1541              
    1542               if (posRepMap.containsKey(position))
    1543               {
    1544                 if (!reporter.equals(posRepMap.get(position).getId()))
    1545                   throw new BaseException("Invalid data. Position, "+position+", occurs twice with different reporter data.");
    1546               }
    1547               else
    1548               {
    1549                 posRepMap.put(position, Reporter.getById(dc, reporter));
    1550               }
    1551              
     1820              spotBatcher.insert(dataCubeColumn, position, intensities);
     1821                   
    15521822              for (int i = 0; i < evBatcher.size(); i++)
    15531823              {
     
    15551825                {
    15561826                  Float ev = new Float(dataline.get(extraFloatsCol[i] + index));
    1557                   evBatcher.get(i).insert(ba.getDataCubeColumnNo(), position, ev);
     1827                  evBatcher.get(i).insert(dataCubeColumn, position, ev);
    15581828                }
    15591829                catch (NumberFormatException e)
     
    15691839    }
    15701840
    1571     //Batch reporters
    1572     if (bas != null && doPositionBatch)
    1573     {
    1574       PositionBatcher posBatcher = bas.getPositionBatcher();
    1575       for (Integer position : posRepMap.keySet())
    1576       {
    1577         posBatcher.insert(position, posRepMap.get(position));
    1578       }
    1579     }
    1580    
    1581     // save bas
    1582     if (bas != null)
    1583     {
    1584       dc.saveItem(bas);
    1585       for (BioAssay ba : idMap.values())
    1586       {
    1587         dc.saveItem(ba);
    1588       }
    1589     }
    1590    
    1591     int id = -1;
    1592     if (t != null) id = t.getId();
    1593     return id;
    1594   }
    1595  
    1596 
     1841  }
     1842 
    15971843  private void importFiles(DbControl dc, Transformation trans)
    15981844  {
     
    20792325    }
    20802326  }
     2327 
     2328  private static class ReporterProxy
     2329    extends ReporterData
     2330  {
     2331    private int id;
     2332    ReporterProxy()
     2333    {}
     2334    public void setTheId(int id)
     2335    {
     2336      this.id = id;
     2337    }
     2338    public int getId()
     2339    {
     2340      return id;
     2341    }
     2342  }
     2343 
     2344  private static class RawDataProxy
     2345    extends RawData
     2346  {
     2347    private int id;
     2348    RawDataProxy()
     2349    {}
     2350    public void setTheId(int id)
     2351    {
     2352      this.id = id;
     2353    }
     2354    public int getId()
     2355    {
     2356      return id;
     2357    }
     2358  }
     2359 
     2360  private static class ChildBioAssay
     2361  {
     2362    final int id;
     2363    final String name;
     2364    final Set<Integer> parents;
     2365   
     2366    ChildBioAssay(int id, String name, Set<Integer> parents)
     2367    {
     2368      this.id = id;
     2369      this.name = name;
     2370      this.parents = parents;
     2371    }
     2372  }
    20812373}
  • branches/2.6-stable/src/test/TestAll.java

    r3820 r4212  
    150150    results.put("TestFormula", TestFormula.test_all());
    151151    results.put("TestExperiment", TestExperiment.test_all());
     152   
     153    // Complex tests
     154    results.put("TestBase1PluginExecuter", TestBase1PluginExecuter.test_all());
    152155
    153156    int failures = 0;
  • branches/2.6-stable/src/test/TestAnalyzePluginUtil.java

    r4124 r4212  
    3535import net.sf.basedb.core.RawDataBatcher;
    3636import net.sf.basedb.core.RawDataTypes;
     37import net.sf.basedb.core.ReporterBatcher;
    3738import net.sf.basedb.core.data.RawData;
    3839import net.sf.basedb.util.FileUtil;
     40import net.sf.basedb.util.Values;
    3941import net.sf.basedb.util.parser.FlatFileParser;
    4042
     
    4345  /**
    4446    Creates a randomly generated experiment.
    45     @param rawBioAssays number of {@link net.sf.basedb.core.RawBioAssay RawBioAssays} in experiment
    46     @param spots number of spots in each RawBioAssay
     47   * @param file TODO
     48   * @param rawBioAssays number of {@link net.sf.basedb.core.RawBioAssay RawBioAssays} in experiment
     49   * @param spots number of spots in each RawBioAssay
    4750  */
    48   static int test_createExperiment(int rawBioAssays, int spots)
     51  static int test_createExperiment(String file, int rawBioAssays, int spots)
    4952  {
    5053    if (!TestUtil.hasPermission(Permission.CREATE, Item.EXPERIMENT)) return 0;
     
    6669        parser.setDataHeaderRegexp(Pattern.compile("\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*"));
    6770        parser.setDataSplitterRegexp(Pattern.compile("\\t"));
    68         parser.setInputStream(FileUtil.getInputStream(new java.io.File("data/test.rawdata.import.txt")), "ISO-8859-1");
     71        parser.setInputStream(FileUtil.getInputStream(new java.io.File(file)), "ISO-8859-1");
    6972        parser.parseHeaders();
    7073       
     
    7376        rba.setDescription("RawBioAssay created by TestAnalyzePluginUtil. Number of spots should be "+spots);
    7477        RawDataBatcher rawDataBatcher = rba.getRawDataBatcher(null);
     78        ReporterBatcher reporterBatcher = ReporterBatcher.getNew(dc);
    7579        for (int j = 0; parser.hasMoreData() && j < spots; j++)
    7680        {
    7781          FlatFileParser.Data parsedData = parser.nextData();
    7882          RawData rawData = rawDataBatcher.newRawData();
    79           rawData.setBlock(Integer.valueOf(parsedData.get(0)));
    80           rawData.setRow(Integer.valueOf(parsedData.get(2)));
    81           rawData.setColumn(Integer.valueOf(parsedData.get(1)));
    82           rawData.setX(Float.valueOf(parsedData.get(5)));
    83           rawData.setY(Float.valueOf(parsedData.get(6)));
    84 //          String reporterId = parsedData.get(4);
    85           rawData.setReporter(null);
     83          rawData.setBlock(Values.getInteger(parsedData.get(0), null));
     84          rawData.setRow(Values.getInteger(parsedData.get(2), null));
     85          rawData.setColumn(Values.getInteger(parsedData.get(1), null));
     86          rawData.setX(Values.getFloat(parsedData.get(5), null));
     87          rawData.setY(Values.getFloat(parsedData.get(6), null));
     88          String reporterId = parsedData.get(4);
     89          rawData.setReporter(reporterId == null ? null : reporterBatcher.getByExternalId(reporterId));
    8690         
    8791          Map<String, Object> extraData = rawData.getAllExtended();
    88           extraData.put("diameter", Float.valueOf(parsedData.get(7)));
    89           extraData.put("ch1FgMedian", Float.valueOf(parsedData.get(8)));
    90           extraData.put("ch1FgMean", Float.valueOf(parsedData.get(9)));
    91           extraData.put("ch1FgSd", Float.valueOf(parsedData.get(10)));
    92           extraData.put("ch1BgMedian", Float.valueOf(parsedData.get(11)));
    93           extraData.put("ch1BgMean", Float.valueOf(parsedData.get(12)));
    94           extraData.put("ch1BgSd", Float.valueOf(parsedData.get(13)));
    95           extraData.put("ch1PercSd1", Integer.valueOf(parsedData.get(14)));
    96           extraData.put("ch1PercSd2", Integer.valueOf(parsedData.get(15)));
    97           extraData.put("ch1PercSat", Integer.valueOf(parsedData.get(16)));
    98           extraData.put("ch2FgMedian", Float.valueOf(parsedData.get(17)));
    99           extraData.put("ch2FgMean", Float.valueOf(parsedData.get(18)));
    100           extraData.put("ch2FgSd", Float.valueOf(parsedData.get(19)));
    101           extraData.put("ch2BgMedian", Float.valueOf(parsedData.get(20)));
    102           extraData.put("ch2BgMean", Float.valueOf(parsedData.get(21)));
    103           extraData.put("ch2BgSd", Float.valueOf(parsedData.get(22)));
    104           extraData.put("ch2PercSd1", Integer.valueOf(parsedData.get(23)));
    105           extraData.put("ch2PercSd2", Integer.valueOf(parsedData.get(24)));
    106           extraData.put("ch2PercSat", Integer.valueOf(parsedData.get(25)));
     92          extraData.put("diameter", Values.getFloat(parsedData.get(7), null));
     93          extraData.put("ch1FgMedian", Values.getFloat(parsedData.get(8), null));
     94          extraData.put("ch1FgMean", Values.getFloat(parsedData.get(9), null));
     95          extraData.put("ch1FgSd", Values.getFloat(parsedData.get(10), null));
     96          extraData.put("ch1BgMedian", Values.getFloat(parsedData.get(11), null));
     97          extraData.put("ch1BgMean", Values.getFloat(parsedData.get(12), null));
     98          extraData.put("ch1BgSd", Values.getFloat(parsedData.get(13), null));
     99          extraData.put("ch1PercSd1", Values.getInteger(parsedData.get(14), null));
     100          extraData.put("ch1PercSd2", Values.getInteger(parsedData.get(15), null));
     101          extraData.put("ch1PercSat", Values.getInteger(parsedData.get(16), null));
     102          extraData.put("ch2FgMedian", Values.getFloat(parsedData.get(17), null));
     103          extraData.put("ch2FgMean", Values.getFloat(parsedData.get(18), null));
     104          extraData.put("ch2FgSd", Values.getFloat(parsedData.get(19), null));
     105          extraData.put("ch2BgMedian", Values.getFloat(parsedData.get(20), null));
     106          extraData.put("ch2BgMean", Values.getFloat(parsedData.get(21), null));
     107          extraData.put("ch2BgSd", Values.getFloat(parsedData.get(22), null));
     108          extraData.put("ch2PercSd1", Values.getInteger(parsedData.get(23), null));
     109          extraData.put("ch2PercSd2", Values.getInteger(parsedData.get(24), null));
     110          extraData.put("ch2PercSat", Values.getInteger(parsedData.get(25), null));
    107111         
    108112          rawDataBatcher.insert(rawData);
  • branches/2.6-stable/src/test/TestBase1PluginExecuter.java

    r3719 r4212  
    5757  {
    5858    write("++Testing TestBase1PluginExecuter");
    59     int experimentId = TestAnalyzePluginUtil.test_createExperiment(2, 100);
    60 
    61     int formulaId = TestFormula.test_create(Formula.Type.INTENSITY_EXPRESSION, "genepix",
    62         new String[] { "raw('ch1FgMedian')", "raw('ch2FgMedian')" }, false);
    63    
    64     int fileId = TestFile.test_create("data/test.plugin.base", false, false);
     59   
     60    // Import reporters
     61    TestReporter.test_import_from_file("data/test.rawdata.import.txt",
     62      "\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", "\\t", 4, 3);
     63   
     64    // Create experiment
     65    int experimentId = TestAnalyzePluginUtil.test_createExperiment("data/test.rawdata.import.txt", 2, 100);
     66
     67    int formulaId = TestFormula.test_create("raw fg mean", Formula.Type.INTENSITY_EXPRESSION,
     68        "genepix", new String[] { "raw('ch1FgMedian')", "raw('ch2FgMedian')" }, false);
     69   
     70    int formulaChromosomeId = TestFormula.test_create("chromosome",
     71        Formula.Type.COLUMN_EXPRESSION, "genepix", new String[] { "rep('chromosome')" }, false);
     72   
     73    int fileId = TestFile.test_create("data/test.nullplugin.base", false, false);
     74    int fileId2 = TestFile.test_create("data/test.base1plugin.base", false, false);
    6575    int directoryId = TestDirectory.test_create(true, "Base1PluginExecuter");
    6676   
     
    6878    int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.Base1PluginExecuter");
    6979    int pluginConfigurationId = test_create_configuration(pluginDefinitionId, fileId);
     80    int pluginConfigurationId2 = test_create_configuration(pluginDefinitionId, fileId2);
     81   
     82    // Copy input to output
    7083    int jobId = test_create_job(pluginConfigurationId, experimentId, directoryId);
    7184    TestJob.test_execute(jobId);
    7285   
     86    // One-to-one mapping on assays and reporters
     87    int jobId2 = test_create_job(pluginConfigurationId2, experimentId, directoryId);
     88    TestJob.test_execute(jobId2);
     89
     90    // Merge assays
     91    int jobId3 = test_create_job(pluginConfigurationId2, experimentId, directoryId,
     92        new Parameter("mergeAssays", "1"));
     93    TestJob.test_execute(jobId3);
     94
     95    // Offset positions
     96    int jobId4 = test_create_job(pluginConfigurationId2, experimentId, directoryId,
     97        new Parameter("offsetPositions", "1"));
     98    TestJob.test_execute(jobId4);
     99
     100    // Offset positions and merge assays
     101    int jobId5 = test_create_job(pluginConfigurationId2, experimentId, directoryId,
     102        new Parameter("mergeAssays", "1"), new Parameter("offsetPositions", "1"));
     103    TestJob.test_execute(jobId5);
     104
    73105    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
    74106   
    75107    // Cleanup
    76108    TestExperiment.test_delete(experimentId);
    77     TestJob.test_delete(jobId);
    78109    TestPluginConfiguration.test_delete(pluginConfigurationId);
     110    TestPluginConfiguration.test_delete(pluginConfigurationId2);
    79111    TestFormula.test_delete(formulaId);
     112    TestFormula.test_delete(formulaChromosomeId);
    80113    TestFile.test_delete(fileId);
     114    TestFile.test_delete(fileId2);
    81115    TestDirectory.test_delete(directoryId, true);
     116    TestReporter.test_delete();
    82117    return ok;
    83118  }
     
    129164  }
    130165 
    131   static int test_create_job(int pluginConfigurationId, int experimentId, int directoryId)
     166  static int test_create_job(int pluginConfigurationId, int experimentId, int directoryId, Parameter... parameters)
    132167  {
    133168    if (pluginConfigurationId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0;
     
    146181     
    147182      PluginConfigurationRequest request = j.configure(null);
     183     
     184      // First, set default values
    148185      for (PluginParameter<?> p : request.getRequestInformation().getParameters())
    149186      {
    150         Object value = p.getParameterType().getDefaultValue();
    151 
    152         request.setParameterValue(p.getName(), value);
    153       }
     187        request.setParameterValue(p.getName(), p.getParameterType().getDefaultValue());
     188      }
     189     
     190      // Then, set values from method call
     191      if (parameters != null)
     192      {
     193        for (Parameter p : parameters)
     194        {
     195          request.setParameterValue(p.name, p.value);
     196        }
     197      }
     198     
    154199      request.setParameterValue("source", bioAssaySet);
    155200      request.setParameterValue("pluginDirectory", Directory.getById(dc, directoryId).getPath().toString());
     
    202247    }
    203248  }
     249 
     250  static class Parameter
     251  {
     252    final String name;
     253    final Object value;
     254    Parameter(String name, Object value)
     255    {
     256      this.name = name;
     257      this.value = value;
     258    }
     259  }
     260 
    204261}
  • branches/2.6-stable/src/test/TestExperiment.java

    r4124 r4212  
    102102   
    103103   
    104     int formulaId = TestFormula.test_create(Formula.Type.INTENSITY_EXPRESSION, "genepix",
    105         new String[] { "raw('ch1FgMean')", "raw('ch2FgMean')" }, false);
     104    int formulaId = TestFormula.test_create(null, Formula.Type.INTENSITY_EXPRESSION,
     105        "genepix", new String[] { "raw('ch1FgMean')", "raw('ch2FgMean')" }, false);
    106106    int jobId = test_create_root_bioassayset_using_plugin(id, formulaId, rbaId1, rbaId2);
    107107    TestJob.test_execute(jobId);
  • branches/2.6-stable/src/test/TestFormula.java

    r3679 r4212  
    4444    write_header();
    4545    // Standard tests: create, load, list
    46     int id = test_create(Formula.Type.COLUMN_EXPRESSION, "genepix",
    47       new String[] { "ch(1) + ch(2)" }, true);
    48     int id2 = test_create(Formula.Type.INTENSITY_EXPRESSION, "genepix",
    49       new String[] { "raw('ch1FgMean')", "raw('ch2FgMean')" }, false);
     46    int id = test_create("add", Formula.Type.COLUMN_EXPRESSION,
     47      "genepix",  new String[] { "ch(1) + ch(2)" }, true);
     48    int id2 = test_create("raw fg mean", Formula.Type.INTENSITY_EXPRESSION,
     49      "genepix", new String[] { "raw('ch1FgMean')", "raw('ch2FgMean')" }, false);
    5050    test_load(id);
    5151    test_list(-1);
     
    5959  }
    6060
    61   static int test_create(Formula.Type formulaType, String rawDataType, String[] formulas, boolean setAll)
     61  static int test_create(String name, Formula.Type formulaType, String rawDataType, String[] formulas, boolean setAll)
    6262  {
    6363    if (!TestUtil.hasPermission(Permission.CREATE, Item.FORMULA)) return 0;
     
    7575        f.setParser(Formula.Parser.JEP);
    7676      }
     77      if (name != null) f.setName(name);
    7778      f.setFormulaType(formulaType);
    7879      f.setRawDataType(RawDataTypes.getRawDataType(rawDataType));
  • branches/2.6-stable/src/test/TestJob.java

    r3679 r4212  
    9595      if (response.getStatus() == Response.Status.ERROR)
    9696      {
    97         throw new BaseException(response.getMessage(), response.getErrorList().get(0));
     97        Throwable cause = response.getErrorList() != null &&
     98          response.getErrorList().size() > 0 ? response.getErrorList().get(0) : null;
     99        throw new BaseException(response.getMessage(), cause);
    98100      }
    99101     
  • branches/2.6-stable/src/test/TestLowessNormalization.java

    r3675 r4212  
    5454  {
    5555    write("++Testing TestLowessNormalization");
    56     int experimentId = TestAnalyzePluginUtil.test_createExperiment(2, 100);
     56    int experimentId = TestAnalyzePluginUtil.test_createExperiment("data/test.rawdata.import.txt", 2, 100);
    5757
    58     int formulaId = TestFormula.test_create(Formula.Type.INTENSITY_EXPRESSION, "genepix",
    59         new String[] { "raw('ch1FgMedian')", "raw('ch2FgMedian')" }, false);
     58    int formulaId = TestFormula.test_create(null, Formula.Type.INTENSITY_EXPRESSION,
     59        "genepix", new String[] { "raw('ch1FgMedian')", "raw('ch2FgMedian')" }, false);
    6060   
    6161    TestAnalyzePluginUtil.test_createRootBioAssaySet(experimentId, formulaId);
  • branches/2.6-stable/src/test/TestMedianRatioNormalization.java

    r3675 r4212  
    4949  {
    5050    write("++Testing MedianRatioNormalization");
    51     int experimentId = TestAnalyzePluginUtil.test_createExperiment(2, 100);
    52     int formulaId = TestFormula.test_create(Formula.Type.INTENSITY_EXPRESSION, "genepix",
    53         new String[] { "raw('ch1FgMedian')", "raw('ch2FgMedian')" }, false);
     51    int experimentId = TestAnalyzePluginUtil.test_createExperiment("data/test.rawdata.import.txt", 2, 100);
     52    int formulaId = TestFormula.test_create(null, Formula.Type.INTENSITY_EXPRESSION,
     53        "genepix", new String[] { "raw('ch1FgMedian')", "raw('ch2FgMedian')" }, false);
    5454    TestAnalyzePluginUtil.test_createRootBioAssaySet(experimentId, formulaId);
    5555    int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.MedianRatioNormalization");
  • branches/2.6-stable/src/test/data/test.nullplugin.base

    r4191 r4212  
    55name  Base1NullPlugin
    66descr Test base1pluginexecuter
    7 execName  runplugin.sh
     7execName  nullplugin.sh
    88geneAverages  0
    99serialFormat  1
Note: See TracChangeset for help on using the changeset viewer.