Changeset 1918:0e7a2add2967 in orange-bioinformatics


Ignore:
Timestamp:
11/26/13 19:07:20 (5 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Fixed a UnicodeDecodeError when sorting a mixed str/unicode list.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orangecontrib/bio/widgets/OWSetEnrichment.py

    r1899 r1918  
    66 
    77import math 
     8import operator 
    89from collections import defaultdict 
    910 
     
    3435fmtp = lambda score: "%0.5f" % score if score > 10e-4 else "%0.1e" % score 
    3536fmtpdet = lambda score: "%0.9f" % score if score > 10e-4 else "%0.5e" % score 
     37 
     38 
     39def as_unicode(string): 
     40    if isinstance(string, str): 
     41        return string.decode("utf-8", errors="ignore") 
     42    else: 
     43        return string 
     44 
     45# A translation table mapping punctuation, ... to spaces 
     46_TR_TABLE = dict((ord(c), ord(" ")) for c in ".,!?()[]{}:;'\"<>") 
     47 
     48def word_split(string): 
     49    """ 
     50    Split a string into a list of words. 
     51    """ 
     52    return as_unicode(string).translate(_TR_TABLE).split() 
     53 
    3654 
    3755def _toPyObject(variant): 
     
    508526            self.warning(0) 
    509527 
    510         replace = lambda s:s.replace(",", " ").replace("(", " ").replace(")", " ") 
    511         self._completerModel = completerModel = QStringListModel(sorted(reduce(set.union, [[gsname(geneset)] + replace(gsname(geneset)).split() for geneset, (c, _, _, _) in results if c], set()))) 
    512         self.filterCompleter.setModel(completerModel) 
     528        allnames = set(as_unicode(gsname(geneset)) 
     529                       for geneset, (count, _, _, _) in results if count) 
     530 
     531        allnames |= reduce(operator.ior, 
     532                           (set(word_split(name)) for name in allnames), 
     533                           set()) 
     534 
     535        self.completerModel = QStringListModel(sorted(allnames)) 
     536        self.filterCompleter.setModel(self.completerModel) 
    513537 
    514538        self.annotationsChartView.setItemDelegateForColumn(6, BarItemDelegate(self, scale=(0.0, max(t[1][3] for t in results)))) 
Note: See TracChangeset for help on using the changeset viewer.