Search in sources :

Example 16 with ColumnFilter

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

the class CompositeFilterTest method testCompositeFilterAlwaysFalse.

@Test
public void testCompositeFilterAlwaysFalse() {
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<>(CyNetwork.class, CyIdentifiable.class);
    ColumnFilter filterForA = new ColumnFilter();
    ColumnFilter filterForB = new ColumnFilter();
    ColumnFilter filterForC = new ColumnFilter();
    composite.append(filterForA);
    composite.append(filterForB);
    composite.append(filterForC);
    assertTrue(filterForA.isAlwaysFalse());
    assertTrue(filterForB.isAlwaysFalse());
    assertTrue(filterForC.isAlwaysFalse());
    composite.setType(Type.ALL);
    assertTrue(composite.isAlwaysFalse());
    composite.setType(Type.ANY);
    assertTrue(composite.isAlwaysFalse());
    filterForA.setColumnName("s");
    filterForA.setPredicateAndCriterion(Predicate.CONTAINS, "a");
    assertFalse(filterForA.isAlwaysFalse());
    composite.setType(Type.ALL);
    assertTrue(composite.isAlwaysFalse());
    composite.setType(Type.ANY);
    assertFalse(composite.isAlwaysFalse());
    filterForB.setColumnName("s");
    filterForB.setPredicateAndCriterion(Predicate.CONTAINS, "a");
    filterForC.setColumnName("s");
    filterForC.setPredicateAndCriterion(Predicate.CONTAINS, "a");
    composite.setType(Type.ALL);
    assertFalse(composite.isAlwaysFalse());
    composite.setType(Type.ANY);
    assertFalse(composite.isAlwaysFalse());
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) 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)

Example 17 with ColumnFilter

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