Пример #1
0
    def __init__(self, mat=None, on_click=None, 
                 bgcolor=(0,0,0), drawzeros=False, style="points",
                 show_labels=False, show_label_windows=False,
                 winsize=(400,400), title="summatrix",
                 rtree=None, ctree=None,
                 use_tree_lens=(False, False),
                 show_tree_windows=None):
        self.win = None
        self.mat = mat
        self.bgcolor = bgcolor
        self.drawzeros = drawzeros
        self.style = style
        self.winsize = winsize[:]
        self.title = title
        self.part_lines = None
        self.part_lines_visible = True
        self.first_open = True
        if on_click != None:
            self.on_click = on_click

        # labels
        self.show_labels = show_labels
        self.show_label_windows = show_label_windows        
        self.label_windows = [None, None]

        # trees
        if show_tree_windows != False and (rtree != None or ctree != None):
            self.show_tree_windows = True
        else:
            self.show_tree_windows = False
        self.tree_windows = [None, None]
        self.rtree = rtree
        self.ctree = ctree
        self.use_tree_lens = use_tree_lens

        # setup perm based on trees
        if self.rtree:
            leaves = self.rtree.leaf_names()
            if self.mat.rowlabels == None:
                self.mat.rperm = map(int, leaves)
            else:
                lookup = util.list2lookup(self.mat.rowlabels)
                self.mat.rperm = util.mget(lookup, leaves)

        if self.ctree:
            leaves = self.ctree.leaf_names()
            if self.mat.collabels == None:
                self.mat.cperm = map(int, leaves)
            else:
                lookup = util.list2lookup(self.mat.collabels)
                self.mat.cperm = util.mget(lookup, leaves)

            
        # set inverse permutations
        self.mat.rinv = util.invperm(self.mat.rperm)
        self.mat.cinv = util.invperm(self.mat.cperm)
Пример #2
0
    def submatrix(self, rows=None, cols=None):
        """Returns a submatrix"""
        
        mat = Matrix()
        
        if rows == None:
            rows = range(mat.nrows)
        
        if cols == None:
            cols = range(mat.ncols)
                
        lookuprows = util.list2lookup(rows)
        lookupcols = util.list2lookup(cols)
        
        # get subset of data
        rows2, cols2, vals2 = self.rows, self.cols, self.vals
        rows3, cols3, vals3 = mat.rows, mat.cols, mat.vals
                
        for i in xrange(len(rows2)):            
            r = rows2[i]
            c = cols2[i]
            v = vals2[i]
            
            if r not in lookuprows or c not in lookupcols:
                continue

            r2 = lookuprows[r]
            c2 = lookupcols[r]
            rows3.append(r2)
            cols3.append(c2)
            vals3.append(v)
            mat[r2][c2] = v
        
        # get subset of permutation        
        ind = [self.rinv[i] for i in rows]
        lookup = util.list2lookup(util.sort(ind))
        mat.rinv = util.mget(lookup, ind)
        mat.rperm = util.invperm(mat.rinv)
        
        ind = [self.cinv[i] for i in cols]
        lookup = util.list2lookup(util.sort(ind))
        mat.cinv = util.mget(lookup, ind)
        mat.cperm = util.invperm(mat.cinv)
        
        # get subset of partition
        if mat.rpart != None:
            mat.rpart = util.mget(self.rpart, rows)
        if mat.cpart != None:
            mat.cpart = util.mget(self.cpart, cols)
        
        mat.setup(len(rows), len(cols), len(rows3))
        return mat