Author: clopes
Date: 2012-01-13 14:49:33 -0800 (Fri, 13 Jan 2012)
New Revision: 28017

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/task/MCODEAnalyzeTask.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
Log:
Fixed analyzeTask.cancel().  Fixed the task monitor.  Destroying the 
sub-networks that are created during the analysis and not used in the results.

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-01-13 22:31:48 UTC (rev 28016)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
   2012-01-13 22:49:33 UTC (rev 28017)
@@ -62,8 +62,8 @@
  */
 public class MCODEAlgorithm {
 
-       private boolean cancelled = false;
-       private TaskMonitor taskMonitor = null;
+       private boolean cancelled;
+       private TaskMonitor taskMonitor;
        
        private static final Logger logger = 
LoggerFactory.getLogger(MCODEAlgorithm.class);
 
@@ -228,6 +228,7 @@
                                return d2.compareTo(d1);
                        }
                };
+               
                // Will store Doubles (score) as the key, Lists of node indexes 
as values
                SortedMap<Double, List<Integer>> nodeScoreSortedMap = new 
TreeMap<Double, List<Integer>>(scoreComparator);
 
@@ -236,7 +237,7 @@
                List<Integer> al = null;
                int i = 0;
                List<CyNode> nodes = inputNetwork.getNodeList();
-
+               
                for (CyNode n : nodes) {
                        nodeInfo = calcNodeInfo(inputNetwork, n.getIndex());
                        nodeInfoHashMap.put(n.getIndex(), nodeInfo);
@@ -255,11 +256,13 @@
                        }
 
                        if (taskMonitor != null) {
-                               i++;
-                               taskMonitor.setProgress((i * 100) / (double) 
nodes.size());
+                               taskMonitor.setProgress( (++i / (double) 
nodes.size()) );
                        }
+                       
+                       if (cancelled)
+                               break;
                }
-
+               
                nodeScoreResultsMap.put(resultId, nodeScoreSortedMap);
                nodeInfoResultsMap.put(resultId, nodeInfoHashMap);
 
@@ -316,8 +319,8 @@
                long msTimeBefore = System.currentTimeMillis();
                HashMap<Integer, Boolean> nodeSeenHashMap = new 
HashMap<Integer, Boolean>(); //key is node ID
                int currentNode = -1;
-               int findingProgress = 0;
-               int findingTotal = 0;
+               double findingProgress = 0;
+               double findingTotal = 0;
                Collection<List<Integer>> values = nodeScoreSortedMap.values(); 
//returns a Collection sorted by key order (descending)
 
                // In order to track the progress without significant lags (for 
times when many nodes have the same score
@@ -378,13 +381,11 @@
                                }
 
                                if (taskMonitor != null) {
-                                       findingProgress++;
                                        // We want to be sure that only 
progress changes are reported and not
                                        // miniscule decimal increments so that 
the taskMonitor isn't overwhelmed
-                                       int newProgress = (findingProgress * 
100) / findingTotal;
-                                       int oldProgress = ((findingProgress - 
1) * 100) / findingTotal;
+                                       double newProgress = ++findingProgress 
/ findingTotal;
 
-                                       if (newProgress != oldProgress) {
+                                       if ( Math.round(newProgress * 100) != 
Math.round((newProgress - 0.01) * 100) ) {
                                                
taskMonitor.setProgress(newProgress);
                                        }
                                }
@@ -486,7 +487,7 @@
                clusterNetwork = createClusterNetwork(alCluster, inputNetwork);
                cluster.setNetwork(clusterNetwork);
                cluster.setClusterScore(scoreCluster(cluster));
-
+               
                return cluster;
        }
 
@@ -806,7 +807,7 @@
                                cluster.add(n.getIndex());
                        }
                }
-
+               
                return true;
        }
 
@@ -876,7 +877,7 @@
                boolean firstLoop = true;
                CySubNetwork outputNetwork = null;
 
-               while (true) {
+               while (true && !cancelled) {
                        int numDeleted = 0;
                        List<Integer> alCoreNodeIndices = new 
ArrayList<Integer>(inputNetwork.getNodeCount());
                        List<CyNode> nodes = inputNetwork.getNodeList();

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEAnalyzeTask.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEAnalyzeTask.java
  2012-01-13 22:31:48 UTC (rev 28016)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEAnalyzeTask.java
  2012-01-13 22:49:33 UTC (rev 28017)
@@ -107,7 +107,8 @@
 
                        // Only (re)score the graph if the scoring parameters 
have been changed
                        if (analyze == MCODEAnalyzeAction.RESCORE) {
-                               taskMonitor.setProgress(0);
+                               taskMonitor.setProgress(0.001);
+                               taskMonitor.setTitle("MCODE Analysis");
                                taskMonitor.setStatusMessage("Scoring Network 
(Step 1 of 3)");
                                alg.scoreGraph(network, resultId);
 
@@ -115,10 +116,10 @@
                                        return;
                                }
 
-                               logger.error("Network was scored in " + 
alg.getLastScoreTime() + " ms.");
+                               logger.info("Network was scored in " + 
alg.getLastScoreTime() + " ms.");
                        }
 
-                       taskMonitor.setProgress(0);
+                       taskMonitor.setProgress(0.001);
                        taskMonitor.setStatusMessage("Finding Clusters (Step 2 
of 3)");
 
                        clusters = alg.findClusters(network, resultId);
@@ -127,7 +128,7 @@
                                return;
                        }
 
-                       taskMonitor.setProgress(0);
+                       taskMonitor.setProgress(0.001);
                        taskMonitor.setStatusMessage("Drawing Results (Step 3 
of 3)");
 
                        // Also create all the images here for the clusters, 
since it can be a time consuming operation
@@ -141,13 +142,15 @@
                                }
 
                                imageList[i] = 
mcodeUtil.createClusterImage(clusters[i], imageSize, imageSize, null, true, 
null);
-                               taskMonitor.setProgress((i * 100) / (double) 
clusters.length);
+                               taskMonitor.setProgress((i+1) / (double) 
clusters.length);
                        }
 
                        success = true;
                } catch (Exception e) {
                        throw new Exception("Error while executing the MCODE 
analysis", e);
                } finally {
+                       mcodeUtil.removeUnusedSubNetworks(network, clusters);
+                       
                        if (listener != null) {
                                listener.handleEvent(new 
AnalysisCompletedEvent(success, clusters, imageList));
                        }
@@ -158,6 +161,8 @@
        public void cancel() {
                this.interrupted = true;
                alg.setCancelled(true);
+               mcodeUtil.removeNetworkResult(resultId);
+               mcodeUtil.removeNetworkAlgorithm(network.getSUID());
        }
 
        /**

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
 2012-01-13 22:31:48 UTC (rev 28016)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
 2012-01-13 22:49:33 UTC (rev 28017)
@@ -145,6 +145,8 @@
 
        private int currentResultId;
        
+       private Set<CySubNetwork> subNetworks;
+       
        private static final Logger logger = 
LoggerFactory.getLogger(MCODEUtil.class);
 
        public MCODEUtil(final RenderingEngineFactory<CyNetwork> 
renderingEngineFactory,
@@ -191,6 +193,27 @@
                currentParameters = new MCODECurrentParameters();
                networkAlgorithms = new HashMap<Long, MCODEAlgorithm>();
                networkResults = new HashMap<Long, Set<Integer>>();
+               subNetworks = new HashSet<CySubNetwork>();
+       }       
+       
+       public void removeUnusedSubNetworks(CyNetwork network, MCODECluster[] 
clusters) {
+               Set<CySubNetwork> clusterNetworks = new HashSet<CySubNetwork>();
+               
+               if (clusters != null && clusters.length > 0) {
+                       for (MCODECluster c : clusters) {
+                               clusterNetworks.add(c.getNetwork());
+                       }
+               }
+               
+               CyRootNetwork rootNet = rootNetworkMgr.getRootNetwork(network);
+               
+               for (CySubNetwork subNet : subNetworks) {
+                       if (!clusterNetworks.contains(subNet)) {
+                               rootNet.removeSubNetwork(subNet);
+                       }
+               }
+               
+               subNetworks.clear();
        }
 
        public MCODECurrentParameters getCurrentParameters() {
@@ -208,6 +231,10 @@
        public void addNetworkAlgorithm(final long suid, final MCODEAlgorithm 
alg) {
                networkAlgorithms.put(suid, alg);
        }
+       
+       public void removeNetworkAlgorithm(final long suid) {
+               networkAlgorithms.remove(suid);
+       }
 
        public boolean containsNetworkResult(final long suid) {
                return networkResults.containsKey(suid);
@@ -434,11 +461,11 @@
 
                return image;
        }
-private int subNetCount; // TODO: delete
+
        public CySubNetwork createSubNetwork(final CyNetwork net, 
Collection<CyNode> nodes) {
                final CyRootNetwork root = rootNetworkMgr.getRootNetwork(net);
                final Set<CyEdge> edges = new HashSet<CyEdge>();
-System.out.println(">> MCODE: Creating sub-network: " + (++subNetCount)); // 
TODO: delete
+
                for (CyNode n : nodes) {
                        Set<CyEdge> adjacentEdges = new 
HashSet<CyEdge>(net.getAdjacentEdgeList(n, CyEdge.Type.ANY));
 
@@ -449,9 +476,10 @@
                                }
                        }
                }
-
+System.out.println(">> MCODE: Creating sub-network..."); // TODO: delete
                final CySubNetwork subNet = root.addSubNetwork(nodes, edges);
-
+               subNetworks.add(subNet);
+System.out.println(">> MCODE: [ sub-network created! ]"); // TODO: delete
                return subNet;
        }
 
@@ -473,13 +501,6 @@
                view.updateView();
        }
 
-       public void destroyNetworkViewAndModel(CyNetworkView view) {
-               if (view != null) {
-                       networkViewMgr.destroyNetworkView(view);
-                       networkMgr.destroyNetwork(view.getModel());
-               }
-       }
-
        public void addVirtualColumns(CySubNetwork subNetwork, CyNetwork 
parent) {
                CyTable tbl = subNetwork.getDefaultNodeTable();
                CyTable parentTbl = parent.getDefaultNodeTable();
@@ -777,7 +798,7 @@
 
                return false;
        }
-
+       
        private static Properties loadProperties(String name) {
                Properties props = new Properties();
 

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