Search in sources :

Example 6 with CyNetworkFactory

use of org.cytoscape.model.CyNetworkFactory in project cytoscape-impl by cytoscape.

the class ReadDataManager method createRootNetwork.

protected CyRootNetwork createRootNetwork() {
    if (this.rootNetwork != null)
        return this.rootNetwork;
    final CyNetworkFactory networkFactory = serviceRegistrar.getService(CyNetworkFactory.class);
    final CyNetwork baseNet = networkFactory.createNetwork();
    final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
    final CyRootNetwork rootNetwork = rootNetworkManager.getRootNetwork(baseNet);
    return rootNetwork;
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 7 with CyNetworkFactory

use of org.cytoscape.model.CyNetworkFactory in project PhenomeScape by soulj.

the class LoadNetworkTask method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setTitle("Loading " + species + " Network");
    taskMonitor.setStatusMessage("Creating network");
    CyNetworkFactory networkFactory = cyServiceRegistrar.getService(CyNetworkFactory.class);
    CyNetwork network = networkFactory.createNetwork();
    network.getRow(network).set(CyNetwork.NAME, NetworkUtils.getUniqueNetworkName(cyServiceRegistrar, species + "Network"));
    network.getDefaultEdgeTable().createColumn("Confidence", Double.class, false);
    Map<String, CyNode> nodeNameMap = new HashMap<String, CyNode>();
    Scanner sc = new Scanner(input);
    nodeNameMap = new HashMap<String, CyNode>();
    while (sc.hasNextLine()) {
        String line = sc.nextLine();
        String[] nodes = line.split("\t");
        CyNode node1 = null;
        CyNode node2 = null;
        if (nodeNameMap.containsKey(nodes[0])) {
            node1 = nodeNameMap.get(nodes[0]);
        } else {
            node1 = network.addNode();
            CyRow attributes = network.getRow(node1);
            attributes.set("name", nodes[0]);
            nodeNameMap.put(nodes[0], node1);
        }
        if (nodeNameMap.containsKey(nodes[1])) {
            node2 = (CyNode) nodeNameMap.get(nodes[1]);
        } else {
            node2 = network.addNode();
            CyRow attributes = network.getRow(node2);
            attributes.set("name", nodes[1]);
            nodeNameMap.put(nodes[1], node2);
        }
        CyEdge myEdge = network.addEdge(node1, node2, false);
        network.getRow(myEdge).set("interaction", "ppi");
        network.getRow(myEdge).set("Confidence", Double.parseDouble(nodes[2]));
        network.getRow(myEdge).set("name", nodes[0] + " (ppi) " + nodes[1]);
    }
    sc.close();
    CyNetworkManager networkManager = cyServiceRegistrar.getService(CyNetworkManager.class);
    networkManager.addNetwork(network);
}
Also used : Scanner(java.util.Scanner) CyNetworkManager(org.cytoscape.model.CyNetworkManager) HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge)

Example 8 with CyNetworkFactory

use of org.cytoscape.model.CyNetworkFactory in project cytoscape-impl by cytoscape.

the class ServiceConfigurationTest method setup.

@Before
public void setup() {
    registerMockService(Interpreter.class);
    registerMockService(CyServiceRegistrar.class);
    // Obtain a CyNetworkFactory service:
    final ServiceTracker networkFactoryTracker = new ServiceTracker(bundleContext, CyNetworkFactory.class.getName(), null);
    networkFactoryTracker.open();
    networkFactory = null;
    try {
        // seconds
        final int WAIT_TIME = 10000;
        networkFactory = (CyNetworkFactory) networkFactoryTracker.waitForService(WAIT_TIME);
    } catch (final InterruptedException ie) {
        fail("Did not get an instance of a CyNetworkFactory service within the specified amount of time!");
    }
    assertNotNull(networkFactory);
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) Before(org.junit.Before)

Example 9 with CyNetworkFactory

use of org.cytoscape.model.CyNetworkFactory in project cytoscape-impl by cytoscape.

the class LayoutEdgeTest method createLayoutNodes.

private void createLayoutNodes() {
    CyNetworkFactory nFactory = support.getNetworkFactory();
    CyNetwork newNetwork = nFactory.createNetwork();
    CyNode s = newNetwork.addNode();
    CyNode t = newNetwork.addNode();
    final CyNetworkViewFactory viewFactory = support.getNetworkViewFactory();
    CyNetworkView newView = viewFactory.createNetworkView(newNetwork);
    final View<CyNode> sourceView = newView.getNodeView(s);
    final View<CyNode> targetView = newView.getNodeView(t);
    CyRow sRow = newNetwork.getRow(s);
    CyRow tRow = newNetwork.getRow(t);
    layoutNodeS = new LayoutNode(sourceView, 0, sRow);
    layoutNodeT = new LayoutNode(targetView, 1, tRow);
}
Also used : CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 10 with CyNetworkFactory

use of org.cytoscape.model.CyNetworkFactory in project cytoscape-impl by cytoscape.

the class NewNetworkSelectedNodesOnlyTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    NetworkViewTestSupport viewSupport = new NetworkViewTestSupport();
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetworkFactory networkFactory = networkSupport.getNetworkFactory();
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyRootNetworkManager crnf = new CyRootNetworkManagerImpl();
    CyNetworkViewFactory cnvf = viewSupport.getNetworkViewFactory();
    CyNetworkManager netmgr = mock(CyNetworkManager.class);
    CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
    CyNetworkNaming naming = mock(CyNetworkNaming.class);
    VisualMappingManager vmm = mock(VisualMappingManager.class);
    CyApplicationManager appManager = mock(CyApplicationManager.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    CyGroupManager groupMgr = mock(CyGroupManager.class);
    RenderingEngineManager renderingEngineMgr = mock(RenderingEngineManager.class);
    CyLayoutAlgorithm defLayout = mock(CyLayoutAlgorithm.class);
    CyLayoutAlgorithmManager layoutMgr = mock(CyLayoutAlgorithmManager.class);
    when(layoutMgr.getDefaultLayout()).thenReturn(defLayout);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layoutMgr);
    NewNetworkSelectedNodesOnlyTaskFactoryImpl factory = new NewNetworkSelectedNodesOnlyTaskFactoryImpl(undoSupport, crnf, cnvf, netmgr, networkViewManager, naming, vmm, appManager, eventHelper, groupMgr, renderingEngineMgr, serviceRegistrar);
    CyNetwork network = networkFactory.createNetwork();
    CyNode node = network.addNode();
    network.getRow(node).set(CyNetwork.SELECTED, true);
    TaskObserver observer = mock(TaskObserver.class);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    TaskIterator iterator = factory.createTaskIterator(network);
    while (iterator.hasNext()) {
        Task t = iterator.next();
        t.run(taskMonitor);
        if (t instanceof ObservableTask)
            observer.taskFinished((ObservableTask) t);
    }
    verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) CyNetwork(org.cytoscape.model.CyNetwork) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyRootNetworkManagerImpl(org.cytoscape.model.internal.CyRootNetworkManagerImpl) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskObserver(org.cytoscape.work.TaskObserver) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Aggregations

CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)15 CyNetwork (org.cytoscape.model.CyNetwork)10 CyNetworkManager (org.cytoscape.model.CyNetworkManager)8 CyNode (org.cytoscape.model.CyNode)7 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)7 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)7 CyApplicationManager (org.cytoscape.application.CyApplicationManager)6 CyGroupManager (org.cytoscape.group.CyGroupManager)5 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)5 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)5 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)5 CyEventHelper (org.cytoscape.event.CyEventHelper)4 CyEdge (org.cytoscape.model.CyEdge)4 CyRow (org.cytoscape.model.CyRow)4 CyLayoutAlgorithmManager (org.cytoscape.view.layout.CyLayoutAlgorithmManager)4 TaskIterator (org.cytoscape.work.TaskIterator)4 UndoSupport (org.cytoscape.work.undo.UndoSupport)4 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)3 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)3