Search in sources :

Example 1 with ColumnFilter

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

the class CreateFilterTaskTest method testCreateColumnFilterBoolean.

@Test
public void testCreateColumnFilterBoolean() {
    CreateFilterTask task = new CreateFilterTask(serviceRegistrar, "MyFilter");
    task.jsonTunable.json = "{ \"id\" : \"ColumnFilter\", \"parameters\" : { \"criterion\" : false, \"columnName\" : \"name\", \"predicate\" : \"IS\"} }";
    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.IS, columnFilter.getPredicate());
    assertEquals(false, 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 2 with ColumnFilter

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

the class CreateFilterTaskTest method testCreateColumnFilterString.

@Test
public void testCreateColumnFilterString() {
    CreateFilterTask task = new CreateFilterTask(serviceRegistrar, "MyFilter");
    task.jsonTunable.json = "{ \"id\" : \"ColumnFilter\", \"parameters\" : { \"criterion\" : \"1\", \"columnName\" : \"name\", \"predicate\" : \"CONTAINS\"} }";
    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.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) Test(org.junit.Test)

Example 3 with ColumnFilter

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

the class CreateFilterTaskTest method testCreateCompositeFilter.

@Test
public void testCreateCompositeFilter() {
    CreateFilterTask task = new CreateFilterTask(serviceRegistrar, "MyFilter");
    String subFilterJson = "{ \"id\" : \"ColumnFilter\", \"parameters\" : { \"criterion\" : \"1\", \"columnName\" : \"name\", \"predicate\" : \"CONTAINS\"} }";
    task.jsonTunable.json = "{ \"id\" : \"org.cytoscape.CompositeFilter\", \"parameters\" : { \"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);
    @SuppressWarnings("rawtypes") CompositeFilter compositeFilter = (CompositeFilter) transformer.getTransformers().get(0);
    assertEquals(CompositeFilter.Type.ALL, compositeFilter.getType());
    assertEquals(1, compositeFilter.getLength());
    ColumnFilter columnFilter = (ColumnFilter) compositeFilter.get(0);
    assertEquals(Predicate.CONTAINS, columnFilter.getPredicate());
    assertEquals("1", columnFilter.getCriterion());
    assertEquals("name", columnFilter.getColumnName());
}
Also used : CompositeFilter(org.cytoscape.filter.model.CompositeFilter) 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 4 with ColumnFilter

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

the class ModelMonitor method updateColumnSliders.

private void updateColumnSliders() {
    for (ColumnFilterController controller : columnViews.values()) {
        ColumnFilter filter = controller.getFilter();
        Class<? extends CyIdentifiable> columnType = filter.getTableType();
        Number[] range;
        String name = filter.getColumnName();
        if (name == null) {
            continue;
        }
        CyTable table;
        if (CyNode.class.equals(columnType)) {
            table = network.getDefaultNodeTable();
            range = getColumnRange(table, name, nodeColumnRanges);
        } else if (CyEdge.class.equals(columnType)) {
            table = network.getDefaultEdgeTable();
            range = getColumnRange(table, name, edgeColumnRanges);
        } else {
            continue;
        }
        CyColumn column = table.getColumn(name);
        if (column == null) {
            continue;
        }
        Class<?> type = column.getType();
        if (List.class.equals(type)) {
            type = column.getListElementType();
        }
        if (Integer.class.equals(type) || Long.class.equals(type)) {
            controller.setSliderBounds(range[0].longValue(), range[1].longValue());
        } else {
            controller.setSliderBounds(range[0].doubleValue(), range[1].doubleValue());
        }
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) ColumnFilterController(org.cytoscape.filter.internal.filters.column.ColumnFilterController) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) CyEdge(org.cytoscape.model.CyEdge)

Example 5 with ColumnFilter

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

the class CompositeFilterTest method testCompositeFilterString.

@Test
public void testCompositeFilterString() {
    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", "abc");
    network.getRow(n2).set("s", "def");
    network.getRow(n3).set("s", "aa");
    ColumnFilter filterForA = new ColumnFilter("s", Predicate.CONTAINS, "a");
    ColumnFilter filterForB = new ColumnFilter("s", Predicate.CONTAINS, "b");
    ColumnFilter filterForC = new ColumnFilter("s", Predicate.CONTAINS, "c");
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
    composite.append(filterForA);
    composite.append(filterForB);
    composite.append(filterForC);
    composite.setType(Type.ANY);
    assertTrue(composite.accepts(network, n1));
    assertFalse(composite.accepts(network, n2));
    assertTrue(composite.accepts(network, n3));
    assertFalse(composite.accepts(network, n4));
    composite.setType(Type.ALL);
    assertTrue(composite.accepts(network, n1));
    assertFalse(composite.accepts(network, n2));
    assertFalse(composite.accepts(network, n3));
    assertFalse(composite.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) CompositeFilterImpl(org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl) CyIdentifiable(org.cytoscape.model.CyIdentifiable) 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