use of org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory 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);
}
use of org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory 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);
}
}
use of org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory 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);
}
use of org.cytoscape.filter.internal.filters.topology.TopologyFilterFactory 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());
}
Aggregations