Search in sources :

Example 16 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.

the class PartitionUtilTest method testPartition2.

@Test
public void testPartition2() {
    CyNetworkView networkView = mock(CyNetworkView.class);
    CyNetwork network = mock(CyNetwork.class);
    when(networkView.getModel()).thenReturn(network);
    EdgeWeighter edgeWeighter = new EdgeWeighter();
    List<LayoutPartition> result = PartitionUtil.partition(networkView, false, edgeWeighter);
    assertNotNull(result);
    assertEquals(0, result.size());
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Test(org.junit.Test)

Example 17 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.

the class PartitionUtilTest method testPartition1.

@Test
public void testPartition1() {
    CyNetworkView networkView = mock(CyNetworkView.class);
    CyNetwork network = mock(CyNetwork.class);
    when(networkView.getModel()).thenReturn(network);
    Collection<CyNode> nodes = new ArrayList<CyNode>();
    EdgeWeighter edgeWeighter = new EdgeWeighter();
    List<LayoutPartition> result = PartitionUtil.partition(networkView, nodes, edgeWeighter);
    assertNotNull(result);
    assertEquals(0, result.size());
}
Also used : ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Test(org.junit.Test)

Example 18 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.

the class AbstractCyNodeTest method testSetNestedNetwork.

@Test
public void testSetNestedNetwork() {
    CyNode n1 = net.addNode();
    CyNetwork net2 = mock(CyNetwork.class);
    n1.setNetworkPointer(net2);
    assertNotNull(n1.getNetworkPointer());
    assertEquals(net2, n1.getNetworkPointer());
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Test(org.junit.Test)

Example 19 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.

the class PartitionUtil method partition.

/**
	 * Partition the graph -- this builds the LayoutEdge and LayoutNode
	 * arrays as a byproduct.  The algorithm for this was taken from
	 * algorithms/graphPartition/SGraphPartition.java.
	 *
	 * @param networkView the CyNetworkView representing the graph
	 * @param nodeSet the set of nodes to consider
	 * @param edgeWeighter the weighter to use for edge weighting
	 * @return a List of LayoutPartitions
	 */
public static List<LayoutPartition> partition(CyNetworkView networkView, Collection<CyNode> nodeSet, EdgeWeighter edgeWeighter) {
    final List<LayoutPartition> partitions = new ArrayList<LayoutPartition>();
    final CyNetwork network = networkView.getModel();
    final Map<CyNode, Integer> nodesSeenMap = new HashMap<CyNode, Integer>();
    final Map<CyEdge, Integer> edgesSeenMap = new HashMap<CyEdge, Integer>();
    final Map<CyNode, View<CyNode>> nodesToViews = new HashMap<CyNode, View<CyNode>>();
    int partitionNumber = 1;
    // Initialize the maps
    for (final View<CyNode> nv : networkView.getNodeViews()) {
        nodesSeenMap.put(nv.getModel(), m_NODE_HAS_NOT_BEEN_SEEN);
        nodesToViews.put(nv.getModel(), nv);
    }
    for (CyEdge edge : network.getEdgeList()) edgesSeenMap.put(edge, m_NODE_HAS_NOT_BEEN_SEEN);
    // OK, now traverse the graph
    for (final CyNode node : nodeSet) {
        // Have we seen this already?
        if (nodesSeenMap.get(node) == m_NODE_HAS_BEEN_SEEN)
            continue;
        // Nope, first time
        final LayoutPartition part = new LayoutPartition(network.getNodeCount(), network.getEdgeCount());
        part.setPartitionNumber(partitionNumber++);
        // Set the edge weighter
        part.setEdgeWeighter(edgeWeighter);
        nodesSeenMap.put(node, m_NODE_HAS_BEEN_SEEN);
        // Traverse through all connected nodes
        traverse(network, networkView, nodesToViews, node, part, nodesSeenMap, edgesSeenMap);
        // Done -- finalize the parition
        part.trimToSize();
        // Finally, now that we're sure we've touched all of our
        // nodes.  Fix up our edgeLayout list to have all of our
        // layoutNodes
        part.fixEdges();
        partitions.add(part);
    }
    // Now sort the partitions based on the partition's node count
    Collections.sort(partitions, new Comparator<LayoutPartition>() {

        public int compare(LayoutPartition p1, LayoutPartition p2) {
            return (p2.size() - p1.size());
        }

        public boolean equals(LayoutPartition obj) {
            return false;
        }
    });
    return partitions;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyNode(org.cytoscape.model.CyNode)

Example 20 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.

the class AbstractCyNodeTest method testSetNullNestedNetwork.

// null nested networks are allowed
@Test
public void testSetNullNestedNetwork() {
    CyNode n1 = net.addNode();
    // put a real network here first
    CyNetwork net2 = mock(CyNetwork.class);
    n1.setNetworkPointer(net2);
    assertNotNull(n1.getNetworkPointer());
    assertEquals(net2, n1.getNetworkPointer());
    // now put a null network to verify that we've "unset" things
    n1.setNetworkPointer(null);
    assertNull(n1.getNetworkPointer());
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Test(org.junit.Test)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)48 Test (org.junit.Test)20 CyNode (org.cytoscape.model.CyNode)16 CyNetworkView (org.cytoscape.view.model.CyNetworkView)13 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)11 CyEdge (org.cytoscape.model.CyEdge)9 ArrayList (java.util.ArrayList)8 List (java.util.List)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyRow (org.cytoscape.model.CyRow)6 BaseIntegrationTest (org.baderlab.csplugins.enrichmentmap.integration.BaseIntegrationTest)5 DataSetFiles (org.baderlab.csplugins.enrichmentmap.model.DataSetFiles)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)5 CyTable (org.cytoscape.model.CyTable)5 Map (java.util.Map)4 Set (java.util.Set)4 EMCreationParameters (org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters)4 View (org.cytoscape.view.model.View)4 Inject (com.google.inject.Inject)3 Color (java.awt.Color)3