Search in sources :

Example 6 with TransformerManagerImpl

use of org.cytoscape.filter.internal.work.TransformerManagerImpl in project cytoscape-impl by cytoscape.

the class UiScaffold method start.

void start() {
    MockitoAnnotations.initMocks(this);
    Random random = new Random(0);
    NetworkTestSupport networkTestSupport = new NetworkTestSupport();
    CyNetwork network = networkTestSupport.getNetwork();
    CyTable nodeTable = network.getDefaultNodeTable();
    nodeTable.createColumn("Score", Double.class, false);
    nodeTable.createColumn("IsSpecial", Boolean.class, false);
    for (int i = 0; i < TOTAL_NODES; i++) {
        CyNode node = network.addNode();
        network.getRow(node).set("Score", random.nextGaussian());
        network.getRow(node).set("IsSpecial", i % 2 == 0);
    }
    List<CyNode> nodes = network.getNodeList();
    for (int i = 0; i < TOTAL_EDGES; i++) {
        CyNode source = nodes.get(random.nextInt(nodes.size()));
        CyNode target = nodes.get(random.nextInt(nodes.size()));
        network.addEdge(source, target, false);
    }
    when(applicationManager.getCurrentNetworkView()).thenReturn(networkView);
    when(applicationManager.getCurrentNetwork()).thenReturn(network);
    when(networkView.getModel()).thenReturn(network);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
    when(serviceRegistrar.getService(TaskManager.class)).thenReturn(taskManager);
    when(serviceRegistrar.getService(IconManager.class)).thenReturn(iconManager);
    JFrame frame = new JFrame();
    frame.setTitle("Select");
    Map<String, String> properties = Collections.emptyMap();
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    transformerManager.registerFilterFactory(new ColumnFilterFactory(), properties);
    transformerManager.registerFilterFactory(new DegreeFilterFactory(), properties);
    transformerManager.registerFilterFactory(new TopologyFilterFactory(), properties);
    transformerManager.registerElementTransformerFactory(new InteractionTransformerFactory(), properties);
    ModelMonitor modelMonitor = new ModelMonitor();
    modelMonitor.handleEvent(new SetCurrentNetworkEvent(applicationManager, network));
    ValidationManager validationManager = new ValidationManager();
    FilterPanelStyle style = new StandardStyle();
    TransformerViewManager transformerViewManager = new TransformerViewManager(transformerManager);
    // transformerViewManager.registerTransformerViewFactory(new ColumnFilterViewFactory(style, modelMonitor), properties);
    transformerViewManager.registerTransformerViewFactory(new DegreeFilterViewFactory(style, modelMonitor), properties);
    transformerViewManager.registerTransformerViewFactory(new TopologyFilterViewFactory(style), properties);
    transformerViewManager.registerTransformerViewFactory(new InteractionTransformerViewFactory(style), properties);
    LazyWorkQueue queue = new LazyWorkQueue();
    FilterWorker filterWorker = new FilterWorker(queue, serviceRegistrar);
    FilterIO filterIo = null;
    FilterPanelController filterPanelController = new FilterPanelController(transformerManager, transformerViewManager, validationManager, filterWorker, modelMonitor, filterIo, style, serviceRegistrar);
    FilterPanel filterPanel = new FilterPanel(filterPanelController, filterWorker, serviceRegistrar);
    TransformerWorker transformerWorker = new TransformerWorker(queue, transformerManager, serviceRegistrar);
    TransformerPanelController transformerPanelController = new TransformerPanelController(transformerManager, transformerViewManager, validationManager, filterPanelController, transformerWorker, filterIo, style, serviceRegistrar);
    TransformerPanel transformerPanel = new TransformerPanel(transformerPanelController, transformerWorker, serviceRegistrar);
    SelectPanel selectPanel = new SelectPanel(filterPanel, transformerPanel);
    JRootPane root = frame.getRootPane();
    root.setLayout(new GridBagLayout());
    root.add(selectPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    frame.setSize(450, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
Also used : TransformerViewManager(org.cytoscape.filter.internal.view.TransformerViewManager) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) InteractionTransformerFactory(org.cytoscape.filter.internal.transformers.interaction.InteractionTransformerFactory) CyNetwork(org.cytoscape.model.CyNetwork) FilterPanel(org.cytoscape.filter.internal.view.FilterPanel) FilterPanelStyle(org.cytoscape.filter.internal.view.look.FilterPanelStyle) CyTable(org.cytoscape.model.CyTable) Random(java.util.Random) JFrame(javax.swing.JFrame) CyNode(org.cytoscape.model.CyNode) LazyWorkQueue(org.cytoscape.filter.internal.work.LazyWorkQueue) SetCurrentNetworkEvent(org.cytoscape.application.events.SetCurrentNetworkEvent) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl) ColumnFilterFactory(org.cytoscape.filter.internal.filters.column.ColumnFilterFactory) ValidationManager(org.cytoscape.filter.internal.work.ValidationManager) StandardStyle(org.cytoscape.filter.internal.view.look.StandardStyle) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) TopologyFilterFactory(org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory) InteractionTransformerViewFactory(org.cytoscape.filter.internal.transformers.interaction.InteractionTransformerViewFactory) DegreeFilterFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterFactory) SelectPanel(org.cytoscape.filter.internal.view.SelectPanel) TopologyFilterViewFactory(org.cytoscape.filter.internal.filters.topology.TopologyFilterViewFactory) TransformerPanelController(org.cytoscape.filter.internal.view.TransformerPanelController) TransformerPanel(org.cytoscape.filter.internal.view.TransformerPanel) FilterWorker(org.cytoscape.filter.internal.work.FilterWorker) DegreeFilterViewFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterViewFactory) FilterPanelController(org.cytoscape.filter.internal.view.FilterPanelController) JRootPane(javax.swing.JRootPane) TransformerWorker(org.cytoscape.filter.internal.work.TransformerWorker)

Example 7 with TransformerManagerImpl

use of org.cytoscape.filter.internal.work.TransformerManagerImpl 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)

Example 8 with TransformerManagerImpl

use of org.cytoscape.filter.internal.work.TransformerManagerImpl in project cytoscape-impl by cytoscape.

the class FilterIOTest method testNestedFilterRoundTrip.

@SuppressWarnings("rawtypes")
@Test
public void testNestedFilterRoundTrip() throws Exception {
    DegreeFilter degreeFilter = new DegreeFilter();
    degreeFilter.setCriterion(new Double[] { 0.2, 5.5 });
    degreeFilter.setEdgeType(CyEdge.Type.ANY);
    CompositeFilter<CyNetwork, CyIdentifiable> composite = new CompositeFilterImpl<CyNetwork, CyIdentifiable>(CyNetwork.class, CyIdentifiable.class);
    composite.setType(Type.ANY);
    composite.append(degreeFilter);
    CyTransformerWriter writer = new CyTransformerWriterImpl();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    writer.write(stream, FilterIO.createNamedTransformer("filter1", composite));
    String serialized = stream.toString("utf-8");
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    Map<String, String> properties = Collections.emptyMap();
    transformerManager.registerFilterFactory(new DegreeFilterFactory(), properties);
    transformerManager.registerFilterFactory(new CompositeFilterFactory<CyNetwork, CyIdentifiable>(CyNetwork.class, CyIdentifiable.class), 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("filter1", 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 composite2 = (CompositeFilter) child;
    Assert.assertEquals(composite.getType(), composite2.getType());
    Assert.assertEquals(composite.getLength(), composite2.getLength());
    Filter filter = composite2.get(0);
    Assert.assertTrue(filter instanceof DegreeFilter);
    DegreeFilter degreeFilter2 = (DegreeFilter) filter;
    Assert.assertArrayEquals((Number[]) degreeFilter.getCriterion(), (Number[]) degreeFilter2.getCriterion());
    Assert.assertEquals(degreeFilter.getEdgeType(), degreeFilter2.getEdgeType());
}
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) CyTransformerWriter(org.cytoscape.io.write.CyTransformerWriter) CyTransformerWriterImpl(org.cytoscape.io.internal.write.transformer.CyTransformerWriterImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CompositeFilterImpl(org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl) DegreeFilterFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterFactory) DegreeFilter(org.cytoscape.filter.internal.filters.degree.DegreeFilter) NamedTransformer(org.cytoscape.filter.model.NamedTransformer) 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) CyIdentifiable(org.cytoscape.model.CyIdentifiable) Test(org.junit.Test)

Aggregations

TransformerManagerImpl (org.cytoscape.filter.internal.work.TransformerManagerImpl)8 CyNetwork (org.cytoscape.model.CyNetwork)6 ColumnFilterFactory (org.cytoscape.filter.internal.filters.column.ColumnFilterFactory)5 DegreeFilterFactory (org.cytoscape.filter.internal.filters.degree.DegreeFilterFactory)5 CyTransformerReaderImpl (org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 TopologyFilterFactory (org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory)4 NamedTransformer (org.cytoscape.filter.model.NamedTransformer)4 CyIdentifiable (org.cytoscape.model.CyIdentifiable)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 List (java.util.List)3 ColumnFilter (org.cytoscape.filter.internal.filters.column.ColumnFilter)3 TopologyFilter (org.cytoscape.filter.internal.filters.topology.TopologyFilter)3 AdjacencyTransformer (org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformer)3 AbstractTransformer (org.cytoscape.filter.model.AbstractTransformer)3 CompositeFilter (org.cytoscape.filter.model.CompositeFilter)3 Transformer (org.cytoscape.filter.model.Transformer)3 Random (java.util.Random)2 DegreeFilter (org.cytoscape.filter.internal.filters.degree.DegreeFilter)2