示例#1
0
def save_node_data(t, d, node_dict, debug=False):
    # join items like (('A','B'),'C') into 'ABC'
    left = ''.join(utils.list_elements(t[0]))
    right =  ''.join(utils.list_elements(t[1]))
    new_node = ''.join(utils.list_elements(left+right))
    d *= 0.5
    node_dict[new_node] = { 'left':left, 'right':right, 'to_tips':d }
    if debug:
        print 'new node:'
        print new_node, node_dict[new_node]
    for i,child_node in enumerate([left,right]):
        if not child_node in node_dict:
            node_dict[child_node] =  {'parent':new_node, 'up':d }
        else:
            up_d = d - node_dict[child_node]['to_tips']
            node_dict[child_node].update({ 'parent':new_node, 'up':up_d} )
        if debug:
            print ['left node:','right_node:'][i]
            print child_node, node_dict[child_node]
示例#2
0
def average_distance(t, D, debug=False):
    if debug:
        print "average_distance",
        print t
    dL = list()
    t0 = utils.list_elements(t[0])
    t1 = utils.list_elements(t[1])
    if debug:
        print t0, t1,
    for u in t0:
        for v in t1:
            d = D[(u, v)]
            if debug:
                print u+v, d,
            dL.append(d)
    average = sum(dL)*1.0/len(dL)
    if debug:
        print 'avg =', average
    return average
def save_node_data(t,d,node_dict,debug=False):
    # join items like (('A','B'),'C') into 'ABC'
    left = ''.join(utils.list_elements(t[0]))
    right =  ''.join(utils.list_elements(t[1]))
    new_node = ''.join(utils.list_elements(left+right))
    d *= 0.5
    node_dict[new_node] = { 'left':left, 'right':right, 'to_tips':d }
    if debug:
        print 'new node:'
        print new_node, node_dict[new_node]
    for i,child_node in enumerate([left,right]):
        if not child_node in node_dict:
            node_dict[child_node] =  {'parent':new_node, 'up':d }
        else:
            up_d = d - node_dict[child_node]['to_tips']
            node_dict[child_node].update({ 'parent':new_node, 'up':up_d} )
        if debug:
            print ['left node:','right_node:'][i]
            print child_node, node_dict[child_node]
def average_distance(t,D,debug=False):
    if debug:
        print 'average_distance',
        print t
    dL = list()
    t0 = utils.list_elements(t[0])
    t1 = utils.list_elements(t[1])
    if debug:
        print t0, t1,
    for u in t0:
        for v in t1:
            d = D[(u,v)]
            if debug:
                print u+v, d,
            dL.append(d)
    average = sum(dL)*1.0/len(dL)
    if debug:
        print 'avg =', average
    return average
示例#5
0
def collapse(L, node_in, debug=False):
    node = ''.join(utils.list_elements(node_in))
    if debug:
        print 'node', node
        print 'L'
        node, utils.print_list(L, n=4)
    rL = list()
    for item in L:
        left,right = item
        if debug:
            print 'left', left, 'right', right
        for tip in left:
            if tip in node:
                left = node
        for tip in right:
            if tip in node:
                right = node
        if not left == right:
            rL.append((left,right))
    rL = sorted(list(set(rL)))
    if debug:
        print 'rL after set:'
        utils.print_list(rL)
    return rL
def collapse(L,node_in,debug=False):
    node = ''.join(utils.list_elements(node_in))
    if debug:
        print 'node', node
        print 'L'
        node, utils.print_list(L, n=4)
    rL = list()
    for item in L:
        left,right = item
        if debug:
            print 'left', left, 'right', right
        for tip in left:
            if tip in node:
                left = node
        for tip in right:
            if tip in node:
                right = node
        if not left == right:
            rL.append((left,right))
    rL = sorted(list(set(rL)))
    if debug:
        print 'rL after set:'
        utils.print_list(rL)
    return rL
示例#7
0
    ct = colors.color_names
    if ct.has_key(color):
        color = ct[color]
    for k,v in table.iteritems():
        if ct.has_key(k):
            table[ct[k]] = v;
    for k,v in table.iteritems():
        if ct.has_key(v):
            table[k] = ct[v];

            
    
    svg_in = svgparser.parse(sys.stdin)
    
    elts = utils.list_elements(svg_in)
    if dofill:
        for e in elts:
            if not 'get_fill' in dir(e): continue;
            if not colorall and not e.get_fill():
                continue
            
            if table.has_key(e.get_fill()):
                e.set_fill(table[e.get_fill()])
            else:
                e.set_fill(color)
    if dolines:
        for e in elts:
            if not 'get_color' in dir(e): continue;
            if (not colorall ) and ( not e.get_color()):
                continue
示例#8
0
        table = dict([[e.strip() for e in re.split(re.compile('\s+'), l)]
                      for l in fopen.readlines()])

    ct = colors.color_names
    if ct.has_key(color):
        color = ct[color]
    for k, v in table.iteritems():
        if ct.has_key(k):
            table[ct[k]] = v
    for k, v in table.iteritems():
        if ct.has_key(v):
            table[k] = ct[v]

    svg_in = svgparser.parse(sys.stdin)

    elts = utils.list_elements(svg_in)
    if dofill:
        for e in elts:
            if not 'get_fill' in dir(e): continue
            if not colorall and not e.get_fill():
                continue

            if table.has_key(e.get_fill()):
                e.set_fill(table[e.get_fill()])
            else:
                e.set_fill(color)
    if dolines:
        for e in elts:
            if not 'get_color' in dir(e): continue
            if (not colorall) and (not e.get_color()):
                continue