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();
}
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));
}
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));
}
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);
}
}
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));
}
Aggregations