Changeset 4212
- Timestamp:
- Apr 10, 2008, 12:53:41 PM (15 years ago)
- Location:
- branches/2.6-stable
- Files:
-
- 3 added
- 11 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2.6-stable/build.xml
r4194 r4212 848 848 jarfile="${test.build}/JarPlugin.jar" 849 849 basedir="${test.build}" 850 includes="JarPlugin*,NullPlugin*,Base1 NullPlugin*"850 includes="JarPlugin*,NullPlugin*,Base1*" 851 851 excludes="JarPlugin.jar,JarPluginAbout.*" 852 852 manifest="${test.src}/data/JarPluginManifest.txt" -
branches/2.6-stable/src/core/net/sf/basedb/core/data/RawData.java
r4080 r4212 46 46 { 47 47 48 RawData()48 public RawData() 49 49 {} 50 50 -
branches/2.6-stable/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java
r4121 r4212 35 35 import net.sf.basedb.core.DbControl; 36 36 import net.sf.basedb.core.Directory; 37 import net.sf.basedb.core.DynamicQuery; 38 import net.sf.basedb.core.DynamicResultIterator; 39 import net.sf.basedb.core.DynamicSpotQuery; 37 40 import net.sf.basedb.core.Experiment; 38 41 import net.sf.basedb.core.ExtraValue; … … 48 51 import net.sf.basedb.core.ItemQuery; 49 52 import net.sf.basedb.core.Job; 53 import net.sf.basedb.core.MappingBatcher; 50 54 import net.sf.basedb.core.Path; 51 55 import net.sf.basedb.core.PathParameterType; … … 55 59 import net.sf.basedb.core.PositionBatcher; 56 60 import net.sf.basedb.core.ProgressReporter; 57 import net.sf.basedb.core.Reporter;58 61 import net.sf.basedb.core.RequestInformation; 59 62 import net.sf.basedb.core.SpotBatcher; … … 63 66 import net.sf.basedb.core.Type; 64 67 import net.sf.basedb.core.User; 68 import net.sf.basedb.core.VirtualColumn; 69 import net.sf.basedb.core.VirtualTable; 70 import net.sf.basedb.core.data.RawData; 65 71 import net.sf.basedb.core.data.ReporterData; 66 72 import net.sf.basedb.core.plugin.About; … … 72 78 import net.sf.basedb.core.plugin.Request; 73 79 import net.sf.basedb.core.plugin.Response; 80 import net.sf.basedb.core.query.Dynamic; 74 81 import net.sf.basedb.core.query.Hql; 82 import net.sf.basedb.core.query.JoinType; 75 83 import net.sf.basedb.core.query.Orders; 84 import net.sf.basedb.core.query.SqlResult; 76 85 import net.sf.basedb.core.signal.SignalException; 77 86 import net.sf.basedb.core.signal.SignalHandler; 78 87 import net.sf.basedb.core.signal.SignalTarget; 79 88 import net.sf.basedb.core.signal.ThreadSignalHandler; 89 import net.sf.basedb.util.Diff3; 80 90 import net.sf.basedb.util.Enumeration; 81 91 import net.sf.basedb.util.Values; … … 1331 1341 /** 1332 1342 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.1335 1343 @throws IOException if there is any error reading from stdout.txt 1336 1344 */ 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 1348 1379 FlatFileParser ffp = getInitializedFlatFileParser(stdout.getDownloadStream(0)); 1349 1350 1380 while (ffp.hasMoreSections()) 1351 1381 { 1382 checkInterrupted(); 1352 1383 FlatFileParser.Line section = ffp.nextSection(); 1353 1384 ffp.parseHeaders(); 1354 1385 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 */ 1360 1394 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) 1365 1412 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; 1385 1433 try 1386 1434 { 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 } 1388 1441 } 1389 catch (ItemNotFoundException e )1442 catch (ItemNotFoundException ex) 1390 1443 { 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 ); 1392 1448 } 1393 1449 } 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 {} 1399 1704 } 1400 1705 else if (section.name().equals("spots")) 1401 1706 { 1402 1707 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"))); 1404 1709 List<String> assayFields = Arrays.asList(ffp.getHeader("assayFields").split("\\t")); 1405 1710 List<String> setExtraFloats = new ArrayList<String>(); … … 1407 1712 setExtraFloats = Arrays.asList(ffp.getHeader("setExtraFloats").split("\\t")); 1408 1713 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 try1421 {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 1433 1714 ffp.setMinDataColumns(columns.size() - 1 + assays.size() * assayFields.size()); 1434 1715 … … 1436 1717 1437 1718 int posCol = columns.indexOf("position"); 1438 int repCol = columns.indexOf("reporter");1439 1719 int dataCol = columns.indexOf("assayData"); 1440 int[] intCol = new int[ bas.getRawDataType().getChannels()];1720 int[] intCol = new int[child.getRawDataType().getChannels()]; 1441 1721 for (int i = 0; i < intCol.length; ++i) 1442 1722 { … … 1506 1786 evtMap.put(name, evt); 1507 1787 } 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()))); 1509 1789 } 1510 1790 1511 1791 while (ffp.hasMoreData()) 1512 1792 { 1793 checkInterrupted(); 1513 1794 FlatFileParser.Data dataline = ffp.nextData(); 1514 1795 int index = 0; 1515 for ( StringassayId : assays)1516 { 1517 BioAssay ba = idMap.get(assayId);1796 for (Integer assayId : assays) 1797 { 1798 short dataCubeColumn = bioAssayColumns.get(assayId); 1518 1799 try 1519 1800 { 1520 1801 float[] intensities = new float[intCol.length]; 1521 Integer reporter = dataline.get(repCol) == null ? null : new Integer(dataline.get(repCol));1522 1802 Integer position = dataline.get(posCol) == null ? null : new Integer(dataline.get(posCol)); 1523 1803 … … 1538 1818 } 1539 1819 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 1552 1822 for (int i = 0; i < evBatcher.size(); i++) 1553 1823 { … … 1555 1825 { 1556 1826 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); 1558 1828 } 1559 1829 catch (NumberFormatException e) … … 1569 1839 } 1570 1840 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 1597 1843 private void importFiles(DbControl dc, Transformation trans) 1598 1844 { … … 2079 2325 } 2080 2326 } 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 } 2081 2373 } -
branches/2.6-stable/src/test/TestAll.java
r3820 r4212 150 150 results.put("TestFormula", TestFormula.test_all()); 151 151 results.put("TestExperiment", TestExperiment.test_all()); 152 153 // Complex tests 154 results.put("TestBase1PluginExecuter", TestBase1PluginExecuter.test_all()); 152 155 153 156 int failures = 0; -
branches/2.6-stable/src/test/TestAnalyzePluginUtil.java
r4124 r4212 35 35 import net.sf.basedb.core.RawDataBatcher; 36 36 import net.sf.basedb.core.RawDataTypes; 37 import net.sf.basedb.core.ReporterBatcher; 37 38 import net.sf.basedb.core.data.RawData; 38 39 import net.sf.basedb.util.FileUtil; 40 import net.sf.basedb.util.Values; 39 41 import net.sf.basedb.util.parser.FlatFileParser; 40 42 … … 43 45 /** 44 46 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 47 50 */ 48 static int test_createExperiment( int rawBioAssays, int spots)51 static int test_createExperiment(String file, int rawBioAssays, int spots) 49 52 { 50 53 if (!TestUtil.hasPermission(Permission.CREATE, Item.EXPERIMENT)) return 0; … … 66 69 parser.setDataHeaderRegexp(Pattern.compile("\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*")); 67 70 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"); 69 72 parser.parseHeaders(); 70 73 … … 73 76 rba.setDescription("RawBioAssay created by TestAnalyzePluginUtil. Number of spots should be "+spots); 74 77 RawDataBatcher rawDataBatcher = rba.getRawDataBatcher(null); 78 ReporterBatcher reporterBatcher = ReporterBatcher.getNew(dc); 75 79 for (int j = 0; parser.hasMoreData() && j < spots; j++) 76 80 { 77 81 FlatFileParser.Data parsedData = parser.nextData(); 78 82 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)); 86 90 87 91 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)); 107 111 108 112 rawDataBatcher.insert(rawData); -
branches/2.6-stable/src/test/TestBase1PluginExecuter.java
r3719 r4212 57 57 { 58 58 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); 65 75 int directoryId = TestDirectory.test_create(true, "Base1PluginExecuter"); 66 76 … … 68 78 int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.Base1PluginExecuter"); 69 79 int pluginConfigurationId = test_create_configuration(pluginDefinitionId, fileId); 80 int pluginConfigurationId2 = test_create_configuration(pluginDefinitionId, fileId2); 81 82 // Copy input to output 70 83 int jobId = test_create_job(pluginConfigurationId, experimentId, directoryId); 71 84 TestJob.test_execute(jobId); 72 85 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 73 105 if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); 74 106 75 107 // Cleanup 76 108 TestExperiment.test_delete(experimentId); 77 TestJob.test_delete(jobId);78 109 TestPluginConfiguration.test_delete(pluginConfigurationId); 110 TestPluginConfiguration.test_delete(pluginConfigurationId2); 79 111 TestFormula.test_delete(formulaId); 112 TestFormula.test_delete(formulaChromosomeId); 80 113 TestFile.test_delete(fileId); 114 TestFile.test_delete(fileId2); 81 115 TestDirectory.test_delete(directoryId, true); 116 TestReporter.test_delete(); 82 117 return ok; 83 118 } … … 129 164 } 130 165 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) 132 167 { 133 168 if (pluginConfigurationId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0; … … 146 181 147 182 PluginConfigurationRequest request = j.configure(null); 183 184 // First, set default values 148 185 for (PluginParameter<?> p : request.getRequestInformation().getParameters()) 149 186 { 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 154 199 request.setParameterValue("source", bioAssaySet); 155 200 request.setParameterValue("pluginDirectory", Directory.getById(dc, directoryId).getPath().toString()); … … 202 247 } 203 248 } 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 204 261 } -
branches/2.6-stable/src/test/TestExperiment.java
r4124 r4212 102 102 103 103 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); 106 106 int jobId = test_create_root_bioassayset_using_plugin(id, formulaId, rbaId1, rbaId2); 107 107 TestJob.test_execute(jobId); -
branches/2.6-stable/src/test/TestFormula.java
r3679 r4212 44 44 write_header(); 45 45 // 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); 50 50 test_load(id); 51 51 test_list(-1); … … 59 59 } 60 60 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) 62 62 { 63 63 if (!TestUtil.hasPermission(Permission.CREATE, Item.FORMULA)) return 0; … … 75 75 f.setParser(Formula.Parser.JEP); 76 76 } 77 if (name != null) f.setName(name); 77 78 f.setFormulaType(formulaType); 78 79 f.setRawDataType(RawDataTypes.getRawDataType(rawDataType)); -
branches/2.6-stable/src/test/TestJob.java
r3679 r4212 95 95 if (response.getStatus() == Response.Status.ERROR) 96 96 { 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); 98 100 } 99 101 -
branches/2.6-stable/src/test/TestLowessNormalization.java
r3675 r4212 54 54 { 55 55 write("++Testing TestLowessNormalization"); 56 int experimentId = TestAnalyzePluginUtil.test_createExperiment( 2, 100);56 int experimentId = TestAnalyzePluginUtil.test_createExperiment("data/test.rawdata.import.txt", 2, 100); 57 57 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); 60 60 61 61 TestAnalyzePluginUtil.test_createRootBioAssaySet(experimentId, formulaId); -
branches/2.6-stable/src/test/TestMedianRatioNormalization.java
r3675 r4212 49 49 { 50 50 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); 54 54 TestAnalyzePluginUtil.test_createRootBioAssaySet(experimentId, formulaId); 55 55 int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.MedianRatioNormalization"); -
branches/2.6-stable/src/test/data/test.nullplugin.base
r4191 r4212 5 5 name Base1NullPlugin 6 6 descr Test base1pluginexecuter 7 execName runplugin.sh7 execName nullplugin.sh 8 8 geneAverages 0 9 9 serialFormat 1
Note: See TracChangeset
for help on using the changeset viewer.