Author: ruschein
Date: 2009-11-23 11:28:29 -0800 (Mon, 23 Nov 2009)
New Revision: 18542
Modified:
cytoscape/trunk/build.xml
cytoscape/trunk/src/cytoscape/data/readers/NNFParser.java
cytoscape/trunk/tests/cytoscape/data/readers/NNFReaderTest.java
Log:
Changed semantics when reading multiple NNF files with networks that have the
same name.
Modified: cytoscape/trunk/build.xml
===================================================================
--- cytoscape/trunk/build.xml 2009-11-23 19:28:55 UTC (rev 18541)
+++ cytoscape/trunk/build.xml 2009-11-23 19:28:29 UTC (rev 18542)
@@ -286,7 +286,7 @@
target="1.5"
optimize="on"
includeAntRuntime="false"
- deprecation="yes">
+ deprecation="no">
<classpath refid="classpath" />
<include name="cytoscape/**" />
<src path="${src.dir}" />
Modified: cytoscape/trunk/src/cytoscape/data/readers/NNFParser.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/NNFParser.java 2009-11-23
19:28:55 UTC (rev 18541)
+++ cytoscape/trunk/src/cytoscape/data/readers/NNFParser.java 2009-11-23
19:28:29 UTC (rev 18542)
@@ -4,6 +4,7 @@
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
+import java.util.Set;
import cytoscape.CyEdge;
import cytoscape.CyNetwork;
@@ -38,28 +39,47 @@
}
+ /** Returns the first network with title "networkTitle" or null, if
there is no network w/ this title.
+ */
+ private CyNetwork getNetworkByTitle(final String networkTitle) {
+ Set<CyNetwork> networks = Cytoscape.getNetworkSet();
+ for (final CyNetwork network : networks) {
+ if (network.getTitle().equals(networkTitle))
+ return network;
+ }
+
+ return null;
+ }
+
+
/**
* Parse an entry/line in an NNF file.
*
* @param line
*/
public boolean parse(String line) {
- System.out.println("Current Line: " + line);
-
// Split with white space chars
parts = line.split("\\s+");
length = parts.length;
CyNetwork network = networkMap.get(parts[0]);
if (network == null) {
- // Create network without view. View will be created
later in class Cytoscape.
- network = Cytoscape.createNetwork(parts[0], false);
+ // Reuse existing networks, if possible:
+ network = getNetworkByTitle(parts[0]);
+ if (network == null) {
+ // Create network without view. View will be
created later in class Cytoscape.
+ network = Cytoscape.createNetwork(parts[0], /*
create_view = */false);
+ }
+
networkMap.put(parts[0], network);
networks.add(network);
+
// Create node attribute called IMMUTABLE_ID
Cytoscape.getNetworkAttributes().setAttribute(network.getIdentifier(),
IMMUTABLE_ID, network.getIdentifier());
Cytoscape.getNetworkAttributes().setUserEditable(IMMUTABLE_ID, false);
- CyNode parent = Cytoscape.getCyNode(parts[0]);
+
+ // Attempt to nest network within the node with the
same name
+ final CyNode parent = Cytoscape.getCyNode(parts[0]);
if (parent != null) {
parent.setNestedNetwork(network);
}
@@ -68,7 +88,7 @@
if (length == 2) {
final CyNode node = Cytoscape.getCyNode(parts[1], true);
network.addNode(node);
- CyNetwork nestedNetwork = networkMap.get(parts[1]);
+ final CyNetwork nestedNetwork =
networkMap.get(parts[1]);
if (nestedNetwork != null) {
node.setNestedNetwork(nestedNetwork);
}
@@ -88,7 +108,8 @@
target.setNestedNetwork(nestedNetwork);
}
- final CyEdge edge = Cytoscape.getCyEdge(source, target,
Semantics.INTERACTION, parts[2], true);
+ final CyEdge edge = Cytoscape.getCyEdge(source, target,
Semantics.INTERACTION, parts[2], /* create = */true,
+ /* directed =
*/true);
network.addEdge(edge);
} else {
// Invalid number of columns.
Modified: cytoscape/trunk/tests/cytoscape/data/readers/NNFReaderTest.java
===================================================================
--- cytoscape/trunk/tests/cytoscape/data/readers/NNFReaderTest.java
2009-11-23 19:28:55 UTC (rev 18541)
+++ cytoscape/trunk/tests/cytoscape/data/readers/NNFReaderTest.java
2009-11-23 19:28:29 UTC (rev 18542)
@@ -12,6 +12,7 @@
import junit.framework.TestCase;
+
/**
* Test code for Nested Network Format file reader.
*
@@ -34,7 +35,20 @@
}
+ /**
+ * Destroys all networks in the root graph. Please note that the nodes
and edges of said networks are also being destroyed.
+ */
+ private static void destroyNetworksEdgesAndNodes() {
+ final Set<CyNetwork> networks = Cytoscape.getNetworkSet();
+ for (final CyNetwork network : networks) {
+ Cytoscape.destroyNetwork(network, /* destroy_unique =
*/true);
+ }
+ }
+
+
public void testGood1() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
final NNFReader reader = new NNFReader(FILE_LOCATION +
"good1.nnf");
reader.read();
@@ -44,6 +58,8 @@
public void testGood2() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
final NNFReader reader = new NNFReader(FILE_LOCATION +
"good2.nnf");
reader.read();
@@ -53,6 +69,8 @@
public void testGood3() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
final NNFReader reader = new NNFReader(FILE_LOCATION +
"good3.nnf");
reader.read();
@@ -76,6 +94,8 @@
public void testGood4() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
final NNFReader reader = new NNFReader(FILE_LOCATION +
"good4.nnf");
reader.read();
@@ -84,7 +104,7 @@
final Set<CyNetwork> networks = Cytoscape.getNetworkSet();
CyNetwork targetNetwork = null;
- for (CyNetwork net:networks) {
+ for (CyNetwork net : networks) {
if (net.getTitle().equals("M3")) {
targetNetwork = net;
}
@@ -107,6 +127,8 @@
public void testGood5() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
final NNFReader reader = new NNFReader(FILE_LOCATION +
"good5.nnf");
reader.read();
@@ -116,6 +138,8 @@
public void testGood6() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
final NNFReader reader = new NNFReader(FILE_LOCATION +
"good6.nnf");
reader.read();
@@ -125,6 +149,8 @@
public void testBad1() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
final NNFReader reader = new NNFReader(FILE_LOCATION +
"bad1.nnf");
try {
reader.read();
@@ -140,6 +166,8 @@
public void testBad2() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
final NNFReader reader = new NNFReader(FILE_LOCATION +
"bad2.nnf");
try {
reader.read();
@@ -152,4 +180,26 @@
//If not caught by the above, something is wrong!
fail();
}
+
+ public void testMultipleFiles() throws Exception {
+ destroyNetworksEdgesAndNodes();
+
+ final NNFReader reader1 = new NNFReader(FILE_LOCATION +
"good3.nnf");
+ reader1.read();
+
+ final NNFReader reader2 = new NNFReader(FILE_LOCATION +
"good4.nnf");
+ reader2.read();
+ final Set<CyNetwork> networks = Cytoscape.getNetworkSet();
+ CyNetwork targetNetwork = null;
+ for (CyNetwork net : networks) {
+ if (net.getTitle().equals("M3")) {
+ targetNetwork = net;
+ }
+ }
+
+ assertNotNull(targetNetwork);
+ assertEquals("M3", targetNetwork.getTitle());
+ assertEquals(6, targetNetwork.getNodeCount());
+ assertEquals(4, targetNetwork.getEdgeCount());
+ }
}
--
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=.