use of org.cytoscape.model.internal.CyTableImpl in project cytoscape-impl by cytoscape.
the class MergeDataTableTaskTest method mappingToAllNetworksWithSubNetwork.
@Test
public void mappingToAllNetworksWithSubNetwork() throws Exception {
// set up tunable mutator
stm.addTunableHandlerFactory(syncTunableHandlerFactory, syncFactoryProp);
CyNetwork net1;
CyNetwork subnet1;
CyNetwork subnet2;
String node1Name = "node1";
String node2Name = "node2";
String row1Name = "node1";
String row2Name = "node2";
CyTableImpl table1;
CyTableImpl table2;
CyTableImpl table3;
CyTableImpl table4;
String table1sCol = "col1";
String table2sCol = "col2";
String table3sCol = "col3";
String table4sCol = "col4";
String table1sRow1 = "col1 row1";
String table1sRow2 = "col1 row2";
String table2sRow1 = "col2 row1";
String table2sRow2 = "col2 row2";
String table3sRow1 = "col3 row1";
String table3sRow2 = "col3 row2";
String table4sRow1 = "col4 row1";
String table4sRow2 = "col4 row2";
// creating first network with 2 nodes
net1 = support.getNetwork();
net1.getRow(net1).set(CyNetwork.NAME, "net1");
final CyNode node1 = net1.addNode();
final CyNode node2 = net1.addNode();
net1.addEdge(node1, node2, true);
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.NAME, node1Name);
net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyNetwork.NAME, node2Name);
netMgr.addNetwork(net1);
((CySubNetworkImpl) net1).handleEvent(new NetworkAddedEvent(netMgr, net1));
List<CyNetwork> firstnetlist = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
// creating a table for mapping to all networks
table1 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table1.createColumn(table1sCol, String.class, false);
CyRow row1 = table1.getRow(node1Name);
row1.set(table1sCol, table1sRow1);
CyRow row2 = table1.getRow(node2Name);
row2.set(table1sCol, table1sRow2);
root = rootNetMgr.getRootNetwork(net1);
List<String> listCols = new ArrayList<String>();
listCols.add(table1sCol);
mapping(table1, listCols, "ID", true, net1, root, root.getDefaultNodeTable().getColumn(CyRootNetwork.SHARED_NAME), false);
// check the mapping by task
assertNotNull(net1.getDefaultNodeTable().getColumn(table1sCol));
assertEquals(table1sRow1, net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table1sCol, String.class));
// creating a sub network to check if gets updated or not
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, true);
net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyNetwork.SELECTED, true);
NewNetworkSelectedNodesOnlyTask newNetTask = new NewNetworkSelectedNodesOnlyTask(mock(UndoSupport.class), net1, support.getRootNetworkFactory(), viewSupport.getNetworkViewFactory(), netMgr, mock(CyNetworkViewManager.class), mock(CyNetworkNaming.class), mock(VisualMappingManager.class), mock(CyApplicationManager.class), eventHelper, groupMgr, renderingEngineManager, mock(CyServiceRegistrar.class));
assertNotNull(newNetTask);
newNetTask.setTaskIterator(new TaskIterator(newNetTask));
newNetTask.run(mock(TaskMonitor.class));
List<CyNetwork> secondNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
secondNetList.removeAll(firstnetlist);
assertEquals(1, secondNetList.size());
subnet1 = secondNetList.get(0);
secondNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
((CySubNetworkImpl) subnet1).handleEvent(new NetworkAddedEvent(netMgr, subnet1));
assertEquals(2, subnet1.getNodeList().size());
assertNotNull(subnet1.getDefaultNodeTable().getColumn(table1sCol));
// these two tests are failing because the required table update when creating the subnetwork is not handled
// hence the nodes are there but the related rows in the table are empty
assertEquals(table1sRow1, subnet1.getRow(node1).get(table1sCol, String.class));
// creating another table to map to the net1 only
table2 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table2.createColumn(table2sCol, String.class, false);
CyRow row3 = table2.getRow(node1Name);
row3.set(table2sCol, table2sRow1);
CyRow row4 = table2.getRow(node2Name);
row4.set(table2sCol, table2sRow2);
root = rootNetMgr.getRootNetwork(net1);
listCols = new ArrayList<String>();
listCols.add(table2sCol);
mapping(table2, listCols, "ID", true, net1, root, root.getDefaultNodeTable().getColumn(CyRootNetwork.SHARED_NAME), true);
// check the mapping by task
assertNotNull(net1.getDefaultNodeTable().getColumn(table2sCol));
assertEquals(table2sRow1, net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table2sCol, String.class));
// subnet1 should not be mapped
assertNull(subnet1.getDefaultNodeTable().getColumn(table2sCol));
// creating another subnetwork (subnet2) to check that bot virtual columns will be added
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, true);
NewNetworkSelectedNodesOnlyTask newNetTask2 = new NewNetworkSelectedNodesOnlyTask(mock(UndoSupport.class), net1, support.getRootNetworkFactory(), viewSupport.getNetworkViewFactory(), netMgr, mock(CyNetworkViewManager.class), mock(CyNetworkNaming.class), mock(VisualMappingManager.class), mock(CyApplicationManager.class), eventHelper, groupMgr, renderingEngineManager, mock(CyServiceRegistrar.class));
assertNotNull(newNetTask2);
newNetTask2.setTaskIterator(new TaskIterator(newNetTask2));
newNetTask2.run(mock(TaskMonitor.class));
List<CyNetwork> thirdNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
thirdNetList.removeAll(secondNetList);
assertEquals(1, thirdNetList.size());
subnet2 = thirdNetList.get(0);
((CySubNetworkImpl) subnet2).handleEvent(new NetworkAddedEvent(netMgr, subnet2));
assertEquals(2, subnet2.getNodeList().size());
// check that the new subnetwork has both columns
assertNotNull(subnet2.getDefaultNodeTable().getColumn(table1sCol));
assertNotNull(subnet2.getDefaultNodeTable().getColumn(table2sCol));
// these two tests are failing because the required table update when creating the subnetwork is not handled
// hence the nodes are there but the related rows in the table are empty
assertEquals(table1sRow1, subnet2.getRow(node1).get(table1sCol, String.class));
assertEquals(table2sRow1, subnet2.getRow(node1).get(table2sCol, String.class));
// creating another table to map to the net1 only
table3 = new CyTableImpl("dummy table 3", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table3.createColumn(table2sCol, String.class, false);
table3.createColumn(table3sCol, String.class, false);
CyRow rowTemp;
rowTemp = table3.getRow(row1Name);
rowTemp.set(table2sCol, table2sRow1);
rowTemp.set(table3sCol, table3sRow1);
rowTemp = table3.getRow(row2Name);
rowTemp.set(table2sCol, table2sRow2);
rowTemp.set(table3sCol, table3sRow2);
table4 = new CyTableImpl("dummy table 4", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table4.createColumn(table2sCol, String.class, false);
table4.createColumn(table4sCol, String.class, false);
rowTemp = table4.getRow(row1Name);
rowTemp.set(table2sCol, table2sRow1);
rowTemp.set(table4sCol, table4sRow1);
rowTemp = table4.getRow(row2Name);
rowTemp.set(table2sCol, table2sRow2);
rowTemp.set(table4sCol, table4sRow2);
tableMgr.addTable(table3);
tableMgr.addTable(table4);
List<String> listCols2 = new ArrayList<String>();
listCols2.add(table3sCol);
mappingGlobalTable(table3, table4, listCols2, table2sCol, false, null, null, table4.getColumn(table2sCol), false);
assertEquals(table3sRow1, table4.getRow(row1Name).get(table3sCol, String.class));
assertEquals(table3sRow2, table4.getRow(row2Name).get(table3sCol, String.class));
}
use of org.cytoscape.model.internal.CyTableImpl in project cytoscape-impl by cytoscape.
the class CyTableManagerTest method tableWithVirtColumnDeletionTest.
@Test
public void tableWithVirtColumnDeletionTest() {
final Interpreter interpreter = new InterpreterImpl();
CyTable table = new CyTableImpl("homer", CyIdentifiable.SUID, Long.class, true, true, SavePolicy.SESSION_FILE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 1000);
CyTable table2 = new CyTableImpl("marge", CyIdentifiable.SUID, Long.class, true, true, SavePolicy.SESSION_FILE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 1000);
table.createColumn("x", Long.class, false);
CyColumn column = table.getColumn("x");
assertNull(column.getVirtualColumnInfo().getSourceTable());
table2.createListColumn("b", Boolean.class, false);
table.addVirtualColumn("b1", "b", table2, "x", true);
mgr.addTable(table2);
boolean caughtException = false;
try {
mgr.deleteTable(table2.getSUID());
} catch (IllegalArgumentException e) {
caughtException = true;
}
assertTrue(caughtException);
table2.deleteColumn("b1");
mgr.deleteTable(table.getSUID());
}
use of org.cytoscape.model.internal.CyTableImpl in project cytoscape-impl by cytoscape.
the class CyTableTest method setUp.
@Before
public void setUp() {
eventHelper = new DummyCyEventHelper();
compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
final Interpreter interpreter = new InterpreterImpl();
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
table = new CyTableImpl("homer", CyIdentifiable.SUID, Long.class, false, true, SavePolicy.SESSION_FILE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 1000);
attrs = table.getRow(1L);
table2 = new CyTableImpl("marge", CyIdentifiable.SUID, Long.class, false, true, SavePolicy.SESSION_FILE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 1000);
CyTableManagerImpl tblMgr = new CyTableManagerImpl(new CyNetworkTableManagerImpl(), new CyNetworkManagerImpl(serviceRegistrar), serviceRegistrar);
tblMgr.addTable(table);
((CyTableImpl) table).handleEvent(new TableAddedEvent(tblMgr, table));
tblMgr.addTable(table2);
((CyTableImpl) table2).handleEvent(new TableAddedEvent(tblMgr, table2));
}
use of org.cytoscape.model.internal.CyTableImpl in project cytoscape-impl by cytoscape.
the class MappingIntegrationTest method mappingToAllNetworksWithSubNetwork.
@Test
public void mappingToAllNetworksWithSubNetwork() throws Exception {
// set up tunable mutator
stm.addTunableHandlerFactory(syncTunableHandlerFactory, syncFactoryProp);
CyNetwork net1;
CyNetwork subnet1;
CyNetwork subnet2;
String node1Name = "node1";
String node2Name = "node2";
CyTableImpl table1;
CyTableImpl table2;
String table1sCol = "col1";
String table2sCol = "col2";
String table1sRow1 = "col1 row1";
String table1sRow2 = "col1 row2";
String table2sRow1 = "col2 row2";
String table2sRow2 = "col2 row2";
// creating first network with 2 nodes
net1 = support.getNetwork();
net1.getRow(net1).set(CyNetwork.NAME, "net1");
final CyNode node1 = net1.addNode();
final CyNode node2 = net1.addNode();
net1.addEdge(node1, node2, true);
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.NAME, node1Name);
net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyNetwork.NAME, node2Name);
netMgr.addNetwork(net1);
((CySubNetworkImpl) net1).handleEvent(new NetworkAddedEvent(netMgr, net1));
List<CyNetwork> firstnetlist = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
// creating a table for mapping to all networks
table1 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table1.createColumn(table1sCol, String.class, false);
CyRow row1 = table1.getRow(node1Name);
row1.set(table1sCol, table1sRow1);
CyRow row2 = table1.getRow(node2Name);
row2.set(table1sCol, table1sRow2);
root = rootNetMgr.getRootNetwork(net1);
mapping(table1, net1, root, root.getDefaultNodeTable().getColumn(CyRootNetwork.SHARED_NAME), false);
// check the mapping by task
assertNotNull(net1.getDefaultNodeTable().getColumn(table1sCol));
assertEquals(table1sRow1, net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table1sCol, String.class));
// creating a sub network to check if gets updated or not
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, true);
net1.getDefaultNodeTable().getRow(node2.getSUID()).set(CyNetwork.SELECTED, true);
NewNetworkSelectedNodesOnlyTask newNetTask = new NewNetworkSelectedNodesOnlyTask(mock(UndoSupport.class), net1, support.getRootNetworkFactory(), viewSupport.getNetworkViewFactory(), netMgr, mock(CyNetworkViewManager.class), mock(CyNetworkNaming.class), mock(VisualMappingManager.class), mock(CyApplicationManager.class), eventHelper, groupMgr, renderingEngineManager, mock(CyServiceRegistrar.class));
assertNotNull(newNetTask);
newNetTask.setTaskIterator(new TaskIterator(newNetTask));
newNetTask.run(mock(TaskMonitor.class));
List<CyNetwork> secondNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
secondNetList.removeAll(firstnetlist);
assertEquals(1, secondNetList.size());
subnet1 = secondNetList.get(0);
secondNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
((CySubNetworkImpl) subnet1).handleEvent(new NetworkAddedEvent(netMgr, subnet1));
assertEquals(2, subnet1.getNodeList().size());
assertNotNull(subnet1.getDefaultNodeTable().getColumn(table1sCol));
// these two tests are failing because the required table update when creating the subnetwork is not handled
// hence the nodes are there but the related rows in the table are empty
assertEquals(table1sRow1, subnet1.getRow(node1).get(table1sCol, String.class));
// creating another table to map to the net1 only
table2 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), interpreter, 2);
table2.createColumn(table2sCol, String.class, false);
CyRow row3 = table2.getRow(node1Name);
row3.set(table2sCol, table2sRow1);
CyRow row4 = table2.getRow(node2Name);
row4.set(table2sCol, table2sRow2);
root = rootNetMgr.getRootNetwork(net1);
mapping(table2, net1, root, root.getDefaultNodeTable().getColumn(CyRootNetwork.SHARED_NAME), true);
// check the mapping by task
assertNotNull(net1.getDefaultNodeTable().getColumn(table2sCol));
assertEquals(table2sRow1, net1.getDefaultNodeTable().getRow(node1.getSUID()).get(table2sCol, String.class));
// subnet1 should not be mapped
assertNull(subnet1.getDefaultNodeTable().getColumn(table2sCol));
// creating another subnetwork (subnet2) to check that bot virtual columns will be added
net1.getDefaultNodeTable().getRow(node1.getSUID()).set(CyNetwork.SELECTED, true);
NewNetworkSelectedNodesOnlyTask newNetTask2 = new NewNetworkSelectedNodesOnlyTask(mock(UndoSupport.class), net1, support.getRootNetworkFactory(), viewSupport.getNetworkViewFactory(), netMgr, mock(CyNetworkViewManager.class), mock(CyNetworkNaming.class), mock(VisualMappingManager.class), mock(CyApplicationManager.class), eventHelper, groupMgr, renderingEngineManager, mock(CyServiceRegistrar.class));
assertNotNull(newNetTask2);
newNetTask2.setTaskIterator(new TaskIterator(newNetTask2));
newNetTask2.run(mock(TaskMonitor.class));
List<CyNetwork> thirdNetList = new ArrayList<CyNetwork>(netMgr.getNetworkSet());
thirdNetList.removeAll(secondNetList);
assertEquals(1, thirdNetList.size());
subnet2 = thirdNetList.get(0);
((CySubNetworkImpl) subnet2).handleEvent(new NetworkAddedEvent(netMgr, subnet2));
assertEquals(2, subnet2.getNodeList().size());
// check that the new subnetwork has both columns
assertNotNull(subnet2.getDefaultNodeTable().getColumn(table1sCol));
assertNotNull(subnet2.getDefaultNodeTable().getColumn(table2sCol));
// these two tests are failing because the required table update when creating the subnetwork is not handled
// hence the nodes are there but the related rows in the table are empty
assertEquals(table1sRow1, subnet2.getRow(node1).get(table1sCol, String.class));
assertEquals(table2sRow1, subnet2.getRow(node1).get(table2sCol, String.class));
}
use of org.cytoscape.model.internal.CyTableImpl in project cytoscape-impl by cytoscape.
the class JoinTablesTaskTest method createTable.
private final CyTable createTable(String col, String listCol) {
CyTable table1 = new CyTableImpl("dummy table", "ID", String.class, true, true, SavePolicy.DO_NOT_SAVE, eventHelper, ColumnDataFactory.createDefaultFactory(), new InterpreterImpl(), 2);
table1.createColumn(col, String.class, false);
CyRow row1 = table1.getRow(node1Name);
row1.set(col, "col1 row1");
CyRow row2 = table1.getRow(node2Name);
row2.set(col, "col1 row2");
List<String> s = new ArrayList<String>();
s.add("listRow1-1");
s.add("listRow1-2");
List<String> s2 = new ArrayList<String>();
s2.add("listRow2-1");
s2.add("listRow2-2");
table1.createListColumn(listCol, String.class, false);
CyRow listRow1 = table1.getRow(node1Name);
listRow1.set(listCol, s);
CyRow listRow2 = table1.getRow(node2Name);
listRow2.set(listCol, s2);
return table1;
}
Aggregations