use of org.cytoscape.filter.internal.MemoizableTransformer 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));
}
}
use of org.cytoscape.filter.internal.MemoizableTransformer in project cytoscape-impl by cytoscape.
the class FilterWorker 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;
}
monitor.setProgress(0);
monitor.setStatusMessage(null);
int nodeCount = 0;
int edgeCount = 0;
int counter = 0;
long startTime = System.currentTimeMillis();
try {
Filter<CyNetwork, CyIdentifiable> filter = controller.getFilter();
if (filter instanceof CompositeFilter) {
// If we have an empty CompositeFilter, bail out.
CompositeFilter<CyNetwork, CyIdentifiable> composite = (CompositeFilter<CyNetwork, CyIdentifiable>) filter;
if (composite.getLength() == 0) {
return;
}
}
if (filter instanceof MemoizableTransformer) {
((MemoizableTransformer) filter).startCaching();
}
try {
List<CyNode> nodeList = network.getNodeList();
List<CyEdge> edgeList = network.getEdgeList();
double total = nodeList.size() + edgeList.size();
List<CyIdentifiable> selected = new ArrayList<>();
List<CyIdentifiable> unselected = new ArrayList<>();
for (CyNode node : nodeList) {
if (monitor.isCancelled()) {
return;
}
boolean accepted = filter.accepts(network, node);
if (accepted) {
selected.add(node);
nodeCount++;
} else {
unselected.add(node);
}
monitor.setProgress(++counter / total);
}
for (CyEdge edge : edgeList) {
if (monitor.isCancelled()) {
return;
}
boolean accepted = filter.accepts(network, edge);
if (accepted) {
selected.add(edge);
edgeCount++;
} else {
unselected.add(edge);
}
monitor.setProgress(++counter / total);
}
// now do the selection
for (CyIdentifiable element : unselected) {
CyRow row = network.getRow(element);
if (row.get(CyNetwork.SELECTED, Boolean.class)) {
row.set(CyNetwork.SELECTED, Boolean.FALSE);
}
}
for (CyIdentifiable element : selected) {
CyRow row = network.getRow(element);
if (!row.get(CyNetwork.SELECTED, Boolean.class)) {
row.set(CyNetwork.SELECTED, Boolean.TRUE);
}
}
} finally {
if (filter instanceof MemoizableTransformer) {
((MemoizableTransformer) filter).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", nodeCount, nodeCount == 1 ? "node" : "nodes", edgeCount, edgeCount == 1 ? "edge" : "edges", duration));
}
}
Aggregations