Search in sources :

Example 1 with FilterElement

use of org.cytoscape.filter.internal.view.FilterElement in project cytoscape-impl by cytoscape.

the class TransformerWorker method doWork.

@Override
public void doWork(ProgressMonitor monitor) {
    if (controller == null) {
        return;
    }
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    CyNetworkView networkView = applicationManager.getCurrentNetworkView();
    CyNetwork network;
    if (networkView != null) {
        network = networkView.getModel();
    } else {
        network = applicationManager.getCurrentNetwork();
    }
    if (network == null) {
        return;
    }
    ProgressMonitor filterMonitor = new SubProgressMonitor(monitor, 0.0, 0.4);
    ProgressMonitor chainMonitor = new SubProgressMonitor(monitor, 0.4, 0.98);
    monitor.setProgress(0.0);
    monitor.setStatusMessage(null);
    Sink sink = new Sink(network);
    long startTime = System.currentTimeMillis();
    try {
        List<Transformer<CyNetwork, CyIdentifiable>> transformers = controller.getTransformers(view);
        FilterElement selected = (FilterElement) controller.getStartWithComboBoxModel().getSelectedItem();
        TransformerSource<CyNetwork, CyIdentifiable> source = createSource(network, selected, filterMonitor);
        for (Transformer<?, ?> transformer : transformers) {
            if (transformer instanceof MemoizableTransformer) {
                ((MemoizableTransformer) transformer).startCaching();
            }
        }
        try {
            transformerManager.execute(network, source, transformers, sink, chainMonitor);
        } finally {
            for (Transformer<?, ?> transformer : transformers) {
                if (transformer instanceof MemoizableTransformer) {
                    ((MemoizableTransformer) transformer).clearCache();
                }
            }
        }
        if (networkView != null) {
            networkView.updateView();
        }
    } finally {
        long duration = System.currentTimeMillis() - startTime;
        monitor.setProgress(1.0);
        monitor.setStatusMessage(String.format("Selected %d %s and %d %s in %dms", sink.nodeCount, sink.nodeCount == 1 ? "node" : "nodes", sink.edgeCount, sink.edgeCount == 1 ? "edge" : "edges", duration));
    }
}
Also used : Transformer(org.cytoscape.filter.model.Transformer) MemoizableTransformer(org.cytoscape.filter.internal.MemoizableTransformer) CyNetwork(org.cytoscape.model.CyNetwork) MemoizableTransformer(org.cytoscape.filter.internal.MemoizableTransformer) CyApplicationManager(org.cytoscape.application.CyApplicationManager) FilterElement(org.cytoscape.filter.internal.view.FilterElement) TransformerSink(org.cytoscape.filter.model.TransformerSink) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Aggregations

CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 MemoizableTransformer (org.cytoscape.filter.internal.MemoizableTransformer)1 FilterElement (org.cytoscape.filter.internal.view.FilterElement)1 Transformer (org.cytoscape.filter.model.Transformer)1 TransformerSink (org.cytoscape.filter.model.TransformerSink)1 CyIdentifiable (org.cytoscape.model.CyIdentifiable)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1