Author: clopes
Date: 2012-07-24 14:17:27 -0700 (Tue, 24 Jul 2012)
New Revision: 29977
Modified:
csplugins/trunk/toronto/clopes/mcode/pom.xml
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
csplugins/trunk/toronto/clopes/mcode/src/test/java/org/cytoscape/mcode/internal/model/MCODEAlgorithmTest.java
Log:
Fixed MCODE's algorithm:
- If includeLoops is false: possibleEdgeNum = (nodeCount*(nodeCount-1))/2
- Count the number of loops and decrease actualEdgeNum by loopCount when
includeLoops is false
- Ignore edge directions: possibleEdgeNum = (nodeCount*(nodeCount-1))/2
Added a unit test for a complete graph.
Modified: csplugins/trunk/toronto/clopes/mcode/pom.xml
===================================================================
--- csplugins/trunk/toronto/clopes/mcode/pom.xml 2012-07-24 21:12:53 UTC
(rev 29976)
+++ csplugins/trunk/toronto/clopes/mcode/pom.xml 2012-07-24 21:17:27 UTC
(rev 29977)
@@ -6,6 +6,7 @@
<bundle.symbolicName>org.cytoscape.mcode.mcode-plugin</bundle.symbolicName>
<bundle.namespace>org.cytoscape.mcode</bundle.namespace>
<cytoscape.api.version>3.0.0-beta3-SNAPSHOT</cytoscape.api.version>
+
<cytoscape.impl.version>3.0.0-alpha10-SNAPSHOT</cytoscape.impl.version>
<maven.build.timestamp.format>MMMM
yyyy</maven.build.timestamp.format>
<buildDate>${maven.build.timestamp}</buildDate>
</properties>
@@ -223,6 +224,37 @@
<version>4.8.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>model-impl</artifactId>
+ <version>${cytoscape.impl.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>model-impl</artifactId>
+ <version>${cytoscape.impl.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>ding-presentation-impl</artifactId>
+ <version>${cytoscape.impl.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>ding-presentation-impl</artifactId>
+ <version>${cytoscape.impl.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified:
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
2012-07-24 21:12:53 UTC (rev 29976)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
2012-07-24 21:17:27 UTC (rev 29977)
@@ -834,22 +834,21 @@
int nodeCount = network.getNodeCount();
int edgeCount = network.getEdgeCount();
- if (includeLoops) {
+ if (!includeLoops) {
//count loops
List<CyNode> nodes = network.getNodeList();
for (CyNode n : nodes) {
List<CyEdge> loopEdges =
network.getConnectingEdgeList(n, n, CyEdge.Type.ANY);
- if (loopEdges != null && loopEdges.size() > 0) {
+ if (loopEdges != null && loopEdges.size() > 0)
loopCount++;
- }
}
- possibleEdgeNum = nodeCount * nodeCount;
+ possibleEdgeNum = (nodeCount * (nodeCount - 1)) / 2;
actualEdgeNum = edgeCount - loopCount;
} else {
- possibleEdgeNum = nodeCount * nodeCount;
+ possibleEdgeNum = (nodeCount * (nodeCount + 1)) / 2;
actualEdgeNum = edgeCount;
}
Modified:
csplugins/trunk/toronto/clopes/mcode/src/test/java/org/cytoscape/mcode/internal/model/MCODEAlgorithmTest.java
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/test/java/org/cytoscape/mcode/internal/model/MCODEAlgorithmTest.java
2012-07-24 21:12:53 UTC (rev 29976)
+++
csplugins/trunk/toronto/clopes/mcode/src/test/java/org/cytoscape/mcode/internal/model/MCODEAlgorithmTest.java
2012-07-24 21:17:27 UTC (rev 29977)
@@ -2,10 +2,29 @@
import static org.junit.Assert.*;
+import java.util.List;
+
+import org.cytoscape.application.CyApplicationManager;
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.ding.NetworkViewTestSupport;
+import org.cytoscape.event.CyEventHelper;
import org.cytoscape.mcode.internal.util.MCODEUtil;
import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.subnetwork.CyRootNetworkManager;
+import org.cytoscape.model.subnetwork.CySubNetwork;
+import org.cytoscape.util.swing.FileUtil;
+import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.model.CyNetworkViewManager;
+import org.cytoscape.view.presentation.RenderingEngineFactory;
+import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
+import org.cytoscape.view.vizmap.VisualMappingManager;
+import org.cytoscape.view.vizmap.VisualStyleFactory;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
/**
* Copyright (c) 2004 Memorial Sloan-Kettering Cancer Center
@@ -50,16 +69,32 @@
MCODEAlgorithm alg;
CyNetwork networkSmall;
- MCODEParameterSet params;
- MCODEUtil mcodeutil;
+ MCODEUtil mcodeUtil;
+
+ @Mock RenderingEngineFactory<CyNetwork> rendererFactory;
+ @Mock CyRootNetworkManager rootNetMgr;
+ @Mock CyApplicationManager appMgr;
+ @Mock CyNetworkViewManager netViewMgr;
+ @Mock VisualMappingManager vmMgr;
+ @Mock VisualStyleFactory styleFactory;
+ @Mock VisualMappingFunctionFactory vmfFactory;
+ @Mock CySwingApplication swingApp;
+ @Mock CyEventHelper evtHelper;
+ @Mock FileUtil fileUtil;
+
+ NetworkViewTestSupport netViewTestSupport;
+ CyNetworkManager netMgr;
+ CyNetworkViewFactory netViewFactory;
@Before
public void setUp() throws Exception {
- // TODO
-// mcodeutil = new MCODEUtil(renderingEngineFactory,
networkViewFactory, rootNetworkFactory, applicationManager,
-//
networkManager, networkViewManager, vmMgr, eventHelper);
-// alg = new MCODEAlgorithm(null);
-// params = new MCODEParameterSet();
+ MockitoAnnotations.initMocks(this);
+ netViewTestSupport = new NetworkViewTestSupport();
+ rootNetMgr = netViewTestSupport.getRootNetworkFactory();
+ netViewFactory = netViewTestSupport.getNetworkViewFactory();
+
+ mcodeUtil = new MCODEUtil(rendererFactory, netViewFactory,
rootNetMgr, appMgr, netMgr, netViewMgr,
+ styleFactory, vmMgr, swingApp, evtHelper,
vmfFactory, vmfFactory, fileUtil);
// networkSmall = Cytoscape.createNetworkFromFile("testData" +
File.separator + "smallTest.sif");
}
@@ -77,4 +112,61 @@
// double score = alg.scoreCluster(clusters[0]);
// assertEquals(score, (double) 1.5, 0);
}
+
+ @Test
+ public void testCompleteGraph() {
+ CyNetwork net = createCompleteGraph(16);
+ int resultId = 1;
+ MCODECluster[] clusters = findClusters(net, resultId);
+
+ assertEquals(1, clusters.length);
+
+ MCODECluster c = clusters[0];
+ CySubNetwork cn = c.getNetwork();
+
+ assertNotNull(cn);
+ assertEquals(resultId, c.getResultId());
+ assertEquals(14.118, c.getClusterScore(), 0.001);
+ assertEquals(16, cn.getNodeCount());
+ assertEquals(120, cn.getEdgeCount());
+ assertNotNull(c.getSeedNode());
+
+ // check scores of the nodes
+ for (CyNode n : cn.getNodeList()) {
+ assertEquals(15.0, alg.getNodeScore(n.getSUID(),
resultId), 0.0);
+ }
+ }
+
+ private MCODECluster[] findClusters(CyNetwork net, int resultId) {
+ mcodeUtil.getCurrentParameters().setParams(new
MCODEParameterSet(), resultId, net.getSUID());
+ alg = new MCODEAlgorithm(net.getSUID(), mcodeUtil);
+ alg.scoreGraph(net, resultId);
+
+ return alg.findClusters(net, resultId);
+ }
+
+ private CyNetwork createCompleteGraph(int totalNodes) {
+ CyNetwork net = netViewTestSupport.getNetwork();
+
+ for (int i = 0; i < totalNodes; i++) {
+ net.addNode();
+ }
+
+ List<CyNode> nodes = net.getNodeList();
+
+ for (int i = 0; i < totalNodes; i++) {
+ CyNode src = nodes.get(i);
+
+ for (int j = 0; j < totalNodes; j++) {
+ CyNode tgt = nodes.get(j);
+
+ if (src != tgt && !net.containsEdge(src, tgt))
+ net.addEdge(src, tgt, false);
+ }
+ }
+
+ assertEquals((totalNodes*(totalNodes-1))/2, net.getEdgeCount());
+
+ return net;
+ }
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.