Search in sources :

Example 6 with ColumnFilter

use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.

the class ColumnFilterTest method testColumnFilterList.

@Test
public void testColumnFilterList() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createListColumn("l", String.class, false);
    CyNode n1 = network.addNode();
    CyNode n2 = network.addNode();
    CyNode n3 = network.addNode();
    network.getRow(n1).set("l", Arrays.asList("a", "b", "c"));
    network.getRow(n2).set("l", Arrays.asList("c", "d"));
    network.getRow(n3).set("l", Arrays.asList("a", "a"));
    ColumnFilter columnFilter = new ColumnFilter("l", Predicate.IS, "a");
    columnFilter.setAnyMatch(true);
    assertTrue(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n3));
    columnFilter.setAnyMatch(false);
    assertFalse(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n3));
}
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 7 with ColumnFilter

use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.

the class ColumnFilterTest method testColumnFilterBoolean.

@Test
public void testColumnFilterBoolean() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createColumn("b", Boolean.class, false);
    CyNode n1 = network.addNode();
    CyNode n2 = network.addNode();
    CyNode n3 = network.addNode();
    network.getRow(n1).set("b", true);
    network.getRow(n2).set("b", false);
    ColumnFilter columnFilter = new ColumnFilter("b", Predicate.IS, true);
    assertTrue(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
    columnFilter.setPredicateAndCriterion(Predicate.IS, false);
    assertFalse(columnFilter.accepts(network, n1));
    assertTrue(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
}
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 8 with ColumnFilter

use of org.cytoscape.filter.internal.filters.column.ColumnFilter 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 9 with ColumnFilter

use of org.cytoscape.filter.internal.filters.column.ColumnFilter in project cytoscape-impl by cytoscape.

the class FilterIOTest method testSubFilterTransformerRoundTrip.

@SuppressWarnings("rawtypes")
@Test
public void testSubFilterTransformerRoundTrip() throws Exception {
    ColumnFilter columnFilter = new ColumnFilter();
    columnFilter.setColumnName("MyColName");
    columnFilter.setPredicateAndCriterion(Predicate.CONTAINS, "blah");
    AdjacencyTransformer adjacency = new AdjacencyTransformer();
    adjacency.setAction(Action.REPLACE);
    adjacency.setEdgesAre(EdgesAre.INCOMING);
    adjacency.setFilterTarget(What.EDGES);
    adjacency.setOutput(What.EDGES);
    adjacency.getCompositeFilter().append(columnFilter);
    CyTransformerWriter writer = new CyTransformerWriterImpl();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    writer.write(stream, FilterIO.createNamedTransformer("transformer1", adjacency));
    // String serialized = stream.toString("utf-8");
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    Map<String, String> properties = Collections.emptyMap();
    transformerManager.registerFilterFactory(new ColumnFilterFactory(), properties);
    transformerManager.registerElementTransformerFactory(new AdjacencyTransformerFactory(), properties);
    CyTransformerReaderImpl reader = new CyTransformerReaderImpl();
    reader.registerTransformerManager(transformerManager, null);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(stream.toByteArray());
    NamedTransformer<?, ?>[] transformers = reader.read(inputStream);
    Assert.assertNotNull(transformers);
    Assert.assertEquals(1, transformers.length);
    NamedTransformer<?, ?> namedTransformer = transformers[0];
    Assert.assertNotNull(namedTransformer);
    Assert.assertEquals("transformer1", namedTransformer.getName());
    List children = namedTransformer.getTransformers();
    Assert.assertEquals(1, children.size());
    Transformer child = (Transformer) children.get(0);
    Assert.assertNotNull(child);
    Assert.assertTrue(child instanceof AdjacencyTransformer);
    AdjacencyTransformer adjacency2 = (AdjacencyTransformer) child;
    Assert.assertEquals(adjacency.getAction(), adjacency2.getAction());
    Assert.assertEquals(adjacency.getEdgesAre(), adjacency2.getEdgesAre());
    Assert.assertEquals(adjacency.getFilterTarget(), adjacency2.getFilterTarget());
    Assert.assertEquals(adjacency.getOutput(), adjacency2.getOutput());
    CompositeFilter<?, ?> composite = adjacency2.getCompositeFilter();
    Assert.assertEquals(1, composite.getLength());
    Filter filter = composite.get(0);
    Assert.assertTrue(filter instanceof ColumnFilter);
    ColumnFilter columnFilter2 = (ColumnFilter) filter;
    Assert.assertEquals(columnFilter.getColumnName(), columnFilter2.getColumnName());
    Assert.assertEquals(columnFilter.getPredicate(), columnFilter2.getPredicate());
    Assert.assertEquals(columnFilter.getCriterion(), columnFilter2.getCriterion());
}
Also used : CyTransformerReaderImpl(org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl) 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) CyTransformerWriter(org.cytoscape.io.write.CyTransformerWriter) CyTransformerWriterImpl(org.cytoscape.io.internal.write.transformer.CyTransformerWriterImpl) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NamedTransformer(org.cytoscape.filter.model.NamedTransformer) AdjacencyTransformerFactory(org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformerFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) TopologyFilter(org.cytoscape.filter.internal.filters.topology.TopologyFilter) DegreeFilter(org.cytoscape.filter.internal.filters.degree.DegreeFilter) Filter(org.cytoscape.filter.model.Filter) CompositeFilter(org.cytoscape.filter.model.CompositeFilter) List(java.util.List) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl) ColumnFilterFactory(org.cytoscape.filter.internal.filters.column.ColumnFilterFactory) AdjacencyTransformer(org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformer) Test(org.junit.Test)

Example 10 with ColumnFilter

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

Aggregations

ColumnFilter (org.cytoscape.filter.internal.filters.column.ColumnFilter)17 Test (org.junit.Test)16 CyNetwork (org.cytoscape.model.CyNetwork)14 CyIdentifiable (org.cytoscape.model.CyIdentifiable)8 CyNode (org.cytoscape.model.CyNode)7 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)7 TopologyFilter (org.cytoscape.filter.internal.filters.topology.TopologyFilter)5 TaskMonitor (org.cytoscape.work.TaskMonitor)5 CompositeFilter (org.cytoscape.filter.model.CompositeFilter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 List (java.util.List)2 ColumnFilterFactory (org.cytoscape.filter.internal.filters.column.ColumnFilterFactory)2 CompositeFilterImpl (org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl)2 AdjacencyTransformer (org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformer)2 TransformerManagerImpl (org.cytoscape.filter.internal.work.TransformerManagerImpl)2 AbstractTransformer (org.cytoscape.filter.model.AbstractTransformer)2 NamedTransformer (org.cytoscape.filter.model.NamedTransformer)2 Transformer (org.cytoscape.filter.model.Transformer)2 CyTransformerReaderImpl (org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1