Marko Toplak avatar Marko Toplak committed efe3081

OWHeatMap: fixed progress bars.

Comments (0)

Files changed (1)

_bioinformatics/widgets/OWHeatMap.py

     def __init__(self, parts=None, progress_callback=None):
         self.progress_callback = progress_callback
         self.parts = parts
-        self.part = 0
+        self.part = -1
 
     def __call__(self, value):
         return self.progress_callback(value / self.parts + 100.0 * self.part / self.parts)
 
-    def newpart(self):
-        self.part += 1
+    def newpart(self, k=1):
+        self.part += k
         self.__call__(0)
  
 
     data_ordering = []
     data_clusters = []
     for i, indices in enumerate(class_data):
+        pp_callback.newpart()
         sub_data = data.select(indices)
-        pp_callback.newpart()
         cluster = orngClustering.hierarchicalClustering(sub_data, order=opt_order, progressCallback=pp_callback)
         ind_map = indices_map(indices)
         data_ordering.append([ind_map[m] for m in cluster.mapping])
         self.progressBarInit()
 
         progress_parts = 0
-        if self.SortExamples > 1:
+
+        args_key_examples = tuple(tuple(d) for d in group_domains), self.SortExamples == 3, "data"
+        args_key_attributes = tuple(tuple(d) for d in group_domains), self.SortAttributes == 2, "attributes"
+
+        if self.SortExamples > 1 and args_key_examples not in self._ordering_cache:
             classVar = data.domain.class_var
             if classVar and isinstance(classVar, orange.EnumVariable):
                 progress_parts += len(classVar.values)
             else:
                 progress_parts += 1
-        if self.SortAttributes > 0:
+
+        if self.SortAttributes > 0 and args_key_attributes not in self._ordering_cache:
             progress_parts += 1
 
         progress_bar = PP_callback(progress_callback=self.progressBarSet, parts=progress_parts)
         # rows
         if self.SortExamples > 1:
 
-            args_key = tuple(tuple(d) for d in group_domains), self.SortExamples == 3, "data"
-            cluster_ordering = self._ordering_cache.get(args_key, None)
+            cluster_ordering = self._ordering_cache.get(args_key_examples, None)
             if cluster_ordering is None:
 
                 # Rows separately
                                       pp_callback=progress_bar)
 
                 # Cache the clusters
-                self._ordering_cache[args_key] = (data_ordering, data_clusters)
+                self._ordering_cache[args_key_examples] = (data_ordering, data_clusters)
             else:
-                 data_ordering, data_clusters = cluster_ordering
+                data_ordering, data_clusters = cluster_ordering
             
             sorted_data = [data[i] for i in itertools.chain(*data_ordering)]
         
         # columns
         if self.SortAttributes > 0:
 
-            args_key = tuple(tuple(d) for d in group_domains), self.SortAttributes == 2, "attributes"
-            cluster_ordering = self._ordering_cache.get(args_key, None)
+            cluster_ordering = self._ordering_cache.get(args_key_attributes, None)
             if cluster_ordering is None:
 
                 # Columns separately
                                       pp_callback=progress_bar)
 
                 # Cache the clusters
-                self._ordering_cache[args_key] = (attr_ordering, attr_cluster)
+                self._ordering_cache[args_key_attributes] = (attr_ordering, attr_cluster)
             else:
-                 attr_ordering, attr_cluster = cluster_ordering
- 
+                attr_ordering, attr_cluster = cluster_ordering
+
         self.progressBarFinished()
 
         self.heatmapconstructor = []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.