Пример #1
0
def draw_events_tree(tree, stree, gene2species, **options):
    phylo.init_dup_loss_tree(stree)
    phylo.count_dup_loss_tree(tree, stree, gene2species)
    phylo.count_ancestral_genes(stree)

    labels = options.get("labels", {})

    for node in stree:
        labels[node.name] = ""

        if node.data['dup'] > 0:
            labels[node.name] += " +%d" % node.data['dup']
        else:
            labels[node.name] += "   "

        if node.data['loss'] > 0:
            labels[node.name] += " -%d" % node.data['loss']
        else:
            labels[node.name] += "   "

        if labels[node.name] != "":
            labels[node.name] += ": "
        labels[node.name] += "%d" % node.data['genes']

    draw_tree(stree, labels=labels, **options)
Пример #2
0
def draw_events_tree(tree, stree, gene2species, **options):
    phylo.init_dup_loss_tree(stree)
    phylo.count_dup_loss_tree(tree, stree, gene2species)
    phylo.count_ancestral_genes(stree)
    
    labels = options.get("labels", {})
    
    for node in stree:
        labels[node.name] = ""

        if node.data['dup'] > 0:
            labels[node.name] += " +%d" % node.data['dup']
        else:
            labels[node.name] += "   "

        if node.data['loss'] > 0:
            labels[node.name] += " -%d" %  node.data['loss']
        else:
            labels[node.name] += "   "
        
        if labels[node.name] != "":
            labels[node.name] += ": "
        labels[node.name] += "%d" % node.data['genes']
    
    draw_tree(stree, labels=labels, **options)
def process_tree(tree, stree, gene2species):

    #==============================
    # process

    if options.hist or options.hashes:
        # count topology
        hashes.append(phylo.hash_tree(tree, gene2species))

    elif options.histsplit:
        # count splits
        for leaf in tree.leaves():
            tree.rename(leaf.name, gene2species(leaf.name))
        splits.extend(phylo.find_splits(tree))

    elif options.dump:
        # dump mode
        dump_tree(tree)

    elif options.events:
        # add event labels
        assert stree is not None and gene2species is not None
        phylo.count_dup_loss_tree(tree, stree, gene2species)

    else:
        # default mode: display tree
        display_tree(tree, options, gene2species=gene2species, stree=stree)
Пример #4
0
def process_tree(tree, stree, gene2species):

    #==============================
    # process

    if options.hist or options.hashes:
        # count topology
        hashes.append(phylo.hash_tree(tree, gene2species))

    elif options.histsplit:
        # count splits
        for leaf in tree.leaves():
            tree.rename(leaf.name, gene2species(leaf.name))
        splits.extend(phylo.find_splits(tree))

    elif options.dump:
        # dump mode
        dump_tree(tree)

    elif options.events:
        # add event labels
        assert stree is not None and gene2species is not None
        phylo.count_dup_loss_tree(tree, stree, gene2species)

    else:
        # default mode: display tree
        display_tree(tree, options, gene2species=gene2species, stree=stree)
Пример #5
0
def count_dup_loss_coal_tree(coal_tree, extra, stree, gene2species,
                             implied=True, locus_mpr=True):
    """count dup loss coal"""

    if not locus_mpr:
        raise Exception("not implemented")

    # TODO: use locus_recon and locus_events rather than MPR
    #       (currently, phylo.py reconciliation functions fail for non-MPR)
    locus_tree = extra["locus_tree"]
    locus_recon = phylo.reconcile(locus_tree, stree, gene2species)
    locus_events = phylo.label_events(locus_tree, locus_recon)
    coal_recon = extra["coal_recon"]

    ndup, nloss, nappear = phylo.count_dup_loss_tree(locus_tree, stree, gene2species,
                                                     locus_recon, locus_events)

    # add implied speciation nodes if desired
    # this must be added AFTER counting dups and losses since it affects loss inference
    if implied:
        added = phylo.add_implied_spec_nodes(locus_tree, stree, locus_recon, locus_events)

    # count coals
    ncoal = 0
    counts = coal.count_lineages_per_branch(coal_tree, coal_recon, locus_tree)
    for lnode, (count_bot, count_top) in counts.iteritems():
        n = max(count_top-1, 0)
        locus_recon[lnode].data['coal'] += n
        ncoal += n

    if implied:
        phylo.remove_implied_spec_nodes(locus_tree, added, locus_recon, locus_events)

    return ndup, nloss, ncoal, nappear
Пример #6
0
def count_dup_loss_coal_tree(coal_tree,
                             extra,
                             stree,
                             gene2species,
                             implied=True,
                             locus_mpr=True):
    """count dup loss coal"""

    if not locus_mpr:
        raise Exception("not implemented")

    # TODO: use locus_recon and locus_events rather than MPR
    #       (currently, phylo.py reconciliation functions fail for non-MPR)
    locus_tree = extra["locus_tree"]
    locus_recon = phylo.reconcile(locus_tree, stree, gene2species)
    locus_events = phylo.label_events(locus_tree, locus_recon)
    coal_recon = extra["coal_recon"]

    ndup, nloss, nappear = phylo.count_dup_loss_tree(locus_tree, stree,
                                                     gene2species, locus_recon,
                                                     locus_events)

    # add implied speciation nodes if desired
    # this must be added AFTER counting dups and losses since it affects loss inference
    if implied:
        added = phylo.add_implied_spec_nodes(locus_tree, stree, locus_recon,
                                             locus_events)

    # count coals
    ncoal = 0
    counts = coal.count_lineages_per_branch(coal_tree, coal_recon, locus_tree)
    for lnode, (count_bot, count_top) in counts.iteritems():
        n = max(count_top - 1, 0)
        locus_recon[lnode].data['coal'] += n
        ncoal += n

    if implied:
        phylo.remove_implied_spec_nodes(locus_tree, added, locus_recon,
                                        locus_events)

    return ndup, nloss, ncoal, nappear