Search in sources :

Example 1 with TransformerManagerImpl

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

the class CreateFilterTaskTest method initMocks.

@Before
public void initMocks() {
    MockitoAnnotations.initMocks(this);
    transformerContainer = new TestTransformerContainer();
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    transformerManager.registerFilterFactory(new ColumnFilterFactory(), Collections.emptyMap());
    transformerManager.registerFilterFactory(new DegreeFilterFactory(), Collections.emptyMap());
    transformerManager.registerFilterFactory(new TopologyFilterFactory(), Collections.emptyMap());
    transformerManager.registerFilterFactory(new CompositeFilterFactory<>(CyNetwork.class, CyIdentifiable.class), Collections.emptyMap());
    CyTransformerReaderImpl transformerReader = new CyTransformerReaderImpl();
    transformerReader.registerTransformerManager(transformerManager, Collections.emptyMap());
    when(serviceRegistrar.getService(CyTransformerReader.class)).thenReturn(transformerReader);
    when(serviceRegistrar.getService(TransformerContainer.class, "(container.type=filter)")).thenReturn(transformerContainer);
}
Also used : CyTransformerReaderImpl(org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl) TopologyFilterFactory(org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory) CyNetwork(org.cytoscape.model.CyNetwork) DegreeFilterFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterFactory) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl) ColumnFilterFactory(org.cytoscape.filter.internal.filters.column.ColumnFilterFactory) CyIdentifiable(org.cytoscape.model.CyIdentifiable) Before(org.junit.Before)

Example 2 with TransformerManagerImpl

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

the class PerformanceScaffold method main.

public static void main(String[] args) {
    NetworkTestSupport testSupport = new NetworkTestSupport();
    CyNetwork network = testSupport.getNetwork();
    CyTable nodeTable = network.getDefaultNodeTable();
    nodeTable.createColumn(STRING_COLUMN, String.class, false);
    nodeTable.createColumn(INTEGER_COLUMN, Integer.class, false);
    nodeTable.createListColumn(LIST_STRING_COLUMN, String.class, false);
    // Use a fixed set of string attributes.
    // Worst case performance for trie expected for first entry
    // Best case performance expected for last entry
    Random random = new Random(1);
    String[] values = { "AAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAB", "AAAAAAAAAAAAACA", "AAAAAAAAAAAADAA", "AAAAAAAAAAAEAAA", "AAAAAAAAAAFAAAA", "AAAAAAAAAGAAAAA", "AAAAAAAAHAAAAAA", "AAAAAAAIAAAAAAA", "AAAAAAJAAAAAAAA", "AAAAAKAAAAAAAAA", "AAAALAAAAAAAAAA", "AAAMAAAAAAAAAAA", "AANAAAAAAAAAAAA", "AOAAAAAAAAAAAAA", "PAAAAAAAAAAAAAA" };
    int totalNodes = TOTAL_NODES;
    int totalEdges = totalNodes * AVERAGE_EDGES_PER_NODE;
    long start;
    start = System.currentTimeMillis();
    List<CyNode> nodes = new ArrayList<CyNode>();
    for (int i = 0; i < totalNodes; i++) {
        CyNode node = network.addNode();
        int valueIndex = random.nextInt(values.length);
        network.getRow(node).set(STRING_COLUMN, values[valueIndex]);
        network.getRow(node).set(INTEGER_COLUMN, valueIndex);
        network.getRow(node).set(LIST_STRING_COLUMN, Collections.singletonList(values[valueIndex]));
        nodes.add(node);
    }
    // Construct random graph
    for (int i = 0; i < totalEdges; i++) {
        CyNode source = nodes.get(random.nextInt(totalNodes));
        CyNode target = nodes.get(random.nextInt(totalNodes));
        network.addEdge(source, target, true);
    }
    System.out.printf("Construct\t%d\n", System.currentTimeMillis() - start);
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    Map<String, String> properties = Collections.emptyMap();
    transformerManager.registerTransformerSource(new CyNetworkSource(), properties);
    List<UseCase> useCases = new ArrayList<UseCase>();
    QuickFind quickFind = new QuickFindImpl();
    useCases.add(new NumberAttributeUseCase(quickFind, 0, transformerManager));
    useCases.add(new StringAttributeUseCase(quickFind, values[values.length - 1], transformerManager));
    useCases.add(new DegreeUseCase(3, transformerManager));
    for (UseCase useCase : useCases) {
        useCase.execute(network, ITERATIONS);
    }
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) QuickFindImpl(org.cytoscape.filter.internal.quickfind.util.QuickFindImpl) CyTable(org.cytoscape.model.CyTable) Random(java.util.Random) QuickFind(org.cytoscape.filter.internal.quickfind.util.QuickFind) CyNode(org.cytoscape.model.CyNode) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl)

Example 3 with TransformerManagerImpl

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

the class FilterIOTest method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() throws Exception {
    DegreeFilter degreeFilter = new DegreeFilter();
    degreeFilter.setCriterion(new Double[] { 0.2, 5.5 });
    degreeFilter.setEdgeType(CyEdge.Type.ANY);
    DummyFilter dummyFilter = new DummyFilter();
    CyTransformerWriter writer = new CyTransformerWriterImpl();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    writer.write(stream, FilterIO.createNamedTransformer("filter1", degreeFilter), FilterIO.createNamedTransformer("filter2", dummyFilter));
    String serialized = stream.toString("utf-8");
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    Map<String, String> properties = Collections.emptyMap();
    transformerManager.registerFilterFactory(new DegreeFilterFactory(), properties);
    transformerManager.registerFilterFactory(new DummyFilterFactory(), properties);
    CyTransformerReaderImpl reader = new CyTransformerReaderImpl();
    reader.registerTransformerManager(transformerManager, null);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(stream.toByteArray());
    NamedTransformer<?, ?>[] transformers = reader.read(inputStream);
    ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
    writer.write(stream2, transformers);
    String serialized2 = stream2.toString("utf-8");
    Assert.assertEquals(serialized, serialized2);
}
Also used : CyTransformerReaderImpl(org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl) CyTransformerWriter(org.cytoscape.io.write.CyTransformerWriter) CyTransformerWriterImpl(org.cytoscape.io.internal.write.transformer.CyTransformerWriterImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl) Test(org.junit.Test)

Example 4 with TransformerManagerImpl

use of org.cytoscape.filter.internal.work.TransformerManagerImpl 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());
}
Also used : CyTransformerReaderImpl(org.cytoscape.io.internal.read.transformer.CyTransformerReaderImpl) 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) CyTransformerWriter(org.cytoscape.io.write.CyTransformerWriter) CyTransformerWriterImpl(org.cytoscape.io.internal.write.transformer.CyTransformerWriterImpl) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NamedTransformer(org.cytoscape.filter.model.NamedTransformer) AdjacencyTransformerFactory(org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformerFactory) 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) ColumnFilterFactory(org.cytoscape.filter.internal.filters.column.ColumnFilterFactory) AdjacencyTransformer(org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformer) Test(org.junit.Test)

Example 5 with TransformerManagerImpl

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

the class CyActivator method start.

@Override
public void start(BundleContext bc) {
    final CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    registerService(bc, transformerManager, TransformerManager.class, new Properties());
    registerServiceListener(bc, transformerManager::registerTransformerSource, transformerManager::unregisterTransformerSource, TransformerSource.class);
    registerServiceListener(bc, transformerManager::registerFilterFactory, transformerManager::unregisterFilterFactory, FilterFactory.class);
    registerServiceListener(bc, transformerManager::registerElementTransformerFactory, transformerManager::unregisterElementTransformerFactory, ElementTransformerFactory.class);
    registerServiceListener(bc, transformerManager::registerHolisticTransformerFactory, transformerManager::unregisterHolisticTransformerFactory, HolisticTransformerFactory.class);
    TransformerViewManager transformerViewManager = new TransformerViewManager(transformerManager);
    registerServiceListener(bc, transformerViewManager::registerTransformerViewFactory, transformerViewManager::unregisterTransformerViewFactory, TransformerViewFactory.class);
    registerService(bc, new CyNetworkSource(), TransformerSource.class, new Properties());
    // Filters
    registerService(bc, new DegreeFilterFactory(), FilterFactory.class, new Properties());
    registerService(bc, new ColumnFilterFactory(), FilterFactory.class, new Properties());
    registerService(bc, new TopologyFilterFactory(), FilterFactory.class, new Properties());
    registerService(bc, new CompositeFilterFactory<CyNetwork, CyIdentifiable>(CyNetwork.class, CyIdentifiable.class), FilterFactory.class, new Properties());
    // Transformers
    registerService(bc, new InteractionTransformerFactory(), ElementTransformerFactory.class, new Properties());
    registerService(bc, new AdjacencyTransformerFactory(), ElementTransformerFactory.class, new Properties());
    ModelMonitor modelMonitor = new ModelMonitor();
    registerAllServices(bc, modelMonitor, new Properties());
    ValidationManager validationManager = new ValidationManager();
    registerAllServices(bc, validationManager, new Properties());
    FilterPanelStyle style = new FlatStyle();
    registerService(bc, new DegreeFilterViewFactory(style, modelMonitor), TransformerViewFactory.class, new Properties());
    registerService(bc, new ColumnFilterViewFactory(style, modelMonitor, serviceRegistrar), TransformerViewFactory.class, new Properties());
    registerService(bc, new TopologyFilterViewFactory(style), TransformerViewFactory.class, TopologyFilterViewFactory.getServiceProperties());
    registerService(bc, new InteractionTransformerViewFactory(style), TransformerViewFactory.class, new Properties());
    registerService(bc, new AdjacencyTransformerViewFactory(style, serviceRegistrar), TransformerViewFactory.class, AdjacencyTransformerViewFactory.getServiceProperties());
    LazyWorkQueue queue = new LazyWorkQueue();
    FilterIO filterIo = new FilterIO(serviceRegistrar);
    FilterWorker filterWorker = new FilterWorker(queue, serviceRegistrar);
    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);
    CytoPanelComponent selectPanel = new FilterCytoPanelComponent(transformerViewManager, modelMonitor, filterPanel, transformerPanel);
    registerService(bc, selectPanel, CytoPanelComponent.class, new Properties());
    FilterSettingsManager settingsManager = new FilterSettingsManager(filterPanel, transformerPanel, filterIo);
    registerService(bc, settingsManager, SessionAboutToBeSavedListener.class, new Properties());
    registerService(bc, settingsManager, SessionAboutToBeLoadedListener.class, new Properties());
    registerService(bc, settingsManager, SessionLoadedListener.class, new Properties());
    // new TransformerPanelManager API
    {
        Properties props = new Properties();
        props.setProperty("service.type", "manager");
        props.setProperty("container.type", "filter");
        registerService(bc, filterPanel, TransformerContainer.class, props);
    }
    {
        Properties props = new Properties();
        props.setProperty("service.type", "manager");
        props.setProperty("container.type", "chain");
        registerService(bc, transformerPanel, TransformerContainer.class, props);
    }
    // commands
    {
        Properties props = new Properties();
        props.setProperty(COMMAND, "import");
        props.setProperty(COMMAND_NAMESPACE, "filter");
        props.setProperty(COMMAND_DESCRIPTION, "Import filter JSON from a file.");
        props.setProperty(COMMAND_LONG_DESCRIPTION, "Import filter JSON from a file.");
        registerService(bc, new ImportNamedTransformersTaskFactory(filterIo, filterPanel), TaskFactory.class, props);
    }
    {
        Properties props = new Properties();
        props.setProperty(COMMAND, "export");
        props.setProperty(COMMAND_NAMESPACE, "filter");
        props.setProperty(COMMAND_DESCRIPTION, "Export filter JSON to a file.");
        props.setProperty(COMMAND_LONG_DESCRIPTION, "Export filter JSON to a file.");
        registerService(bc, new ExportNamedTransformersTaskFactory(filterIo, filterPanelController), TaskFactory.class, props);
    }
}
Also used : TransformerViewManager(org.cytoscape.filter.internal.view.TransformerViewManager) InteractionTransformerFactory(org.cytoscape.filter.internal.transformers.interaction.InteractionTransformerFactory) CyNetwork(org.cytoscape.model.CyNetwork) ServiceProperties(org.cytoscape.work.ServiceProperties) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) FilterPanel(org.cytoscape.filter.internal.view.FilterPanel) FilterPanelStyle(org.cytoscape.filter.internal.view.look.FilterPanelStyle) ExportNamedTransformersTaskFactory(org.cytoscape.filter.internal.tasks.ExportNamedTransformersTaskFactory) AdjacencyTransformerFactory(org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformerFactory) LazyWorkQueue(org.cytoscape.filter.internal.work.LazyWorkQueue) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl) ColumnFilterFactory(org.cytoscape.filter.internal.filters.column.ColumnFilterFactory) CyIdentifiable(org.cytoscape.model.CyIdentifiable) ValidationManager(org.cytoscape.filter.internal.work.ValidationManager) AdjacencyTransformerViewFactory(org.cytoscape.filter.internal.transformers.adjacency.AdjacencyTransformerViewFactory) ColumnFilterViewFactory(org.cytoscape.filter.internal.filters.column.ColumnFilterViewFactory) ImportNamedTransformersTaskFactory(org.cytoscape.filter.internal.tasks.ImportNamedTransformersTaskFactory) TopologyFilterFactory(org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory) InteractionTransformerViewFactory(org.cytoscape.filter.internal.transformers.interaction.InteractionTransformerViewFactory) DegreeFilterFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterFactory) TopologyFilterViewFactory(org.cytoscape.filter.internal.filters.topology.TopologyFilterViewFactory) TransformerPanelController(org.cytoscape.filter.internal.view.TransformerPanelController) TransformerContainer(org.cytoscape.filter.TransformerContainer) TransformerPanel(org.cytoscape.filter.internal.view.TransformerPanel) FlatStyle(org.cytoscape.filter.internal.view.look.FlatStyle) FilterWorker(org.cytoscape.filter.internal.work.FilterWorker) DegreeFilterViewFactory(org.cytoscape.filter.internal.filters.degree.DegreeFilterViewFactory) TaskFactory(org.cytoscape.work.TaskFactory) ExportNamedTransformersTaskFactory(org.cytoscape.filter.internal.tasks.ExportNamedTransformersTaskFactory) ImportNamedTransformersTaskFactory(org.cytoscape.filter.internal.tasks.ImportNamedTransformersTaskFactory) FilterPanelController(org.cytoscape.filter.internal.view.FilterPanelController) TransformerWorker(org.cytoscape.filter.internal.work.TransformerWorker) CytoPanelComponent(org.cytoscape.application.swing.CytoPanelComponent)

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