Search in sources :

Example 6 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class CyGroupTest method setUp.

@Before
public void setUp() {
    NetworkTestSupport support = new NetworkTestSupport();
    net = support.getNetwork();
    groupFactory = TestCyGroupFactory.getFactory();
    defaultSetUp();
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) Before(org.junit.Before)

Example 7 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class CompositeFilterTest method testCompositeFilterEmpty.

@Test
public void testCompositeFilterEmpty() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createColumn("s", String.class, false);
    CyNode n1 = network.addNode();
    network.getRow(n1).set("s", "abc");
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
    composite.setType(Type.ANY);
    assertTrue(composite.accepts(network, n1));
    composite.setType(Type.ALL);
    assertTrue(composite.accepts(network, n1));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CompositeFilterImpl(org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl) CyIdentifiable(org.cytoscape.model.CyIdentifiable) Test(org.junit.Test)

Example 8 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class CompositeFilterTest method testCompositeFilterString.

@Test
public void testCompositeFilterString() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createColumn("s", String.class, false);
    CyNode n1 = network.addNode();
    CyNode n2 = network.addNode();
    CyNode n3 = network.addNode();
    CyNode n4 = network.addNode();
    network.getRow(n1).set("s", "abc");
    network.getRow(n2).set("s", "def");
    network.getRow(n3).set("s", "aa");
    ColumnFilter filterForA = new ColumnFilter("s", Predicate.CONTAINS, "a");
    ColumnFilter filterForB = new ColumnFilter("s", Predicate.CONTAINS, "b");
    ColumnFilter filterForC = new ColumnFilter("s", Predicate.CONTAINS, "c");
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
    composite.append(filterForA);
    composite.append(filterForB);
    composite.append(filterForC);
    composite.setType(Type.ANY);
    assertTrue(composite.accepts(network, n1));
    assertFalse(composite.accepts(network, n2));
    assertTrue(composite.accepts(network, n3));
    assertFalse(composite.accepts(network, n4));
    composite.setType(Type.ALL);
    assertTrue(composite.accepts(network, n1));
    assertFalse(composite.accepts(network, n2));
    assertFalse(composite.accepts(network, n3));
    assertFalse(composite.accepts(network, n4));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) CompositeFilterImpl(org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl) CyIdentifiable(org.cytoscape.model.CyIdentifiable) Test(org.junit.Test)

Example 9 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class PerformanceScaffold method main.

public static void main(String[] args) {
    NetworkTestSupport testSupport = new NetworkTestSupport();
    CyNetwork network = testSupport.getNetwork();
    CyTable nodeTable = network.getDefaultNodeTable();
    nodeTable.createColumn(STRING_COLUMN, String.class, false);
    nodeTable.createColumn(INTEGER_COLUMN, Integer.class, false);
    nodeTable.createListColumn(LIST_STRING_COLUMN, String.class, false);
    // Use a fixed set of string attributes.
    // Worst case performance for trie expected for first entry
    // Best case performance expected for last entry
    Random random = new Random(1);
    String[] values = { "AAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAB", "AAAAAAAAAAAAACA", "AAAAAAAAAAAADAA", "AAAAAAAAAAAEAAA", "AAAAAAAAAAFAAAA", "AAAAAAAAAGAAAAA", "AAAAAAAAHAAAAAA", "AAAAAAAIAAAAAAA", "AAAAAAJAAAAAAAA", "AAAAAKAAAAAAAAA", "AAAALAAAAAAAAAA", "AAAMAAAAAAAAAAA", "AANAAAAAAAAAAAA", "AOAAAAAAAAAAAAA", "PAAAAAAAAAAAAAA" };
    int totalNodes = TOTAL_NODES;
    int totalEdges = totalNodes * AVERAGE_EDGES_PER_NODE;
    long start;
    start = System.currentTimeMillis();
    List<CyNode> nodes = new ArrayList<CyNode>();
    for (int i = 0; i < totalNodes; i++) {
        CyNode node = network.addNode();
        int valueIndex = random.nextInt(values.length);
        network.getRow(node).set(STRING_COLUMN, values[valueIndex]);
        network.getRow(node).set(INTEGER_COLUMN, valueIndex);
        network.getRow(node).set(LIST_STRING_COLUMN, Collections.singletonList(values[valueIndex]));
        nodes.add(node);
    }
    // Construct random graph
    for (int i = 0; i < totalEdges; i++) {
        CyNode source = nodes.get(random.nextInt(totalNodes));
        CyNode target = nodes.get(random.nextInt(totalNodes));
        network.addEdge(source, target, true);
    }
    System.out.printf("Construct\t%d\n", System.currentTimeMillis() - start);
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    Map<String, String> properties = Collections.emptyMap();
    transformerManager.registerTransformerSource(new CyNetworkSource(), properties);
    List<UseCase> useCases = new ArrayList<UseCase>();
    QuickFind quickFind = new QuickFindImpl();
    useCases.add(new NumberAttributeUseCase(quickFind, 0, transformerManager));
    useCases.add(new StringAttributeUseCase(quickFind, values[values.length - 1], transformerManager));
    useCases.add(new DegreeUseCase(3, transformerManager));
    for (UseCase useCase : useCases) {
        useCase.execute(network, ITERATIONS);
    }
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) QuickFindImpl(org.cytoscape.filter.internal.quickfind.util.QuickFindImpl) CyTable(org.cytoscape.model.CyTable) Random(java.util.Random) QuickFind(org.cytoscape.filter.internal.quickfind.util.QuickFind) CyNode(org.cytoscape.model.CyNode) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl)

Example 10 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class TestCyGroupFactory method testMetaEdges.

// Test maintenance of meta-edges
// Create two groups that share edges
// Collapse both and expand them in the opposite order
@Test
public void testMetaEdges() throws Exception {
    // Set up our data structures
    final CyGroupFactory factory = TestCyGroupFactory.getFactory();
    final NetworkTestSupport support = new NetworkTestSupport();
    final CyNetwork net = support.getNetwork();
    final CyNode nodeA = net.addNode();
    final CyNode nodeB = net.addNode();
    final CyNode nodeC = net.addNode();
    final CyNode nodeD = net.addNode();
    final CyNode nodeE = net.addNode();
    final CyEdge edge1 = net.addEdge(nodeA, nodeE, false);
    final CyEdge edge2 = net.addEdge(nodeE, nodeB, false);
    final CyEdge edge3 = net.addEdge(nodeE, nodeC, false);
    final CyEdge edge4 = net.addEdge(nodeE, nodeD, false);
    final CyEdge edge5 = net.addEdge(nodeC, nodeB, false);
    final CyEdge edge6 = net.addEdge(nodeC, nodeD, false);
    final CyGroup group1 = factory.createGroup(net, null, Arrays.asList(nodeA, nodeB, nodeC), null, true);
    assertNotNull(group1);
    assertEqualWithoutOrder(group1.getNodeList(), Arrays.asList(nodeA, nodeB, nodeC));
    assertEqualWithoutOrder(group1.getInternalEdgeList(), Arrays.asList(edge5));
    assertEqualWithoutOrder(group1.getExternalEdgeList(), Arrays.asList(edge1, edge2, edge3, edge6));
    final CyGroup group2 = factory.createGroup(net, null, Arrays.asList(nodeD, nodeE), null, true);
    assertNotNull(group2);
    assertEqualWithoutOrder(group2.getNodeList(), Arrays.asList(nodeD, nodeE));
    assertEqualWithoutOrder(group2.getInternalEdgeList(), Arrays.asList(edge4));
    // 4 external edges, we create meta-edges when we collapse
    assertTrue(group2.getExternalEdgeList().size() == 4);
    // Collapse both groups
    group1.collapse(net);
    assertTrue(group1.isCollapsed(net));
    group2.collapse(net);
    assertTrue(group2.isCollapsed(net));
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(group1.getGroupNode(), group2.getGroupNode()));
    // Expand in opposite order
    group1.expand(net);
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(nodeA, nodeB, nodeC, group2.getGroupNode()));
    // 1 internal edge + 3 meta-edges
    assertTrue(net.getEdgeList().size() == 4);
    group2.expand(net);
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(nodeA, nodeB, nodeC, nodeD, nodeE));
    assertEqualWithoutOrder(net.getEdgeList(), Arrays.asList(edge1, edge2, edge3, edge4, edge5, edge6));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Aggregations

NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)23 CyNetwork (org.cytoscape.model.CyNetwork)17 CyNode (org.cytoscape.model.CyNode)16 Test (org.junit.Test)15 ColumnFilter (org.cytoscape.filter.internal.filters.column.ColumnFilter)7 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)6 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)6 TaskMonitor (org.cytoscape.work.TaskMonitor)6 Before (org.junit.Before)6 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)4 TaskIterator (org.cytoscape.work.TaskIterator)4 CyEventHelper (org.cytoscape.event.CyEventHelper)3 CyEdge (org.cytoscape.model.CyEdge)3 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)3 CyRootNetworkManagerImpl (org.cytoscape.model.internal.CyRootNetworkManagerImpl)3 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 CompositeFilterImpl (org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl)2