Search in sources :

Example 11 with ColumnFilter

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

the class CreateFilterTaskTest method testCreateColumnFilterNumber.

@Test
public void testCreateColumnFilterNumber() {
    CreateFilterTask task = new CreateFilterTask(serviceRegistrar, "MyFilter");
    task.jsonTunable.json = "{ \"id\" : \"ColumnFilter\", \"parameters\" : { \"predicate\" : \"BETWEEN\", \"criterion\" : [1,1], \"columnName\" : \"name\"} }";
    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);
    ColumnFilter columnFilter = (ColumnFilter) transformer.getTransformers().get(0);
    assertEquals(Predicate.BETWEEN, columnFilter.getPredicate());
    assertArrayEquals(new Number[] { 1l, 1l }, (Number[]) 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) Test(org.junit.Test)

Example 12 with ColumnFilter

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

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

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

the class ColumnFilterTest method testColumnFilterAlwaysFalse.

@Test
public void testColumnFilterAlwaysFalse() {
    ColumnFilter columnFilter = new ColumnFilter();
    assertTrue(columnFilter.isAlwaysFalse());
    columnFilter.setPredicateAndCriterion(Predicate.IS, "a");
    assertTrue(columnFilter.isAlwaysFalse());
    columnFilter.setColumnName("c");
    assertFalse(columnFilter.isAlwaysFalse());
}
Also used : ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) Test(org.junit.Test)

Example 15 with ColumnFilter

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

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