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