Search in sources :

Example 16 with NetworkTestSupport

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

the class UiScaffold method start.

void start() {
    MockitoAnnotations.initMocks(this);
    Random random = new Random(0);
    NetworkTestSupport networkTestSupport = new NetworkTestSupport();
    CyNetwork network = networkTestSupport.getNetwork();
    CyTable nodeTable = network.getDefaultNodeTable();
    nodeTable.createColumn("Score", Double.class, false);
    nodeTable.createColumn("IsSpecial", Boolean.class, false);
    for (int i = 0; i < TOTAL_NODES; i++) {
        CyNode node = network.addNode();
        network.getRow(node).set("Score", random.nextGaussian());
        network.getRow(node).set("IsSpecial", i % 2 == 0);
    }
    List<CyNode> nodes = network.getNodeList();
    for (int i = 0; i < TOTAL_EDGES; i++) {
        CyNode source = nodes.get(random.nextInt(nodes.size()));
        CyNode target = nodes.get(random.nextInt(nodes.size()));
        network.addEdge(source, target, false);
    }
    when(applicationManager.getCurrentNetworkView()).thenReturn(networkView);
    when(applicationManager.getCurrentNetwork()).thenReturn(network);
    when(networkView.getModel()).thenReturn(network);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
    when(serviceRegistrar.getService(TaskManager.class)).thenReturn(taskManager);
    when(serviceRegistrar.getService(IconManager.class)).thenReturn(iconManager);
    JFrame frame = new JFrame();
    frame.setTitle("Select");
    Map<String, String> properties = Collections.emptyMap();
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    transformerManager.registerFilterFactory(new ColumnFilterFactory(), properties);
    transformerManager.registerFilterFactory(new DegreeFilterFactory(), properties);
    transformerManager.registerFilterFactory(new TopologyFilterFactory(), properties);
    transformerManager.registerElementTransformerFactory(new InteractionTransformerFactory(), properties);
    ModelMonitor modelMonitor = new ModelMonitor();
    modelMonitor.handleEvent(new SetCurrentNetworkEvent(applicationManager, network));
    ValidationManager validationManager = new ValidationManager();
    FilterPanelStyle style = new StandardStyle();
    TransformerViewManager transformerViewManager = new TransformerViewManager(transformerManager);
    // transformerViewManager.registerTransformerViewFactory(new ColumnFilterViewFactory(style, modelMonitor), properties);
    transformerViewManager.registerTransformerViewFactory(new DegreeFilterViewFactory(style, modelMonitor), properties);
    transformerViewManager.registerTransformerViewFactory(new TopologyFilterViewFactory(style), properties);
    transformerViewManager.registerTransformerViewFactory(new InteractionTransformerViewFactory(style), properties);
    LazyWorkQueue queue = new LazyWorkQueue();
    FilterWorker filterWorker = new FilterWorker(queue, serviceRegistrar);
    FilterIO filterIo = null;
    FilterPanelController filterPanelController = new FilterPanelController(transformerManager, transformerViewManager, validationManager, filterWorker, modelMonitor, filterIo, style, serviceRegistrar);
    FilterPanel filterPanel = new FilterPanel(filterPanelController, filterWorker, serviceRegistrar);
    TransformerWorker transformerWorker = new TransformerWorker(queue, transformerManager, serviceRegistrar);
    TransformerPanelController transformerPanelController = new TransformerPanelController(transformerManager, transformerViewManager, validationManager, filterPanelController, transformerWorker, filterIo, style, serviceRegistrar);
    TransformerPanel transformerPanel = new TransformerPanel(transformerPanelController, transformerWorker, serviceRegistrar);
    SelectPanel selectPanel = new SelectPanel(filterPanel, transformerPanel);
    JRootPane root = frame.getRootPane();
    root.setLayout(new GridBagLayout());
    root.add(selectPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    frame.setSize(450, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
Also used : TransformerViewManager(org.cytoscape.filter.internal.view.TransformerViewManager) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) InteractionTransformerFactory(org.cytoscape.filter.internal.transformers.interaction.InteractionTransformerFactory) CyNetwork(org.cytoscape.model.CyNetwork) FilterPanel(org.cytoscape.filter.internal.view.FilterPanel) FilterPanelStyle(org.cytoscape.filter.internal.view.look.FilterPanelStyle) CyTable(org.cytoscape.model.CyTable) Random(java.util.Random) JFrame(javax.swing.JFrame) CyNode(org.cytoscape.model.CyNode) LazyWorkQueue(org.cytoscape.filter.internal.work.LazyWorkQueue) SetCurrentNetworkEvent(org.cytoscape.application.events.SetCurrentNetworkEvent) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl) ColumnFilterFactory(org.cytoscape.filter.internal.filters.column.ColumnFilterFactory) ValidationManager(org.cytoscape.filter.internal.work.ValidationManager) StandardStyle(org.cytoscape.filter.internal.view.look.StandardStyle) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) TopologyFilterFactory(org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory) InteractionTransformerViewFactory(org.cytoscape.filter.internal.transformers.interaction.InteractionTransformerViewFactory) DegreeFilterFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterFactory) SelectPanel(org.cytoscape.filter.internal.view.SelectPanel) TopologyFilterViewFactory(org.cytoscape.filter.internal.filters.topology.TopologyFilterViewFactory) TransformerPanelController(org.cytoscape.filter.internal.view.TransformerPanelController) TransformerPanel(org.cytoscape.filter.internal.view.TransformerPanel) FilterWorker(org.cytoscape.filter.internal.work.FilterWorker) DegreeFilterViewFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterViewFactory) FilterPanelController(org.cytoscape.filter.internal.view.FilterPanelController) JRootPane(javax.swing.JRootPane) TransformerWorker(org.cytoscape.filter.internal.work.TransformerWorker)

Example 17 with NetworkTestSupport

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

the class GraphMLReaderTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    testSupport = new NetworkTestSupport();
    nvts = new NetworkViewTestSupport();
    rootFactory = testSupport.getRootNetworkFactory();
    netFactory = testSupport.getNetworkFactory();
    viewFactory = nvts.getNetworkViewFactory();
    networkManager = testSupport.getNetworkManager();
    when(netViewRenderer.getNetworkViewFactory()).thenReturn(viewFactory);
    when(appManager.getDefaultNetworkViewRenderer()).thenReturn(netViewRenderer);
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) Before(org.junit.Before)

Example 18 with NetworkTestSupport

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

the class ColumnFilterTest method testColumnFilterInteger.

@Test
public void testColumnFilterInteger() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createColumn("i", Integer.class, false);
    CyNode n1 = network.addNode();
    CyNode n2 = network.addNode();
    CyNode n3 = network.addNode();
    CyNode n4 = network.addNode();
    network.getRow(n1).set("i", 111);
    network.getRow(n2).set("i", 222);
    network.getRow(n3).set("i", 333);
    ColumnFilter columnFilter = new ColumnFilter("i", Predicate.BETWEEN, new Number[] { 200, 300 });
    assertFalse(columnFilter.accepts(network, n1));
    assertTrue(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
    assertFalse(columnFilter.accepts(network, n4));
    columnFilter.setPredicateAndCriterion(Predicate.IS_NOT_BETWEEN, new Number[] { 200, 300 });
    assertTrue(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n3));
    assertTrue(columnFilter.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) Test(org.junit.Test)

Example 19 with NetworkTestSupport

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

the class ColumnFilterTest method testColumnFilterString.

@Test
public void testColumnFilterString() {
    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", "aaa");
    network.getRow(n2).set("s", "bbb");
    network.getRow(n3).set("s", "ccc");
    ColumnFilter columnFilter = new ColumnFilter("s", Predicate.CONTAINS, "a");
    assertTrue(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
    assertFalse(columnFilter.accepts(network, n4));
    columnFilter.setPredicateAndCriterion(Predicate.DOES_NOT_CONTAIN, "a");
    assertFalse(columnFilter.accepts(network, n1));
    assertTrue(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n3));
    assertTrue(columnFilter.accepts(network, n4));
    columnFilter.setPredicateAndCriterion(Predicate.IS, "a");
    assertFalse(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
    assertFalse(columnFilter.accepts(network, n4));
    columnFilter.setPredicateAndCriterion(Predicate.IS, "aaa");
    assertTrue(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
    assertFalse(columnFilter.accepts(network, n4));
    columnFilter.setPredicateAndCriterion(Predicate.IS_NOT, "aaa");
    assertFalse(columnFilter.accepts(network, n1));
    assertTrue(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n3));
    assertTrue(columnFilter.accepts(network, n4));
    columnFilter.setPredicateAndCriterion(Predicate.REGEX, ".a.");
    assertTrue(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
    assertFalse(columnFilter.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) Test(org.junit.Test)

Example 20 with NetworkTestSupport

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

the class TopologyFilterTest method testTopologyFilterCycle.

@Test
public void testTopologyFilterCycle() {
    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.addEdge(n1, n2, false);
    network.addEdge(n2, n3, false);
    network.addEdge(n3, n1, false);
    network.addEdge(n3, n1, false);
    network.addEdge(n3, n4, false);
    network.getRow(n4).set("s", "a");
    TopologyFilter topologyFilter = new TopologyFilter();
    topologyFilter.setThreshold(1);
    topologyFilter.setDistance(100);
    topologyFilter.setPredicate(Predicate.GREATER_THAN_OR_EQUAL);
    ColumnFilter columnFilter = new ColumnFilter("s", Predicate.IS, "a");
    topologyFilter.append(columnFilter);
    // not getting caught in a cycle!
    assertTrue(topologyFilter.accepts(network, n1));
    topologyFilter.setThreshold(10);
    topologyFilter.setDistance(1000);
    topologyFilter.setPredicate(Predicate.GREATER_THAN_OR_EQUAL);
    // not getting caught in a cycle!
    assertFalse(topologyFilter.accepts(network, n1));
}
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) TopologyFilter(org.cytoscape.filter.internal.filters.topology.TopologyFilter) 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