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