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;
}
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);
}
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);
}
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);
}
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));
}
Aggregations