Author: clopes
Date: 2011-09-20 13:56:51 -0700 (Tue, 20 Sep 2011)
New Revision: 26889

Modified:
   cytoscapeweb/trunk/cytoscapeweb/default.properties
   cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/test1.graphml
   cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/test2.xgmml
   cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
   cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js
   
cytoscapeweb/trunk/cytoscapeweb/src-test/org/cytoscapeweb/model/converters/SIFConverterTest.as
   cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/GraphProxy.as
   
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/SIFConverter.as
Log:
Implemented #2463: Add "nodeAttr" option to sif function.
Updated API doc.

Modified: cytoscapeweb/trunk/cytoscapeweb/default.properties
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/default.properties  2011-09-20 20:53:22 UTC 
(rev 26888)
+++ cytoscapeweb/trunk/cytoscapeweb/default.properties  2011-09-20 20:56:51 UTC 
(rev 26889)
@@ -1,3 +1,3 @@
-build.version=0.7.5
+build.version=0.8
 
 FLEX_HOME=/Applications/Adobe Flex Builder 3 Plug-in/sdks/3.2.0/
\ No newline at end of file

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/test1.graphml
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/test1.graphml        
2011-09-20 20:53:22 UTC (rev 26888)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/test1.graphml        
2011-09-20 20:56:51 UTC (rev 26889)
@@ -1,5 +1,6 @@
 <graphml>
   <key id="label" for="all" attr.name="label" attr.type="string"/>
+  <key id="name" for="all" attr.name="name" attr.type="string"/>
 
   <key id="weight" for="node" attr.name="weight" attr.type="double"/>
   <key id="ranking" for="node" attr.name="ranking" attr.type="int"/>
@@ -20,6 +21,7 @@
       <data key="weight">0.45</data>
       <data key="ranking">1</data>
       <data key="label">n1&#xA;TEST LINE BREAK</data>
+      <data key="name">Node 1</data>
       <data key="type">1</data>
       <data key="shape">ELLIPSE</data>
       <data key="special">false</data>
@@ -28,6 +30,7 @@
       <data key="weight">0.22</data>
       <data key="ranking">2</data>
       <data key="label">n2</data>
+      <data key="name">Node 2</data>
       <data key="type">2</data>
       <data key="shape">TRIANGLE</data>
       <data key="special">true</data>
@@ -36,6 +39,7 @@
       <data key="weight">0.09</data>
       <data key="ranking">3</data>
       <data key="label">n3</data>
+      <data key="name">Node 3</data>
       <data key="type">1</data>
       <data key="shape">OCTAGON</data>
       <data key="special">false</data>
@@ -44,6 +48,7 @@
       <data key="weight">0.03</data>
       <data key="ranking">4</data>
       <data key="label">n4</data>
+      <data key="name">Node 4</data>
       <data key="type">1</data>
       <data key="shape">DIAMOND</data>
       <data key="special">false</data>
@@ -51,6 +56,7 @@
     <node id="5">
       <data key="weight">0.10</data>
       <data key="ranking">5</data>
+      <data key="name">Node 5</data>
       <data key="label">n5</data>
       <data key="type">3</data>
       <data key="shape">PARALLELOGRAM</data>

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/test2.xgmml
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/test2.xgmml  
2011-09-20 20:53:22 UTC (rev 26888)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/fixtures/test2.xgmml  
2011-09-20 20:56:51 UTC (rev 26889)
@@ -6,6 +6,7 @@
   <att type="real" name="GRAPH_VIEW_CENTER_Y" value="0"/>
   
   <node id="101" weight="0.45" label="A01">
+    <att type="string" name="name" value="Node 1"/>
     <att type="string" name="type" value="1"/>
     <att type="integer" name="ranking" value="1"/>
     <att type="string" name="shape" value="ELLIPSE"/>
@@ -13,6 +14,7 @@
     <graphics x="387.25" y="304" fill="#cccccc" outline="#333333" w="36" 
cy:nodeTransparency="0.8" cy:nodeLabelFont="SansSerif-0-11" type="ELLIPSE" 
h="36" width="1"/>
   </node>
   <node id="102" weight="0.22" label="A02">
+    <att type="string" name="name" value="Node 2"/>
     <att type="string" name="type" value="2"/>
     <att type="integer" name="ranking" value="2"/>
     <att type="string" name="shape" value="TRIANGLE"/>
@@ -20,6 +22,7 @@
     <graphics x="324.85" y="340" fill="#cccccc" outline="#333333" 
w="22.857142857142854" cy:nodeTransparency="0.8" 
cy:nodeLabelFont="SansSerif-0-11" type="ELLIPSE" h="22.857142857142854" 
width="1"/>
   </node>
   <node id="103" weight="0.09" label="A03">
+    <att type="string" name="name" value="Node 3"/>
     <att type="string" name="type" value="2"/>
     <att type="integer" name="ranking" value="3"/>
     <att type="string" name="shape" value="OCTAGON"/>
@@ -27,6 +30,7 @@
     <graphics x="324.85" y="412" fill="#cccccc" outline="#333333" 
w="15.428571428571429" cy:nodeTransparency="0.8" 
cy:nodeLabelFont="SansSerif-0-11" type="ELLIPSE" h="15.428571428571429" 
width="1"/>
   </node>
   <node id="104" weight="0.03" label="A04">
+    <att type="string" name="name" value="Node 4"/>
     <att type="string" name="type" value="1"/>
     <att type="integer" name="ranking" value="4"/>
     <att type="string" name="shape" value="DIAMOND"/>
@@ -34,6 +38,7 @@
     <graphics x="387.25" y="448" fill="#cccccc" outline="#333333" w="12" 
cy:nodeTransparency="0.8" cy:nodeLabelFont="SansSerif-0-11" type="ELLIPSE" 
h="12" width="1"/>
   </node>
   <node id="105" weight="0.1" label="A05">
+    <att type="string" name="name" value="Node 5"/>
     <att type="string" name="type" value="3"/>
     <att type="integer" name="ranking" value="5"/>
     <att type="string" name="shape" value="PARALLELOGRAM"/>

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js    
2011-09-20 20:53:22 UTC (rev 26888)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/cytoscapeweb.js    
2011-09-20 20:56:51 UTC (rev 26889)
@@ -196,20 +196,20 @@
          *               <ul class="options">
          *                    <li><code>network</code>: The model that 
describes the network. Only this option is mandatory. It can be one of the 
following formats:
          *                                              <ul><li>{@link 
org.cytoscapeweb.NetworkModel}: A simple JavaScript object that defines the raw 
data from which to build a network.</li>
-         *                                                  <li><a 
href="http://graphml.graphdrawing.org/primer/graphml-primer.html"; 
target="_blank">GraphML</a>: An XML format for graphs.</li>
-         *                                                  <li><a 
href="http://www.cs.rpi.edu/~puninj/XGMML/"; target="_blank">XGMML</a>: This XML 
format allows you to define
+         *                                                  <li><a 
href="http://graphml.graphdrawing.org/primer/graphml-primer.html"; 
rel="external">GraphML</a>: An XML format for graphs.</li>
+         *                                                  <li><a 
href="http://www.cs.rpi.edu/~puninj/XGMML/"; rel="external">XGMML</a>: This XML 
format allows you to define
          *                                                      visual 
properties (e.g. colors and shapes) and nodes positioning, if you want to,
          *                                                      although using 
the <code>visualStyle</code> and <code>layout</code> options is usually 
better.</li>
-         *                                                  <li><a 
href="http://cytoscape.wodaklab.org/wiki/Cytoscape_User_Manual/Network_Formats/";
 target="_blank">SIF</a>: A simpler text format
+         *                                                  <li><a 
href="http://cytoscape.wodaklab.org/wiki/Cytoscape_User_Manual/Network_Formats/";
 rel="external">SIF</a>: A simpler text format
          *                                                      that can be 
very useful if you do not need to set custom nodes/edges attributes.</li>
          *                                              </ul></li>
          *                    <li><code>visualStyle</code>: an optional {@link 
org.cytoscapeweb.VisualStyle} object to be applied on this network.</li>
          *                    <li><code>layout</code>: an optional {@link 
org.cytoscapeweb.Layout} object, or just the layout name.
          *                                             The default is 
"ForceDirected", unless the network data is an 
-         *                                             <a 
href="http://www.cs.rpi.edu/~puninj/XGMML/"; target="_blank">XGMML</a>, whose 
-         *                                             <code><a 
href="http://www.cs.rpi.edu/~puninj/XGMML/draft-xgmml-20010628.html#NodeE"; 
target="_blank">node</a></code>
+         *                                             <a 
href="http://www.cs.rpi.edu/~puninj/XGMML/"; rel="external">XGMML</a>, whose 
+         *                                             <code><a 
href="http://www.cs.rpi.edu/research/groups/pb/punin/public_html/XGMML/draft-xgmml-20010628.html#NodeE";
 rel="external">node</a></code>
          *                                             elements contain
-         *                                             <code><a 
href="http://www.cs.rpi.edu/~puninj/XGMML/draft-xgmml-20010628.html#GraphicsA"; 
target="_blank">graphics</a></code>
+         *                                             <code><a 
href="http://www.cs.rpi.edu/research/groups/pb/punin/public_html/XGMML/draft-xgmml-20010628.html#GLCPE";
 rel="external">graphics</a></code>
          *                                             tags with defined 
<code>x</code> and <code>y</code> attributes. In that case, the "Preset" layout 
is applied by default.</li>
          *                    <li><code>nodeLabelsVisible</code>: Boolean that 
defines whether or not the node labels will be visible.
          *                                                        The default 
value is <code>true</code>.
@@ -651,8 +651,18 @@
         },
         
         /**
-         * TODO: DOCUMENT ME
-         * 
+         * <p>Add new nodes and/or edges to the network.</p>
+         * <p>The rules described in {@link 
org.cytoscapeweb.Visualization#addNode} and {@link 
org.cytoscapeweb.Visualization#addEdge}
+         * are still valid here.</p>
+         * <p>You can add nodes and edges together and, when doing so, the 
order of the elements in
+         * the array do not matter, because Cytoscape Web will first add all 
the nodes, and then
+         * the edges.</p>
+         * <p>The new element must have a <code>group</code> field set to 
either <code>"nodes"</code> or <code>"edges"</code>,
+         * because {@link org.cytoscapeweb.Node} and {@link 
org.cytoscapeweb.Edge} objects are untype objects and Cytoscape Web
+         * has no other safe way of making the distinction between the two 
types.</p>
+         * <p>If the new elements contain visual properties (e.g. color, 
opacity), they are simply ignored and Cytoscape Web applies
+         * new visual property values according to the current {@link 
org.cytoscapeweb.VisualStyle} and {@link org.cytoscapeweb.VisualStyleBypass}.
+         * The node positions (x, y), if specified, are respected, though.</p>
          * @example
          * // 1. Add two nodes with no data (IDs will be created 
automatically):
          * var nodesArray = [ { group: "nodes", x: 10, y: 35 },
@@ -663,7 +673,15 @@
          * var array = [ { group: "nodes", x: 10, y: 35, data: { id: "n01" } },
          *               { group: "nodes", x: 20, y: 70, data: { id: "n02" } },
          *               { group: "edges", data: { source: "n01", target: 
"n02" } } ];
-         * vis.addElements(array, true);
+         * var elements = vis.addElements(array, true);
+         * @param {Array} [items] The nodes and edges to be added to the 
network.
+         *                        The array must contain {@link 
org.cytoscapeweb.Node} and/or {@link org.cytoscapeweb.Edge} objects.
+         * @param {Boolean} [updateVisualMappers] It tells Cytoscape Web to 
reapply the visual mappers
+         *                                        to the network view after 
removing the elements.
+         * @return {Array} The new created elements ({@link 
org.cytoscapeweb.Node} and {@link org.cytoscapeweb.Edge} objects).
+         * @see org.cytoscapeweb.Visualization#removeElements
+         * @see org.cytoscapeweb.Visualization#addNode
+         * @see org.cytoscapeweb.Visualization#addEdge
          */
         addElements: function(/*items, updateVisualMappers*/) {
             var items, updateVisualMappers = false;
@@ -680,9 +698,11 @@
         /**
          * <p>Create a new node and add it to the network view.<p>
          * <p>If the node <code>id</code> is not specified, Cytoscape Web 
creates a new one automatically.</p>
-         * <p>If you try to add data attributes that have not been previously 
defined,
-         * Cytoscape Web will automatically add the necessary field 
definitions, although it might be safer to always add the
-         * fields to the schema first, by calling {@link 
org.cytoscapeweb.Visualization#addDataField}.</p>
+         * <p>If the data contains attributes that have not been previously 
defined in the {@link org.cytoscapeweb.DataSchema},
+         * Cytoscape Web will throw an error. To prevent that, you simply add 
the new fields to the schema first, 
+         * by calling {@link org.cytoscapeweb.Visualization#addDataField}.</p>
+         * <p>Keep in mind that {@link 
org.cytoscapeweb.Visualization#addElements} is much faster if you have to
+         * add more than one element at once.</p>
          * @example
          * var data = { id: "n4",
          *              label: "MYO2 (Yeast)",
@@ -698,6 +718,7 @@
          *                                        The default value is 
<code>false</code>.
          * @return {org.cytoscapeweb.Node} The new created node object.
          * @see org.cytoscapeweb.Visualization#addEdge
+         * @see org.cytoscapeweb.Visualization#addElements
          * @see org.cytoscapeweb.Visualization#removeElements
          */
         addNode: function (x, y/*, data, updateVisualMappers*/) {
@@ -710,10 +731,13 @@
         /**
          * <p>Create a new edge linking two nodes and add it to the network 
view.<p>
          * <p>If the edge <code>id</code> is not specified, Cytoscape Web 
creates a new one automatically.</p>
-         * <p>Throws exception if missing <code>source</code> or 
<code>target</code>.</p>
-         * <p>If you try to add data attributes that have not been previously 
defined,
-         * Cytoscape Web will automatically add the necessary field 
definitions, although it might be safer to always add the
-         * fields to the schema first, by calling {@link 
org.cytoscapeweb.Visualization#addDataField}.</p>
+         * <p>However the <code>source</code> and <code>target</code> data 
fields are mandatory, and Cytoscape Web 
+         * throws an error if any of them is missing.</p>
+         * <p>If the data contains attributes that have not been previously 
defined in the {@link org.cytoscapeweb.DataSchema},
+         * Cytoscape Web will throw an error. To prevent that, just add the 
new fields to the schema first, 
+         * by calling {@link org.cytoscapeweb.Visualization#addDataField}.</p>
+         * <p>You might also want to take a look at {@link 
org.cytoscapeweb.Visualization#addElements}, which is much faster
+         * when adding more than one element at once.</p>
          * @example
          * var data = { id: "e10",
          *              source: "n1",
@@ -729,6 +753,7 @@
          *                                        to the network view after 
adding the edge.
          * @return {org.cytoscapeweb.Edge} The new created edge object.
          * @see org.cytoscapeweb.Visualization#addNode
+         * @see org.cytoscapeweb.Visualization#addElements
          * @see org.cytoscapeweb.Visualization#removeElements
          */
         addEdge: function (data/*, updateVisualMappers*/) {
@@ -1153,7 +1178,7 @@
          *                        return a boolean value indicating the 
visibility of that element.
          *                        So, if it returns false, that node or edge 
will be hidden.
          *                        If the argument is an array, it must contain 
the IDs or the Node/Edge objects
-         *                        you want to make visible.
+         *                        you want to make or keep visible.
          * @param {Boolean} [updateVisualMappers] It tells Cytoscape Web to 
update and reapply the visual mappers
          *                                        to the network view after 
the filtering action is done.
          *                                        Remember that continuous 
mappers ignore filtered out elements
@@ -1245,7 +1270,7 @@
         },
         
         /**
-         * <p>Return the network data as <a 
href="http://graphml.graphdrawing.org/primer/graphml-primer.html"; 
target="_blank">GraphML</a>.</p>
+         * <p>Return the network data as <a 
href="http://graphml.graphdrawing.org/primer/graphml-primer.html"; 
rel="external">GraphML</a>.</p>
          * @return {String} The XML text.
          * @see org.cytoscapeweb.Visualization#xgmml
          * @see org.cytoscapeweb.Visualization#sif
@@ -1256,7 +1281,7 @@
         },
 
         /**
-         * <p>Return the network data as <a 
href="http://www.cs.rpi.edu/~puninj/XGMML/"; target="_blank">XGMML</a>.</p>
+         * <p>Return the network data as <a 
href="http://www.cs.rpi.edu/~puninj/XGMML/"; rel="external">XGMML</a>.</p>
          * @return {String} The XML text.
          * @see org.cytoscapeweb.Visualization#graphml
          * @see org.cytoscapeweb.Visualization#sif
@@ -1267,19 +1292,27 @@
         },
         
         /**
-         * <p>Return the network data as <a 
href="http://cytoscape.wodaklab.org/wiki/Cytoscape_User_Manual/Network_Formats/";
 target="_blank">Simple Interaction Format (SIF)</a>.</p>
+         * <p>Return the network data as <a 
href="http://cytoscape.wodaklab.org/wiki/Cytoscape_User_Manual/Network_Formats/";
 rel="external">Simple Interaction Format (SIF)</a>.</p>
          * <p>Cytoscape Web uses tab characters to delimit the fields, because 
the node and interaction names may contain spaces.</p>
-         * <p>The node name in the SIF text is taken from the node's 
<code>data.id</code> attribute.</p>
+         * <p>By default, the node name in the SIF text is taken from the 
node's <code>data.id</code> attribute.
+         * You can choose any other node attribute to be the node name by 
passing the <code>nodeAttr</code> option. 
+         * Of course the custom node field should have unique values.</p>
          * <p>Cytoscape Web tries to get the interaction name from the edge's 
<code>data.interaction</code> attribute.
-         * You can choose any other edge attribute to be the interaction name 
by passing an <code>interactionAttr</code> parameter.
+         * You can choose any other edge attribute to be the interaction name 
by passing the <code>interactionAttr</code> option.
          * If the edge data does not have the defined interaction field, 
Cytoscape Web just uses the edge <code>id</code>.</p>
          * @example
          * var xml = '&lt;graphml&gt;' +
-         *               // Create a custom "type" attribute:
+         *               // Create a custom node "label" attribute:
+         *               '&lt;key id="label" for="node" attr.name="label" 
attr.type="string"/&gt;' +
+         *               // Create a custom  edge "type" attribute:
          *               '&lt;key id="type" for="edge" attr.name="type" 
attr.type="string"/&gt;' +
          *               '&lt;graph&gt;' +
-         *                   '&lt;node id="1"/&gt;' +
-         *                   '&lt;node id="2"/&gt;' +
+         *                   '&lt;node id="1"&gt;' +
+         *                       '&lt;data key="label"&gt;Node 1&lt;/data&gt;' 
+
+         *                   '&lt;/node&gt;' +
+         *                   '&lt;node id="2"&gt;' +
+         *                       '&lt;data key="label"&gt;Node 2&lt;/data&gt;' 
+
+         *                   '&lt;/node&gt;' +
          *                   '&lt;edge source="1" target="2"&gt;' +
          *                       '&lt;data 
key="type"&gt;co-expression&lt;/data&gt;' +
          *                   '&lt;/edge&gt;' +
@@ -1292,23 +1325,27 @@
          * var vis = new org.cytoscapeweb.Visualization("container_id");
          * 
          * vis.ready(function() {
-         *     // Export to SIF, using the "type" attribute as edge 
interaction:
-         *     var text = vis.sif('type');
+         *     // Export to SIF, using the "label" as node ID and edge "type" 
as edge interaction:
+         *     var text = vis.sif({ nodeAttr: 'label', interactionAttr: 
'type'});
          *     
-         *     // text ==  '1\tco-expression\t2\n' +
-         *     //          '2\tco-localization\t1\n'
+         *     // text ==  'Node 1\tco-expression\tNode 2\n' +
+         *     //          'Node 2\tco-localization\Node 1\n'
          * });
          * 
          * vis.draw({ network: xml });
          * 
-         * @param {String} [interactionAttr] Optional edge attribute name to 
be used as the SIF interaction name.
+         * @param {Object} [options] Non-mandatory settings:
+         *                           <ul class="options">
+         *                               <li><code>nodeAttr</code>:</strong> 
Optional node attribute name to be used as node name.</li>
+         *                               
<li><code>interactionAttr</code>:</strong> Optional edge attribute name to be 
used as interaction name.</li>
+         *                           </ul>
          * @return {String} The SIF text.
          * @see org.cytoscapeweb.Visualization#graphml
          * @see org.cytoscapeweb.Visualization#xgmml
          * @see org.cytoscapeweb.Visualization#networkModel
          */
-        sif: function (interactionAttr) {
-            return this.swf().getNetworkAsText("sif", { interactionAttr: 
interactionAttr });
+        sif: function (options) {
+            return this.swf().getNetworkAsText("sif", options);
         },
 
         /**
@@ -1552,6 +1589,8 @@
          * the new one and only one menu item will be displayed.</p>
          * <p>It is possible to add more than one menu item with the same 
label, but only if they are added to
          * different groups.</p>
+         * <p><b>Important:</b> Since the context menu is rendered by Flash, 
be aware of these 
+         * <a 
href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenuItem.html";
 rel="external">restrictions</a>.</p>
          * 
          * @example
          * // We will use the context menu to select the first neighbors of the
@@ -1681,7 +1720,7 @@
         /**
          * <p>Redefine this function if you want to use another method to 
detect the Flash Player version
          * and embed the SWF file (e.g. SWFObject).</p>
-         * <p>By default, Adobe's <a 
href="http://www.adobe.com/products/flashplayer/download/detection_kit/"; 
target="_blank">Flash Player Detection Kit</a>
+         * <p>By default, Adobe's <a 
href="http://www.adobe.com/products/flashplayer/download/detection_kit/"; 
rel="external">Flash Player Detection Kit</a>
          * is used.</p>
          * @requires <code>AC_OETags.js</code> and 
<code>playerProductInstall.swf</code>
          */

Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js   2011-09-20 
20:53:22 UTC (rev 26888)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js   2011-09-20 
20:56:51 UTC (rev 26889)
@@ -1344,16 +1344,19 @@
     test("SIF", function() {
        var sif = vis.sif();
        var edges = vis.edges();
+       // Default fields:
        $.each(edges, function(i, e) {
                var inter = e.data.interaction ? e.data.interaction : e.data.id;
                var line = e.data.source + "\t" + inter + "\t" + e.data.target; 
                ok(sif.indexOf(line) > -1, "SIF text should have the line: 
'"+line+"'");
        });
-       // Now replace the default interaction field:
-       var sif = vis.sif("type");
+       // Now replace the default node and interaction fields:
+       var sif = vis.sif({ nodeAttr: "name", interactionAttr: "type" });
        var edges = vis.edges();
        $.each(edges, function(i, e) {
-               var line = e.data.source + "\t" + e.data.type + "\t" + 
e.data.target; 
+               var src = vis.node(e.data.source).data.name;
+               var tgt = vis.node(e.data.target).data.name;
+               var line = src + "\t" + e.data.type + "\t" + tgt; 
                ok(sif.indexOf(line) > -1, "SIF text should have the line: 
'"+line+"'");
        });
     });

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/GraphProxy.as
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/GraphProxy.as    
2011-09-20 20:53:22 UTC (rev 26888)
+++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/GraphProxy.as    
2011-09-20 20:56:51 UTC (rev 26889)
@@ -765,8 +765,7 @@
                 if (format === "graphml") {
                     out = new GraphMLConverter().write(dtSet);
                 } else {
-                    var interaction:String =  options != null ? 
options.interactionAttr : null;
-                    out = new SIFConverter(interaction).write(dtSet);
+                    out = new SIFConverter(options).write(dtSet);
                 }
             }
 

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/SIFConverter.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/SIFConverter.as
       2011-09-20 20:53:22 UTC (rev 26888)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/converters/SIFConverter.as
       2011-09-20 20:56:51 UTC (rev 26889)
@@ -95,13 +95,15 @@
 
         // ========[ PRIVATE PROPERTIES 
]===========================================================
 
-        private var _interaction:String;
+        private var _nodeAttr:String;
+        private var _interactionAttr:String;
 
         // ========[ CONSTRUCTOR 
]==================================================================
 
-        public function SIFConverter(interactionAttr:String=null) {
+        public function SIFConverter(options:Object=null) {
             super();
-            _interaction = interactionAttr != null ? interactionAttr : 
INTERACTION;
+            _nodeAttr = options != null ? options.nodeAttr : ID;
+            _interactionAttr = options != null ? options.interactionAttr : 
INTERACTION;
         }
 
         // ========[ PUBLIC PROPERTIES 
]============================================================
@@ -117,23 +119,34 @@
             var sif:String = "";
             
             if (ds != null) {
-                var lookup:Object = {};
+                var nodeIds:Object = {/*id -> sif_id*/};
+                var writtenNodes:Object = {/*id -> boolean*/};
                 var nodes:Array = ds.nodes.data;
                 var edges:Array = ds.edges.data;
-           
-                for each (var e:Object in edges) {
-                    var src:String = e[SOURCE];
-                    var tgt:String = e[TARGET];
-                    var inter:String = e.hasOwnProperty(_interaction) ? 
e[_interaction] : e.id;
+                var n:Object, e:Object;
+                var id:*, src:String, tgt:String, inter:String;
+                
+                for each (n in nodes) {
+                    id = n.hasOwnProperty(_nodeAttr) ? n[_nodeAttr] : n.id;
+                    nodeIds[n.id] = id;
+                }
+                
+                for each (e in edges) {
+                    src = nodeIds[e[SOURCE]];
+                    tgt = nodeIds[e[TARGET]];
+                    inter = e.hasOwnProperty(_interactionAttr) ? 
e[_interactionAttr] : e.id;
                     
                     sif += (src + "\t" + inter + "\t" + tgt + "\n");
-                    lookup[src] = true;
-                    lookup[tgt] = true;
+                    writtenNodes[src] = true;
+                    writtenNodes[tgt] = true;
                 }
-                for each (var n:Object in nodes) {
-                    if (!lookup[n.id]) {
-                        sif += n.id + "\n";
-                        lookup[n.id] = true;
+                
+                for each (n in nodes) {
+                    id = nodeIds[n.id];
+                    
+                    if (!writtenNodes[id]) {
+                        sif += id + "\n";
+                        writtenNodes[id] = true;
                     }
                 }
            
@@ -158,7 +171,7 @@
 
             edgeSchema.addField(new DataField(ID, DataUtil.STRING));
             edgeSchema.addField(new DataField(LABEL, DataUtil.STRING));
-            edgeSchema.addField(new DataField(_interaction, DataUtil.STRING));
+            edgeSchema.addField(new DataField(_interactionAttr, 
DataUtil.STRING));
             edgeSchema.addField(new DataField(SOURCE, DataUtil.STRING));
             edgeSchema.addField(new DataField(TARGET, DataUtil.STRING));
             edgeSchema.addField(new DataField(DIRECTED, DataUtil.BOOLEAN, 
false));
@@ -230,7 +243,7 @@
         protected function createEdgeData(interaction:String, source:String, 
target:String):Object {
             var data:Object = {};
             data[ID] = source + " (" + interaction + ") " + target;
-            data[_interaction] = data[LABEL] = interaction;
+            data[_interactionAttr] = data[LABEL] = interaction;
             data[SOURCE] = source;
             data[TARGET] = target;
             data[DIRECTED] = false;

Modified: 
cytoscapeweb/trunk/cytoscapeweb/src-test/org/cytoscapeweb/model/converters/SIFConverterTest.as
===================================================================
--- 
cytoscapeweb/trunk/cytoscapeweb/src-test/org/cytoscapeweb/model/converters/SIFConverterTest.as
      2011-09-20 20:53:22 UTC (rev 26888)
+++ 
cytoscapeweb/trunk/cytoscapeweb/src-test/org/cytoscapeweb/model/converters/SIFConverterTest.as
      2011-09-20 20:56:51 UTC (rev 26889)
@@ -99,7 +99,7 @@
             }
         }
         
-        public function testWrite():void {
+        public function testWriteWithDefaultFields():void {
             var ds:DataSet = Fixtures.getDataSet(Fixtures.GRAPHML_SIMPLE);
             var data:Data = Data.fromDataSet(ds);
             var nodes:Array = data.nodes.toDataArray();
@@ -115,7 +115,8 @@
             }
             for each (e in edges) {
                 var inter:String = e.hasOwnProperty("interaction") ? 
e.interaction : e.id;
-                assertTrue("Missing interaction: " + inter, sif.indexOf(inter) 
> -1);
+                var line:String = e.source + "\t" + inter + "\t" + e.target;
+                assertTrue("Missing line: " + line, sif.indexOf(line) > -1);
             }
             
             // If we parse the SIF file again, will it generate the same graph?
@@ -126,14 +127,31 @@
             
             assertEquals(nodes.length, nodes2.length);
             assertEquals(edges.length, edges2.length);
+        }
+        
+        public function testWriteWithCustomFields():void {
+            var ds:DataSet = Fixtures.getDataSet(Fixtures.GRAPHML_SIMPLE);
+            var data:Data = Data.fromDataSet(ds);
+            var nodes:Array = data.nodes.toDataArray();
+            var edges:Array = data.edges.toDataArray();
+            var n:Object, e:Object;
+
+            var out:IDataOutput = new SIFConverter().write(ds);
+            var sif:String = "" + out;
             
-            // Test again, this time replacing the default "interaction" field:
-            out = new SIFConverter("label").write(ds);
-            sif = "" + out;
-
-            for each (e in edges) {
-                assertTrue("Missing interaction: " + e.label, 
sif.indexOf(e.label) > -1);
+            // Does the generated SIF contain all nodes and edges?
+            for each (n in nodes) {
+                assertTrue("Missing node: " + n.id, sif.indexOf(n.id) > -1);
             }
+            
+            // If we parse the SIF file again, will it generate the same graph?
+            var ds2:DataSet = new SIFConverter().parse(sif);
+            var data2:Data = Data.fromDataSet(ds2);
+            var nodes2:Array = data2.nodes.toDataArray();
+            var edges2:Array = data2.edges.toDataArray();
+            
+            assertEquals(nodes.length, nodes2.length);
+            assertEquals(edges.length, edges2.length);
         }
         
         // ========[ PRIVATE METHODS 
]==============================================================

-- 
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.

Reply via email to