Search in sources :

Example 1 with NewNetworkSelectedNodesOnlyTask

use of org.cytoscape.task.internal.network.NewNetworkSelectedNodesOnlyTask 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));
}
Also used : NetworkAddedEvent(org.cytoscape.model.events.NetworkAddedEvent) CySubNetworkImpl(org.cytoscape.model.internal.CySubNetworkImpl) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) NewNetworkSelectedNodesOnlyTask(org.cytoscape.task.internal.network.NewNetworkSelectedNodesOnlyTask) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyTableImpl(org.cytoscape.model.internal.CyTableImpl) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Example 2 with NewNetworkSelectedNodesOnlyTask

use of org.cytoscape.task.internal.network.NewNetworkSelectedNodesOnlyTask 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));
}
Also used : NetworkAddedEvent(org.cytoscape.model.events.NetworkAddedEvent) CySubNetworkImpl(org.cytoscape.model.internal.CySubNetworkImpl) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) NewNetworkSelectedNodesOnlyTask(org.cytoscape.task.internal.network.NewNetworkSelectedNodesOnlyTask) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyTableImpl(org.cytoscape.model.internal.CyTableImpl) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)2 CyNetwork (org.cytoscape.model.CyNetwork)2 CyNode (org.cytoscape.model.CyNode)2 CyRow (org.cytoscape.model.CyRow)2 NetworkAddedEvent (org.cytoscape.model.events.NetworkAddedEvent)2 CySubNetworkImpl (org.cytoscape.model.internal.CySubNetworkImpl)2 CyTableImpl (org.cytoscape.model.internal.CyTableImpl)2 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)2 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)2 NewNetworkSelectedNodesOnlyTask (org.cytoscape.task.internal.network.NewNetworkSelectedNodesOnlyTask)2 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)2 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)2 TaskIterator (org.cytoscape.work.TaskIterator)2 TaskMonitor (org.cytoscape.work.TaskMonitor)2 UndoSupport (org.cytoscape.work.undo.UndoSupport)2 Test (org.junit.Test)2