Author: pwang
Date: 2012-02-09 12:14:14 -0800 (Thu, 09 Feb 2012)
New Revision: 28219

Added:
   csplugins/trunk/ucsd/pwang/subnetworkByCategory/pom.xml
   csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/
   csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/
   csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/
   csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/
   csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/
   
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/
   
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/MyAction.java
   
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/SubnetworkByCategory.java
   csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/resources/
   
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/resources/plugin.props
Log:
Original creation

Added: csplugins/trunk/ucsd/pwang/subnetworkByCategory/pom.xml
===================================================================
--- csplugins/trunk/ucsd/pwang/subnetworkByCategory/pom.xml                     
        (rev 0)
+++ csplugins/trunk/ucsd/pwang/subnetworkByCategory/pom.xml     2012-02-09 
20:14:14 UTC (rev 28219)
@@ -0,0 +1,58 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.cytoscape</groupId>
+  
+  <parent>
+    <groupId>cytoscape.coreplugins</groupId>
+    <artifactId>parent</artifactId>
+    <version>2.8.3-SNAPSHOT</version>
+  </parent>
+
+  
+  <artifactId>subnetworkbycategory</artifactId>
+  <packaging>jar</packaging>
+  <name>SubnetworkByCategory</name>
+  
+  
+  <!-- bootstrap for cytoscape dependencies, namely the parent POM snapshots 
-->
+  <repositories>
+        <repository>
+            <id>cytoscape_snapshots</id>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <name>Cytoscape Snapshots</name>
+            
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/snapshots/</url>
+        </repository>
+        <repository>
+            <id>cytoscape_releases</id>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <name>Cytoscape Releases</name>
+            
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/releases/</url>
+        </repository>
+    </repositories>
+  
+    <build>
+    <plugins>
+         <plugin>
+        <artifactId>maven-assembly-plugin</artifactId> 
+        <configuration>
+          <archive>
+            <manifestEntries>
+              
<Cytoscape-Plugin>org.cytoscape.subnetwork.SubnetworkByCategory</Cytoscape-Plugin>
+            </manifestEntries>
+          </archive>
+        </configuration>
+         </plugin>
+    </plugins>
+  </build>
+  
+</project>
\ No newline at end of file

Added: 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/MyAction.java
===================================================================
--- 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/MyAction.java
                                (rev 0)
+++ 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/MyAction.java
        2012-02-09 20:14:14 UTC (rev 28219)
@@ -0,0 +1,230 @@
+package org.cytoscape.subnetwork;
+
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.data.Semantics;
+import cytoscape.util.CytoscapeAction;
+import java.awt.event.ActionEvent;
+
+import cytoscape.CyNetwork;
+import cytoscape.CyNode;
+import cytoscape.CyEdge;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A simple action.  Change the names as appropriate and
+ * then fill in your expected behavior in the actionPerformed()
+ * method.
+ */
+public class MyAction extends CytoscapeAction {
+
+               private static final long serialVersionUID = 
123456789023451239L;
+
+               public MyAction() {
+                       // Give your action a name here
+                       super("Subnetwork by Category");
+
+                       // Set the menu you'd like here.  Plugins don't need
+                       // to live in the Plugins menu, so choose whatever
+                       // is appropriate!
+               setPreferredMenu("Plugins");
+               }
+               
+               public void actionPerformed(ActionEvent e) {
+                       // Do something useful here!
+                       CyNetwork net = Cytoscape.getCurrentNetwork();
+                       String attributeName = "Category";
+                       
+                       // 1. get the node list for each category
+                       HashMap categoryMap = getNodeCategoryMap(net, 
attributeName);
+                                               
+                       // 2. create subnetwork for each category               
        
+                       CyNetwork[] subnetworks = createSubnetworks(net, 
categoryMap);
+
+                       //3. create an overview network for all nested network
+                       Set overview_nodes = new HashSet();
+                       for (int i=0; i< subnetworks.length; i++){
+                               CyNode newNode 
=Cytoscape.getCyNode(subnetworks[i].getTitle(), true); 
+                               newNode.setNestedNetwork(subnetworks[i]);
+                               overview_nodes.add(newNode);
+                       }
+
+                       Set  overview_edges = getOverviewEdges(net, 
overview_nodes);
+                       final CyNetwork overview = 
Cytoscape.createNetwork(overview_nodes, overview_edges, "Overview of category 
", net, false);
+
+                       // 4. Create a view for overview network
+                       Cytoscape.createNetworkView(overview, 
overview.getTitle());
+               }
+               
+               
+               //
+               private Set getOverviewEdges(CyNetwork parentNetwork, Set 
overview_nodes){
+               
+                       HashSet overview_edgeSet = new HashSet();
+                       
+                       //1. Build node and edge set for each subnetwork
+                       int overview_nodeCount = overview_nodes.size();
+                       CyNode[] overview_nodeArray = new 
CyNode[overview_nodeCount];
+                       
+                       HashSet[] nodeSet = new HashSet[overview_nodeCount];
+                       HashSet[] edgeSet = new HashSet[overview_nodeCount];    
                
+                       
+                       Iterator it = overview_nodes.iterator();
+                       int i=0;
+                       while(it.hasNext()){
+                               CyNode node = (CyNode)it.next();
+                               overview_nodeArray[i] = node;
+                               CyNetwork subnetwork = 
(CyNetwork)node.getNestedNetwork();
+                               
+                               // build node set
+                               List subnetworkNodeList = 
subnetwork.nodesList();
+                               nodeSet[i] = new HashSet();
+                               Iterator nodeIt = subnetworkNodeList.iterator();
+                               while (nodeIt.hasNext()){
+                                       nodeSet[i].add(nodeIt.next());
+                               }
+                               
+                               //build edge set
+                               List subnetworkEdgeList = 
subnetwork.edgesList();
+                               edgeSet[i] = new HashSet();
+                               Iterator edgeIt = subnetworkEdgeList.iterator();
+                               while (edgeIt.hasNext()){
+                                       edgeSet[i].add(edgeIt.next());
+                               }
+                               
+                               i++;
+                       }
+                       
+                       //2.Build outgoing edge set for each subnetwork
+                       HashSet[] outgoing_edgeSet = new 
HashSet[overview_nodeCount];                   
+                       
+                       // build edge set for parent network
+                       //HashSet parentEdgeSet = new HashSet();
+                       Iterator parentEdgeIt = 
parentNetwork.edgesList().iterator();
+                       while (parentEdgeIt.hasNext()){
+                               //parentEdgeSet.add(parentEdgeIt.next());;
+                               CyEdge edge = (CyEdge)parentEdgeIt.next();
+                               
+                               // Check if edge is an outing edge for each 
subnetwork
+                               for (int k=0; k< overview_nodeCount; k++){
+                                       if 
(nodeSet[k].contains(edge.getSource()) && 
!nodeSet[k].contains(edge.getTarget()) ||
+                                               
(!nodeSet[k].contains(edge.getSource()) && 
nodeSet[k].contains(edge.getTarget()))){
+                                               if (outgoing_edgeSet[k] == 
null){
+                                                       outgoing_edgeSet[k] = 
new HashSet();
+                                               }
+                                               outgoing_edgeSet[k].add(edge);
+                                       }
+                               }
+                       }
+
+                       // determine if there are any edge between 
overview_node and its attribute "overlapCount"
+                       for (int m=0; m<overview_nodeArray.length; m++ ){
+                               for (int n=m+1; n< overview_nodeArray.length; 
n++){
+                                       int overlapCount = 
getEdgeSetOverlapCount(outgoing_edgeSet[m], outgoing_edgeSet[n]);
+                                       
+                                       // Create an edge if edge overlapCount 
is more than 0
+                                       if (overlapCount >0){
+                                               CyEdge newEdge 
=Cytoscape.getCyEdge(overview_nodeArray[m], overview_nodeArray[n],
+                                                               
Semantics.INTERACTION, "pp", true);
+                                               // add an attribute 
"overlapCount" for this edge
+                                               
Cytoscape.getEdgeAttributes().setAttribute(newEdge.getIdentifier(), 
"overlapCount", new Integer(overlapCount));
+                                               
+                                               overview_edgeSet.add(newEdge);
+                                       }
+                               }
+                       }
+                                               
+                       return overview_edgeSet;
+               }
+               
+               
+               //
+               private int getEdgeSetOverlapCount(HashSet edgeSetA, HashSet 
edgeSetB){
+               
+                       int overlapCount = 0;
+                       
+                       Iterator it = edgeSetA.iterator();
+                       while (it.hasNext()){
+                               CyEdge edge = (CyEdge)it.next();
+                               if (edgeSetB.contains(edge)){
+                                       overlapCount++;
+                               }
+                       }                       
+                       
+                       return overlapCount;
+               }
+               
+               
+               //
+               private CyNetwork[] createSubnetworks(CyNetwork parentNet, 
HashMap categoryMap) {
+                       CyNetwork[] subnetworks = new 
CyNetwork[categoryMap.keySet().size()];
+
+                       Iterator it = categoryMap.keySet().iterator();
+                       
+                       int i=0;
+                       while (it.hasNext()){
+                               String categoryName = it.next().toString();
+                               
+                               // 1. get node set for this subnetwork
+                               Vector nodeVect = 
(Vector)categoryMap.get(categoryName);
+                               
+                               Set nodeSet = new HashSet();
+                               for (int j = 0; j < nodeVect.size(); j++) {
+                                       CyNode oneNode = (CyNode) 
nodeVect.elementAt(j);
+                                       if (oneNode != null)
+                                               nodeSet.add(oneNode);
+                               }
+                               
+                               // 2. get edge set for this subnetwork
+                               Set edgeSet = new HashSet();
+                               Iterator iterator = parentNet.edgesIterator();
+                               while (iterator.hasNext()) {
+                                       CyEdge edge = (CyEdge) iterator.next();
+                                       if (nodeSet.contains(edge.getSource()) 
&& nodeSet.contains(edge.getTarget()))
+                                               edgeSet.add(edge);
+                               }
+
+                               // 3. Create subnetwork based on given nodeSet 
and EdgeSet
+                               subnetworks[i++] = 
Cytoscape.createNetwork(nodeSet, edgeSet, categoryName, parentNet, false);
+                       }
+                       
+                       return subnetworks;
+               }
+
+               
+               //////
+               private HashMap getNodeCategoryMap(CyNetwork net, String 
attributeName){
+                       HashMap categoryMap = new HashMap();
+                       
+                       int[] nodeIndices = net.getNodeIndicesArray();
+                       CyAttributes attributes = Cytoscape.getNodeAttributes();
+
+                       for (int i=0; i< nodeIndices.length; i++){
+                               CyNode node = (CyNode) 
Cytoscape.getRootGraph().getNode(nodeIndices[i]);
+                               String nodeId = node.getIdentifier();
+                               
+                               if (attributes.getAttribute(nodeId, 
attributeName.toLowerCase()) == null){
+                                       continue;
+                               }
+                               
+                               String attValue = 
attributes.getAttribute(nodeId, attributeName.toLowerCase()).toString();
+                               
+                               if 
(categoryMap.containsKey(attValue.toLowerCase())){
+                                       Vector nodeVect = 
(Vector)categoryMap.get(attValue.toLowerCase());
+                                       nodeVect.add(node);
+                               }
+                               else {// It is a new category
+                                       Vector nodeVect = new Vector();
+                                       nodeVect.add(node);
+                                       categoryMap.put(attValue.toLowerCase(), 
nodeVect);
+                               }
+                       }
+                       
+                       return categoryMap;
+               }
+}

Added: 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/SubnetworkByCategory.java
===================================================================
--- 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/SubnetworkByCategory.java
                            (rev 0)
+++ 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/java/org/cytoscape/subnetwork/SubnetworkByCategory.java
    2012-02-09 20:14:14 UTC (rev 28219)
@@ -0,0 +1,24 @@
+
+package org.cytoscape.subnetwork;
+
+import cytoscape.Cytoscape;
+import cytoscape.plugin.CytoscapePlugin;
+
+
+/**
+ * This class is used to instantiate your plugin. Put whatever initialization 
code
+ * you need into the no argument constructor (the only one that will be 
called).
+ * The actual functionality of your plugin can be in this class, but should 
+ * probably be separated into separted classes that get instantiated here.
+ */
+public class SubnetworkByCategory extends CytoscapePlugin {
+
+       public SubnetworkByCategory() {
+               // Properly initializes things.
+               super();
+
+               // This action represents the actual behavior of the plugin.
+               MyAction action = new MyAction();
+               Cytoscape.getDesktop().getCyMenus().addAction(action);
+       }
+}      

Added: 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/resources/plugin.props
===================================================================
--- 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/resources/plugin.props 
                            (rev 0)
+++ 
csplugins/trunk/ucsd/pwang/subnetworkByCategory/src/main/resources/plugin.props 
    2012-02-09 20:14:14 UTC (rev 28219)
@@ -0,0 +1,26 @@
+# This props file would be filled out and included in the plugin jar file.  
+# This props file will be used  to put information into the Plugin Manager 
+# about the plugin 
+
+# -- The following properties are REQUIRED -- #
+
+# The plugin name that will be displayed to users
+pluginName=MyPlugin
+
+# Description used to give users information about the plugin such as what it 
does.  
+# Html tags are encouraged for formatting purposes.
+pluginDescription=My example Plugin.
+
+# Plugin version number, this must be two numbers separated by a decimlal.  
Ex. 0.2, 14.03
+pluginVersion=1.0
+
+# Compatible Cytoscape version
+cytoscapeVersion=2.8
+
+# Category, use one of the categories listed on the website or create your own
+pluginCategory=Other
+
+# List of authors.  Note each author and institution pair are separated by a : 
(colon)
+# each additional author institution pair must be separated from other pairs 
bye a ; (semicolon)
+pluginAuthorsIntsitutions=Your Name:Your Institution
+

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