Beispiel #1
0
    plt.plot(t,
             t * ebola.date2dist.clock_rate + ebola.date2dist.intercept,
             label="y = %1.5f t%1.3f" %
             (ebola.date2dist.clock_rate, ebola.date2dist.intercept))
    plt.legend(loc=2)

    # rescale branch length to years and plot in axis 0
    from treetime.treetime import plot_vs_years
    fig, axs = plt.subplots(2,
                            1,
                            sharex=True,
                            figsize=(onecolumn_figsize[0],
                                     onecolumn_figsize[1] * 1.7))
    plot_vs_years(ebola,
                  years=.5,
                  ax=axs[0],
                  confidence=(0.05, 0.95),
                  ticks=False,
                  label_func=lambda x: "")
    #    axs[0].tick_params(labelsize=tick_fs)
    #    axs[0].set_axis_off()

    # reset branch length to time (in substitution rate units)
    for n in ebola.tree.find_clades():
        if n.up:
            n.branch_length = n.clock_length

    axs[1].fill_between(skyline.x - ebola.tree.root.numdate,
                        confidence[0],
                        confidence[1],
                        color=(0.8, 0.8, 0.8))
    axs[1].plot(skyline.x - ebola.tree.root.numdate,
Beispiel #2
0
        print("inferred skyline assuming 50 generations per year:")
        for (x,y) in zip(skyline.x, skyline.y):
            print("%1.3f\t%1.3f"%(x,y))


    base_name = '.'.join(params.aln.split('/')[-1].split('.')[:-1])
    # plot
    if params.plot:
        from treetime.treetime import plot_vs_years
        import matplotlib.pyplot as plt
        plt.ion()
        leaf_count = myTree.tree.count_terminals()
        label_func = lambda x: x.name[:20] if (leaf_count<30 & x.is_terminal()) else ''
        branch_label_func = lambda x: (','.join([a+str(pos)+d for a,pos, d in x.mutations[:10]])
                                       +('...' if  len(x.mutations)>10 else '')) if leaf_count<30 else ''
        plot_vs_years(myTree, show_confidence=False, label_func = label_func) #, branch_labels=branch_label_func)
        plt.savefig(base_name+'_tree.pdf')
        print("--- saved tree as pdf in \n\t %s\n"%(base_name+'_tree.pdf'))
    else:
        # convert branch length to years (this is implicit in the above plot)
        myTree.branch_length_to_years()

    # decorate tree with inferred mutations
    outaln_name = base_name+'_ancestral.fasta'
    AlignIO.write(myTree.get_reconstructed_alignment(), outaln_name, 'fasta')
    print("--- alignment including ancestral nodes saved as  \n\t %s\n"%outaln_name)

    terminal_count = 0
    for n in myTree.tree.find_clades():
        if n.up is None:
            continue
Beispiel #3
0
                    time_marginal="assign",
                    vary_rate=True)

    if res == ttconf.ERROR:
        sys.exit()

    # scatter root to tip divergence vs sampling date
    ebola.plot_root_to_tip(add_internal=True)
    plt.legend(loc=2)

    # rescale branch length to years and plot in axis 0
    from treetime.treetime import plot_vs_years
    fig, axs = plt.subplots(1, 2, sharey=True, figsize=(12, 8))
    plot_vs_years(ebola,
                  step=1,
                  ax=axs[1],
                  confidence=(0.05, 0.95),
                  label_func=lambda x: "")
    axs[1].set_xlim(0, 2.5)
    axs[1].set_title("time tree")

    # assign mutation length to branch length and plot the mutation tree in axs[1]
    axs[0].set_title("mutation tree")
    for n in ebola.tree.find_clades():
        n.branch_length = n.mutation_length
    Phylo.draw(ebola.tree, label_func=lambda x: "", axes=axs[0])
    plt.tight_layout()

    # reset branch length to time (in substitution rate units)
    for n in ebola.tree.find_clades():
        n.branch_length = n.clock_length
    # rerooting can be done along with the tree time inference
    tt.run(root="best", branch_length_mode='input')
    # if more complicated models (relaxed clocks, coalescent models) are to be used
    # or you want to resolve polytomies, treetime needs to be run for
    # several iterations, for example as
    # tt.run(root="best", resolve_polytomies=True, max_iter=2)

    # each node is now at a position that correspond to the given or inferred date
    # the units of branch length are still clock rate.
    print("clock rate: %1.5f" % tt.date2dist.clock_rate)
    fig, axs = plt.subplots(1, 2, figsize=(18, 9))
    Phylo.draw(tt.tree,
               label_func=lambda x: '',
               show_confidence=False,
               axes=axs[0])
    axs[0].set_title("Tree: units are substitutions", fontsize=18)
    # we can convert the branch length to units in years and redraw
    tt.branch_length_to_years()
    Phylo.draw(tt.tree,
               label_func=lambda x: '',
               show_confidence=False,
               axes=axs[1])
    axs[1].set_title("Tree: units are years", fontsize=18)
    axs[0].tick_params(labelsize=14)
    axs[1].tick_params(labelsize=14)
    fig.tight_layout()

    # treetime implements a convenience function to plot timetrees
    from treetime.treetime import plot_vs_years
    plot_vs_years(tt, label_func=lambda x: "", show_confidence=False)