Search in sources :

Example 1 with TopologyFilter

use of org.cytoscape.filter.internal.filters.topology.TopologyFilter in project cytoscape-impl by cytoscape.

the class TopologyFilterTest method testTopologyFilter.

@Test
public void testTopologyFilter() {
    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();
    CyNode n5 = network.addNode();
    CyNode n6 = network.addNode();
    CyNode n7 = network.addNode();
    CyNode n8 = network.addNode();
    network.addEdge(n1, n2, false);
    network.addEdge(n1, n3, false);
    network.addEdge(n1, n4, false);
    network.addEdge(n2, n5, false);
    network.addEdge(n3, n6, false);
    network.addEdge(n4, n7, false);
    network.addEdge(n7, n8, false);
    TopologyFilter topologyFilter = new TopologyFilter();
    topologyFilter.setThreshold(6);
    topologyFilter.setDistance(2);
    topologyFilter.setPredicate(Predicate.GREATER_THAN_OR_EQUAL);
    assertTrue(topologyFilter.accepts(network, n1));
    topologyFilter.setDistance(1);
    assertFalse(topologyFilter.accepts(network, n1));
    network.getRow(n2).set("s", "a");
    network.getRow(n6).set("s", "a");
    ColumnFilter columnFilter = new ColumnFilter("s", Predicate.IS, "a");
    assertTrue(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n6));
    topologyFilter.append(columnFilter);
    topologyFilter.setThreshold(2);
    topologyFilter.setDistance(2);
    assertTrue(topologyFilter.accepts(network, n1));
    topologyFilter.setDistance(1);
    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)

Example 2 with TopologyFilter

use of org.cytoscape.filter.internal.filters.topology.TopologyFilter in project cytoscape-impl by cytoscape.

the class CreateFilterTaskTest method testCreateTopologyFilter.

@Test
public void testCreateTopologyFilter() {
    CreateFilterTask task = new CreateFilterTask(serviceRegistrar, "MyFilter");
    String subFilterJson = "{ \"id\" : \"ColumnFilter\", \"parameters\" : { \"criterion\" : \"1\", \"columnName\" : \"name\", \"predicate\" : \"CONTAINS\"} }";
    task.jsonTunable.json = "{ \"id\" : \"TopologyFilter\", \"parameters\" : { \"predicate\" : \"GREATER_THAN_OR_EQUAL\", \"distance\" : 3, \"threshold\" : 2, \"type\" : \"ALL\" }, \"transformers\" : [ " + subFilterJson + "] }";
    TaskMonitor tm = mock(TaskMonitor.class);
    task.run(tm);
    verify(tm, times(0)).showMessage(any(), any());
    NamedTransformer<CyNetwork, CyIdentifiable> transformer = transformerContainer.getNamedTransformer(task.name);
    assertNotNull(transformer);
    TopologyFilter topoFilter = (TopologyFilter) transformer.getTransformers().get(0);
    assertEquals(Predicate.GREATER_THAN_OR_EQUAL, topoFilter.getPredicate());
    assertEquals(new Integer(3), topoFilter.getDistance());
    assertEquals(new Integer(2), topoFilter.getThreshold());
    assertEquals(CompositeFilter.Type.ALL, topoFilter.getType());
    assertEquals(1, topoFilter.getLength());
    ColumnFilter columnFilter = (ColumnFilter) topoFilter.get(0);
    assertEquals(Predicate.CONTAINS, columnFilter.getPredicate());
    assertEquals("1", columnFilter.getCriterion());
    assertEquals("name", columnFilter.getColumnName());
}
Also used : TaskMonitor(org.cytoscape.work.TaskMonitor) CyNetwork(org.cytoscape.model.CyNetwork) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) CyIdentifiable(org.cytoscape.model.CyIdentifiable) TopologyFilter(org.cytoscape.filter.internal.filters.topology.TopologyFilter) Test(org.junit.Test)

Example 3 with TopologyFilter

use of org.cytoscape.filter.internal.filters.topology.TopologyFilter 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)

Example 4 with TopologyFilter

use of org.cytoscape.filter.internal.filters.topology.TopologyFilter in project cytoscape-impl by cytoscape.

the class FilterIOTest method testLoadOldTopologyFilter.

/**
 * The topology filter was made a composite filter in 3.3. Older versions of cytoscape
 * will export a topology filter without the "transformers" field that is part of
 * composite filters. The filter json parser was enhanced to support this.
 */
@SuppressWarnings("rawtypes")
@Test
public void testLoadOldTopologyFilter() throws IOException {
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    Map<String, String> properties = Collections.emptyMap();
    transformerManager.registerFilterFactory(new CompositeFilterFactory<CyNetwork, CyIdentifiable>(CyNetwork.class, CyIdentifiable.class), properties);
    transformerManager.registerFilterFactory(new TopologyFilterFactory(), properties);
    transformerManager.registerFilterFactory(new ColumnFilterFactory(), properties);
    String path = "./src/test/resources/testData/filter/topology-filter-3.2.json";
    byte[] encoded = Files.readAllBytes(Paths.get(path));
    // String contents = new String(encoded);
    // System.out.println(contents);
    CyTransformerReaderImpl reader = new CyTransformerReaderImpl();
    reader.registerTransformerManager(transformerManager, null);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(encoded);
    NamedTransformer<?, ?>[] transformers = reader.read(inputStream);
    Assert.assertNotNull(transformers);
    Assert.assertEquals(1, transformers.length);
    NamedTransformer<?, ?> namedTransformer = transformers[0];
    Assert.assertNotNull(namedTransformer);
    Assert.assertEquals("Default filter", namedTransformer.getName());
    List children = namedTransformer.getTransformers();
    Assert.assertEquals(1, children.size());
    Transformer child = (Transformer) children.get(0);
    Assert.assertNotNull(child);
    Assert.assertTrue(child instanceof CompositeFilter);
    CompositeFilter composite = (CompositeFilter) child;
    Assert.assertEquals(2, composite.getLength());
    Assert.assertTrue(composite.get(0) instanceof TopologyFilter);
    Assert.assertTrue(composite.get(1) instanceof ColumnFilter);
    TopologyFilter topology = (TopologyFilter) composite.get(0);
    Assert.assertEquals(0, topology.getLength());
    Assert.assertEquals(Integer.valueOf(4), topology.getDistance());
    Assert.assertEquals(Integer.valueOf(5), topology.getThreshold());
    ColumnFilter column = (ColumnFilter) composite.get(1);
    Assert.assertEquals("name", column.getColumnName());
}
Also used : CyTransformerReaderImpl(org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl) CompositeFilter(org.cytoscape.filter.model.CompositeFilter) Transformer(org.cytoscape.filter.model.Transformer) AdjacencyTransformer(org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformer) NamedTransformer(org.cytoscape.filter.model.NamedTransformer) AbstractTransformer(org.cytoscape.filter.model.AbstractTransformer) CyNetwork(org.cytoscape.model.CyNetwork) TopologyFilterFactory(org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) NamedTransformer(org.cytoscape.filter.model.NamedTransformer) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl) ColumnFilterFactory(org.cytoscape.filter.internal.filters.column.ColumnFilterFactory) CyIdentifiable(org.cytoscape.model.CyIdentifiable) TopologyFilter(org.cytoscape.filter.internal.filters.topology.TopologyFilter) Test(org.junit.Test)

Aggregations

ColumnFilter (org.cytoscape.filter.internal.filters.column.ColumnFilter)4 TopologyFilter (org.cytoscape.filter.internal.filters.topology.TopologyFilter)4 CyNetwork (org.cytoscape.model.CyNetwork)4 Test (org.junit.Test)4 CyIdentifiable (org.cytoscape.model.CyIdentifiable)2 CyNode (org.cytoscape.model.CyNode)2 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 List (java.util.List)1 ColumnFilterFactory (org.cytoscape.filter.internal.filters.column.ColumnFilterFactory)1 TopologyFilterFactory (org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory)1 AdjacencyTransformer (org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformer)1 TransformerManagerImpl (org.cytoscape.filter.internal.work.TransformerManagerImpl)1 AbstractTransformer (org.cytoscape.filter.model.AbstractTransformer)1 CompositeFilter (org.cytoscape.filter.model.CompositeFilter)1 NamedTransformer (org.cytoscape.filter.model.NamedTransformer)1 Transformer (org.cytoscape.filter.model.Transformer)1 CyTransformerReaderImpl (org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl)1 TaskMonitor (org.cytoscape.work.TaskMonitor)1