Author: kono
Date: 2010-01-13 15:11:58 -0800 (Wed, 13 Jan 2010)
New Revision: 18893

Added:
   
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/VisualStyleBuilder.java
Modified:
   
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/ConvertCyNetworkToSFNetworks.java
   
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/NestedNetworkCreator.java
Log:
Visual Style builder added.

Modified: 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/ConvertCyNetworkToSFNetworks.java
===================================================================
--- 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/ConvertCyNetworkToSFNetworks.java
   2010-01-13 23:03:17 UTC (rev 18892)
+++ 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/ConvertCyNetworkToSFNetworks.java
   2010-01-13 23:11:58 UTC (rev 18893)
@@ -1,6 +1,5 @@
 package org.cytoscape.DenovoPGNetworkAlignmentPlugin;
 
-
 import cytoscape.CyEdge;
 import cytoscape.CyNetwork;
 import cytoscape.Cytoscape;
@@ -9,8 +8,9 @@
 import networks.hashNetworks.FloatHashNetwork;
 import java.util.List;
 
-
-/** Converts a single CyNetwork plus two edge attributes to two separate 
SFNetworks.
+/**
+ * Converts a single CyNetwork plus two edge attributes to two separate
+ * SFNetworks.
  */
 class ConvertCyNetworkToSFNetworks {
        private FloatHashNetwork physicalNetwork = null;
@@ -18,49 +18,84 @@
 
        /**
         * Initialises the network converter.
-        * @param inputNetwork              The single network that will be 
split apart into a physical and a genetic network.
-        * @param physicalNetworkAttrName   The name of a floating point edge 
attribute that will be used to induce edges in the physical network.
-        * @param geneticNetworkAttrName    The name of a floating point edge 
attribute that will be used to induce edges in the genetic network.
-        * @throws IllegalArgumentException Will be thrown if any argument is 
null, or if either physicalNetworkAttrName or geneticNetworkAttrName
-        *                                  do not correspond to a floating 
point edge attribute.
-        * @throws ClassCastException       This should never be thrown and 
indicated an internal error!
+        * 
+        * @param inputNetwork
+        *            The single network that will be split apart into a 
physical
+        *            and a genetic network.
+        * @param physicalNetworkAttrName
+        *            The name of a floating point edge attribute that will be 
used
+        *            to induce edges in the physical network.
+        * @param geneticNetworkAttrName
+        *            The name of a floating point edge attribute that will be 
used
+        *            to induce edges in the genetic network.
+        * @throws IllegalArgumentException
+        *             Will be thrown if any argument is null, or if either
+        *             physicalNetworkAttrName or geneticNetworkAttrName do not
+        *             correspond to a floating point edge attribute.
+        * @throws ClassCastException
+        *             This should never be thrown and indicated an internal 
error!
         */
-       public ConvertCyNetworkToSFNetworks(final CyNetwork inputNetwork, final 
String physicalNetworkAttrName, final String geneticNetworkAttrName)
-               throws IllegalArgumentException, ClassCastException
-       {
+       public ConvertCyNetworkToSFNetworks(final CyNetwork inputNetwork,
+                       final String physicalNetworkAttrName,
+                       final String geneticNetworkAttrName)
+                       throws IllegalArgumentException, ClassCastException {
                if (inputNetwork == null)
-                       throw new IllegalArgumentException("input parameter 
inputNetwork must not be null!");
+                       throw new IllegalArgumentException(
+                                       "input parameter inputNetwork must not 
be null!");
                if (physicalNetworkAttrName == null)
-                       throw new IllegalArgumentException("input parameter 
physicalNetworkAttrName must not be null!");
+                       throw new IllegalArgumentException(
+                                       "input parameter 
physicalNetworkAttrName must not be null!");
                if (geneticNetworkAttrName == null)
-                       throw new IllegalArgumentException("input parameter 
geneticNetworkAttrName must not be null!");
+                       throw new IllegalArgumentException(
+                                       "input parameter geneticNetworkAttrName 
must not be null!");
 
                final CyAttributes edgeAttributes = 
Cytoscape.getEdgeAttributes();
                if (edgeAttributes.getType(physicalNetworkAttrName) != 
CyAttributes.TYPE_FLOATING)
-                       throw new IllegalArgumentException("\"" + 
physicalNetworkAttrName
-                                                          + "\" is not the 
name of a known floating point edge attribute!");
+                       throw new IllegalArgumentException(
+                                       "\""
+                                                       + 
physicalNetworkAttrName
+                                                       + "\" is not the name 
of a known floating point edge attribute!");
                if (edgeAttributes.getType(geneticNetworkAttrName) != 
CyAttributes.TYPE_FLOATING)
-                       throw new IllegalArgumentException("\"" + 
geneticNetworkAttrName
-                                                          + "\" is not the 
name of a known floating point edge attribute!");
+                       throw new IllegalArgumentException(
+                                       "\""
+                                                       + geneticNetworkAttrName
+                                                       + "\" is not the name 
of a known floating point edge attribute!");
 
-               physicalNetwork = new FloatHashNetwork(/* selfOk = */ false, /* 
directed = */ false, /* startsize = */ 1);
-               geneticNetwork = new FloatHashNetwork(/* selfOk = */ false, /* 
directed = */ false, /* startsize = */ 1);
+               physicalNetwork = new FloatHashNetwork(/* selfOk = */false, /*
+                                                                               
                                                         * directed
+                                                                               
                                                         * =
+                                                                               
                                                         */false, /*
+                                                                               
                                                                         * 
startsize
+                                                                               
                                                                         * =
+                                                                               
                                                                         */
+                               1);
+               geneticNetwork = new FloatHashNetwork(/* selfOk = */false, /* 
directed = */
+                               false, /* startsize = */1);
 
-               for (final CyEdge edge : 
(List<CyEdge>)inputNetwork.edgesList()) {
+               for (final CyEdge edge : (List<CyEdge>) 
inputNetwork.edgesList()) {
                        final String edgeID = edge.getIdentifier();
 
-                       final Double physicalAttrValue = 
edgeAttributes.getDoubleAttribute(edgeID, physicalNetworkAttrName);
+                       final Double physicalAttrValue = 
edgeAttributes.getDoubleAttribute(
+                                       edgeID, physicalNetworkAttrName);
                        if (physicalAttrValue != null)
-                               
physicalNetwork.add(edge.getSource().getIdentifier(), 
edge.getTarget().getIdentifier(),
-                                                   
physicalAttrValue.floatValue());
+                               
physicalNetwork.add(edge.getSource().getIdentifier(), edge
+                                               .getTarget().getIdentifier(), 
physicalAttrValue
+                                               .floatValue());
 
-                       final Double geneticAttrValue = 
edgeAttributes.getDoubleAttribute(edgeID, geneticNetworkAttrName);
+                       final Double geneticAttrValue = 
edgeAttributes.getDoubleAttribute(
+                                       edgeID, geneticNetworkAttrName);
                        if (geneticAttrValue != null)
-                               
geneticNetwork.add(edge.getSource().getIdentifier(), 
edge.getTarget().getIdentifier(),
-                                                  
geneticAttrValue.floatValue());
+                               
geneticNetwork.add(edge.getSource().getIdentifier(), edge
+                                               .getTarget().getIdentifier(), 
geneticAttrValue
+                                               .floatValue());
                }
        }
 
-       SFNetwork getPhysicalNetwork() { return physicalNetwork; }
-       SFNetwork getGeneticNetwork() { return geneticNetwork; }
+       SFNetwork getPhysicalNetwork() {
+               return physicalNetwork;
+       }
+
+       SFNetwork getGeneticNetwork() {
+               return geneticNetwork;
+       }
 }

Modified: 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/NestedNetworkCreator.java
===================================================================
--- 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/NestedNetworkCreator.java
   2010-01-13 23:03:17 UTC (rev 18892)
+++ 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/NestedNetworkCreator.java
   2010-01-13 23:11:58 UTC (rev 18893)
@@ -23,19 +23,28 @@
  * Creates an overview network for the detected complexes and nested networks
  * for each complex.
  */
-class NestedNetworkCreator {
+public class NestedNetworkCreator {
+
+       // Package private constants.
+       static final String GENE_COUNT = "gene count";
+       static final String SCORE = "score";
+       static final String EDGE_SCORE = "edge score";
+
        private CyNetwork overviewNetwork = null;
        private Map<TypedLinkNodeModule<String, BFEdge>, CyNode> 
moduleToCyNodeMap;
 
        /**
         * Instantiates an overview network of complexes (modules) and one 
nested
         * network for each node in the overview network.
-        * @param networkOfModules  a representation of the "overview" network
-        * @param originalNetwork   the network that the overview network was 
generated from
+        * 
+        * @param networkOfModules
+        *            a representation of the "overview" network
+        * @param originalNetwork
+        *            the network that the overview network was generated from
         */
-       NestedNetworkCreator(final TypedLinkNetwork<TypedLinkNodeModule<String, 
BFEdge>, BFEdge> networkOfModules,
-                            final CyNetwork originalNetwork)
-       {
+       NestedNetworkCreator(
+                       final TypedLinkNetwork<TypedLinkNodeModule<String, 
BFEdge>, BFEdge> networkOfModules,
+                       final CyNetwork originalNetwork) {
                moduleToCyNodeMap = new HashMap<TypedLinkNodeModule<String, 
BFEdge>, CyNode>();
 
                overviewNetwork = Cytoscape.createNetwork(
@@ -47,43 +56,41 @@
                final CyAttributes edgeAttribs = Cytoscape.getEdgeAttributes();
 
                int nodeIndex = 1;
-               for (final TypedLinkEdge<TypedLinkNodeModule<String, BFEdge>, 
BFEdge> edge :
-                    networkOfModules.edges())
-               {
+               for (final TypedLinkEdge<TypedLinkNodeModule<String, BFEdge>, 
BFEdge> edge : networkOfModules
+                               .edges()) {
                        final TypedLinkNodeModule<String, BFEdge> sourceModule 
= edge
                                        .source().value();
                        CyNode sourceNode = moduleToCyNodeMap.get(sourceModule);
                        if (sourceNode == null) {
                                final String nodeName = 
findNextAvailableNodeName("Complex"
                                                + nodeIndex);
-                               sourceNode = makeOverviewNode(nodeName, 
sourceModule, nodeAttribs,
-                                                             originalNetwork);
+                               sourceNode = makeOverviewNode(nodeName, 
sourceModule,
+                                               nodeAttribs, originalNetwork);
                                ++nodeIndex;
                        }
 
-                       final TypedLinkNodeModule<String, BFEdge> targetModule =
-                               edge.target().value();
+                       final TypedLinkNodeModule<String, BFEdge> targetModule 
= edge
+                                       .target().value();
                        CyNode targetNode = moduleToCyNodeMap.get(targetModule);
                        if (targetNode == null) {
                                final String nodeName = 
findNextAvailableNodeName("Complex"
                                                + nodeIndex);
-                               targetNode = makeOverviewNode(nodeName, 
targetModule, nodeAttribs,
-                                                             originalNetwork);
+                               targetNode = makeOverviewNode(nodeName, 
targetModule,
+                                               nodeAttribs, originalNetwork);
                                ++nodeIndex;
                        }
 
                        final CyEdge newEdge = Cytoscape.getCyEdge(sourceNode, 
targetNode,
-                                                                  
Semantics.INTERACTION,
-                                                                  
"complex-complex",
-                                                                  /* create = 
*/true);
+                                       Semantics.INTERACTION, 
"complex-complex",
+                                       /* create = */true);
 
-                       edgeAttribs.setAttribute(newEdge.getIdentifier(), "edge 
score",
-                                                
Double.valueOf(edge.value().link()));
+                       edgeAttribs.setAttribute(newEdge.getIdentifier(), 
EDGE_SCORE,
+                                       Double.valueOf(edge.value().link()));
                        overviewNetwork.addEdge(newEdge);
-                       
+
                }
-
-               applyNetworkLayout(overviewNetwork, "default");
+               applyNetworkLayout(overviewNetwork, 
VisualStyleBuilder.getVisualStyle()
+                               .getName());
        }
 
        CyNetwork getOverviewNetwork() {
@@ -93,28 +100,32 @@
        /**
         * @returns a new node in the overview (module/complex) network.
         */
-       private CyNode makeOverviewNode(final String nodeName, final 
TypedLinkNodeModule<String, BFEdge> module,
-                                       final CyAttributes nodeAttribs, final 
CyNetwork originalNetwork)
-       {
+       private CyNode makeOverviewNode(final String nodeName,
+                       final TypedLinkNodeModule<String, BFEdge> module,
+                       final CyAttributes nodeAttribs, final CyNetwork 
originalNetwork) {
                final CyNode newNode = Cytoscape.getCyNode(nodeName, /* create 
= */true);
                moduleToCyNodeMap.put(module, newNode);
                overviewNetwork.addNode(newNode);
                final Set<String> genes = module.getMemberValues();
-               nodeAttribs.setAttribute(newNode.getIdentifier(), "gene count", 
Integer.valueOf(genes.size()));
-               nodeAttribs.setAttribute(newNode.getIdentifier(), "score", 
Double.valueOf(module.score()));
-               newNode.setNestedNetwork(generateNestedNetwork(nodeName, genes, 
originalNetwork));
+               nodeAttribs.setAttribute(newNode.getIdentifier(), GENE_COUNT, 
Integer
+                               .valueOf(genes.size()));
+               nodeAttribs.setAttribute(newNode.getIdentifier(), SCORE, Double
+                               .valueOf(module.score()));
+               nodeAttribs.setAttribute(newNode.getIdentifier(), SCORE, Math
+                               .sqrt(genes.size() / Math.PI));
+               newNode.setNestedNetwork(generateNestedNetwork(nodeName, genes,
+                               originalNetwork));
 
                return newNode;
        }
 
-       private CyNetwork generateNestedNetwork(final String networkName, final 
Set<String> nodeNames,
-                                               final CyNetwork 
originalNetwork) 
-       {
+       private CyNetwork generateNestedNetwork(final String networkName,
+                       final Set<String> nodeNames, final CyNetwork 
originalNetwork) {
                if (nodeNames.isEmpty())
                        return null;
 
                final CyNetwork nestedNetwork = 
Cytoscape.createNetwork(networkName,
-                                                                       /* 
create_view = */ false);
+               /* create_view = */false);
 
                // Add the nodes to our new nested network.
                final List<CyNode> nodes = new ArrayList<CyNode>();
@@ -125,7 +136,8 @@
                }
 
                // Add the edges induced by "originalNetwork" to our new nested 
network.
-               final List<CyEdge> edges = 
(List<CyEdge>)originalNetwork.getConnectingEdges(nodes);
+               final List<CyEdge> edges = (List<CyEdge>) originalNetwork
+                               .getConnectingEdges(nodes);
                for (final CyEdge edge : edges)
                        nestedNetwork.addEdge(edge);
 
@@ -195,7 +207,8 @@
        }
 
        private void applyNetworkLayout(final CyNetwork network, final String 
style) {
-               final CyNetworkView targetView = 
Cytoscape.getNetworkView(network.getIdentifier());
+               final CyNetworkView targetView = 
Cytoscape.getNetworkView(network
+                               .getIdentifier());
                targetView.setVisualStyle(style);
                Cytoscape.getVisualMappingManager().setVisualStyle(style);
                targetView.applyLayout(CyLayouts.getDefaultLayout());

Added: 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/VisualStyleBuilder.java
===================================================================
--- 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/VisualStyleBuilder.java
                             (rev 0)
+++ 
csplugins/trunk/ucsd/ruschein/DenovoPGNetworkAlignment/src/org/cytoscape/DenovoPGNetworkAlignmentPlugin/VisualStyleBuilder.java
     2010-01-13 23:11:58 UTC (rev 18893)
@@ -0,0 +1,132 @@
+package org.cytoscape.DenovoPGNetworkAlignmentPlugin;
+
+import static cytoscape.visual.VisualPropertyType.EDGE_LABEL;
+import static cytoscape.visual.VisualPropertyType.NODE_LABEL;
+import giny.view.Label;
+
+import java.awt.Color;
+
+import cytoscape.Cytoscape;
+import cytoscape.visual.EdgeAppearanceCalculator;
+import cytoscape.visual.GlobalAppearanceCalculator;
+import cytoscape.visual.LabelPosition;
+import cytoscape.visual.LineStyle;
+import cytoscape.visual.NodeAppearanceCalculator;
+import cytoscape.visual.NodeShape;
+import cytoscape.visual.VisualPropertyType;
+import cytoscape.visual.VisualStyle;
+import cytoscape.visual.calculators.AbstractCalculator;
+import cytoscape.visual.calculators.BasicCalculator;
+import cytoscape.visual.calculators.Calculator;
+import cytoscape.visual.mappings.DiscreteMapping;
+import cytoscape.visual.mappings.ObjectMapping;
+import cytoscape.visual.mappings.PassThroughMapping;
+
+public class VisualStyleBuilder {
+
+       private VisualStyle overviewVS = null;
+
+       private static final String OVERVIEW_VS_NAME = "Complex Overview Style";
+       private static final String MODULE_VS_NAME = "Denovo Module Style";
+
+       // This is a Singleton.
+       private static VisualStyleBuilder builder = new VisualStyleBuilder();
+
+       public static VisualStyle getVisualStyle() {
+               return builder.getOverviewStyle();
+       }
+
+       private VisualStyleBuilder() {
+               overviewVS = buidlOverviewStyle();
+               Cytoscape.getVisualMappingManager().getCalculatorCatalog()
+                               .addVisualStyle(overviewVS);
+       }
+
+       public VisualStyle getOverviewStyle() {
+               return overviewVS;
+       }
+
+       /**
+        * Generate default visual style. The style is database-dependent.
+        * 
+        * @return default visual style.
+        */
+       private VisualStyle buidlOverviewStyle() {
+               final Color NODE_COLOR = new Color(25, 25, 200);
+               final Color NODE_BORDER_COLOR = new Color(25, 25, 25);
+               final Color NODE_LABEL_COLOR = new Color(10, 10, 10);
+
+               final Color EDGE_COLOR = new Color(10, 10, 10);
+               final Color EDGE_LABEL_COLOR = new Color(50, 50, 255);
+               
+               final LabelPosition POSITION = new LabelPosition(Label.SOUTH, 
Label.NORTH, Label.JUSTIFY_CENTER, 0.0, 4.0);
+
+               final VisualStyle defStyle = new VisualStyle(OVERVIEW_VS_NAME);
+
+               NodeAppearanceCalculator nac = 
defStyle.getNodeAppearanceCalculator();
+               EdgeAppearanceCalculator eac = 
defStyle.getEdgeAppearanceCalculator();
+               GlobalAppearanceCalculator gac = defStyle
+                               .getGlobalAppearanceCalculator();
+
+               gac.setDefaultBackgroundColor(Color.white);
+
+               PassThroughMapping m = new PassThroughMapping("", 
AbstractCalculator.ID);
+
+               final Calculator calc = new BasicCalculator(OVERVIEW_VS_NAME + 
"-"
+                               + "NodeLabelMapping", m, NODE_LABEL);
+               PassThroughMapping me = new PassThroughMapping("", 
"interaction");
+
+               final Calculator calce = new BasicCalculator(OVERVIEW_VS_NAME + 
"-"
+                               + "EdgeLabelMapping", me, EDGE_LABEL);
+               nac.setCalculator(calc);
+
+               
nac.getDefaultAppearance().set(VisualPropertyType.NODE_FILL_COLOR,
+                               NODE_COLOR);
+               nac.getDefaultAppearance().set(VisualPropertyType.NODE_OPACITY, 
0);
+               nac.getDefaultAppearance().set(VisualPropertyType.NODE_SHAPE,
+                               NodeShape.ROUND_RECT);
+               
nac.getDefaultAppearance().set(VisualPropertyType.NODE_LABEL_OPACITY,
+                               225);
+               
nac.getDefaultAppearance().set(VisualPropertyType.NODE_LABEL_POSITION, 
POSITION);
+               
+               
nac.getDefaultAppearance().set(VisualPropertyType.NODE_LINE_WIDTH, 4);
+               
nac.getDefaultAppearance().set(VisualPropertyType.NODE_BORDER_COLOR, 
NODE_BORDER_COLOR);
+               nac.getDefaultAppearance().set(VisualPropertyType.NODE_SIZE, 
65);
+               
nac.getDefaultAppearance().set(VisualPropertyType.NODE_LABEL_COLOR,
+                               NODE_LABEL_COLOR);
+               nac.setNodeSizeLocked(true);
+
+               eac.setCalculator(calce);
+               eac.getDefaultAppearance().set(VisualPropertyType.EDGE_COLOR,
+                               EDGE_COLOR);
+               
eac.getDefaultAppearance().set(VisualPropertyType.EDGE_LABEL_COLOR,
+                               EDGE_LABEL_COLOR);
+               
eac.getDefaultAppearance().set(VisualPropertyType.EDGE_FONT_SIZE, 5);
+               eac.getDefaultAppearance().set(VisualPropertyType.EDGE_OPACITY, 
90);
+               eac.getDefaultAppearance().set(
+                               VisualPropertyType.EDGE_SRCARROW_OPACITY, 120);
+               eac.getDefaultAppearance().set(
+                               VisualPropertyType.EDGE_TGTARROW_OPACITY, 120);
+               
eac.getDefaultAppearance().set(VisualPropertyType.EDGE_LABEL_OPACITY,
+                               70);
+               
eac.getDefaultAppearance().set(VisualPropertyType.EDGE_LINE_WIDTH, 3);
+               eac.getDefaultAppearance().set(VisualPropertyType.EDGE_LABEL, 
"");
+
+               // Set edge color based on datasource name
+
+               DiscreteMapping edgeLineStyle = new 
DiscreteMapping(LineStyle.SOLID,
+                               "interaction type", ObjectMapping.EDGE_MAPPING);
+
+               edgeLineStyle.putMapValue("physical", LineStyle.SOLID);
+               edgeLineStyle.putMapValue("genetic", LineStyle.LONG_DASH);
+
+
+               Calculator edgeLineStyleCalc = new 
BasicCalculator(OVERVIEW_VS_NAME
+                               + "-" + "EdgeLineStyleMapping", edgeLineStyle,
+                               VisualPropertyType.EDGE_LINE_STYLE);
+
+               eac.setCalculator(edgeLineStyleCalc);
+
+               return defStyle;
+       }
+}
\ No newline at end of file

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