Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    hattiechung
    @hattiechung
    A follow-up question -- the use_edge_lengths=True option seems to work for a single tree, but not for the consensus tree (I apologize if I missed something in the doc that I should have seen). Below is the tree as a "single" vs "consensus." I still can't seem to get rid of the extra tick mark for each tip. Thank you in advance! My code is here:
    multitrees = toytree.multitree(newickfile)
    consensustree = multitrees.get_consensus_tree()
    treeh = toytree.tree(consensustree.newick, format=0)
    figout, axes = treeh.draw(
    orient='right',
    width=400, height=500,
    use_edge_lengths=True,
    tip_labels_align=True,
    tip_labels_color=tipcolors,
    tip_labels=True,
    tip_labels_style={
    "font-size":"7px",
    "-toyplot-anchor-shift": "25px"
    },
    node_labels=treeh.get_node_values("support"),
    node_style={
    "stroke": "black",
    "stroke-width":1
    },
    node_labels_style={
    "baseline-shift": "5px",
    "-toyplot-anchor-shift": "-5px",
    "font-size": "10px"}
    )
    single_vs_consensus_tree copy.pdf
    Deren Eaton
    @dereneaton
    @hattiechung Oh I see. The get_consensus_tree() function is not very sophisticated yet. It only calculates a consensus of topologies and stores bootstrap support values, but it does not summarize branch lengths across trees. And so it just sets all of the branch lengths to 1 on the consensus tree. To get a consensus tree with mean branch lengths you may need to use some other software for now. I might recommend sumtrees (https://pythonhosted.org/DendroPy/programs/sumtrees.html#set-node-ages-of-target-or-summary-tree-s-to-mean-median-node-age-of-input-trees)
    hattiechung
    @hattiechung
    Oh great, I'll try that! Thank you!
    leclearnm
    @leclearnm
    Hi @dereneaton
    I am super stoked to get more experience playing with toyplot. This may not be the correct forum for this, but right now I am trying to use the rendering functions from toyplot to save the lovely plots generated from the baba objects in your baba.py code. For example, with a baba object called 'fw85m4'
    import toyplot.pdf
    
    plot1 = fw85m4.plot(height=850, width=700, pct_tree_y=0.0005, pct_tree_x=0.5, alpha=4.0);
    
    plot1
    (<toyplot.canvas.Canvas at 0x7f6bbe911bd0>,
     <toyplot.coordinates.Cartesian at 0x7f6bbe911ed0>,
     <ipyrad.plotting.baba_panel_plot.Panel at 0x7f6bbf0dcd90>)
    
    toyplot.pdf.render(plot1, "plot1.pdf")
    ValueError                                Traceback (most recent call last)
    <ipython-input-61-e11dc1c612b1> in <module>()
    ----> 1 toyplot.pdf.render(plot1, "plot1.pdf")
    
    /home/nathan/miniconda2/lib/python2.7/site-packages/toyplot/pdf.pyc in render(canvas, fobj, width, height, scale)
         55     :func:`toyplot.reportlab.pdf.render()`.
         56     """
    ---> 57     canvas = toyplot.require.instance(canvas, toyplot.canvas.Canvas)
         58     return implementation.render(canvas, fobj, width, height, scale)
    
    /home/nathan/miniconda2/lib/python2.7/site-packages/toyplot/require.pyc in instance(value, types)
        100     """Verify the type of a value."""
        101     if not isinstance(value, types):
    --> 102         raise ValueError("Expected %s, received %s." % (types, type(value))) # pragma: no cover
        103     return value
        104 
    
    ValueError: Expected <class 'toyplot.canvas.Canvas'>, received <type 'tuple'>.
    Eaton Lab
    @eaton-lab
    Hi @leclearnm, the plot() function returns three objects, as you can see when you called the plot1 variable. The three objects are returned together as a tuple object, which is just a type of container. When you use the toyplot.pdf.render function you'll want to pass it just the first object in your tuple, which is the toyplot.Canvas object. Let me know if that works.
    ## example
    plot1 = bb.plot(...)
    toyplot.render.pdf(plot1[0], "plot1.pdf")
    leclearnm
    @leclearnm
    @dereneaton , worked perfectly. Thanks
    hattiechung
    @hattiechung
    Hi @eaton-lab, I'm making some figures for a paper via toytree. Is there a way to make only the terminal nodes (i.e. leaves) different colored circles depending on the name of the leaf, and not label the internal nodes with the circle? The examples only show cases where all nodes are shown with a circle, including internal ones. Thank you in advance! The trees are otherwise looking good :)
    Eaton Lab
    @eaton-lab
    @hattiechung There are two ways to do this. It might be easiest to plot circles at the tips using a scatterplot on the same canvas, as opposed to using node labels, but it can be done with node labels too. I'll show both.
    To use node labels this is easiest by accessing information from the .get_node_dict function.
    tree = toytree.rtree(6)
    
    ## set node labels to "" if you want to disappear
    nls = ["" if node not in tree.get_tip_labels() else node 
           for node in tree.get_node_dict().values()]
    
    ## set color based on tip name
    ncs = [tree.colors[1] if node in "t-1" else tree.colors[0]
           for node in tree.get_node_dict().values()]
    
    ## draw tree
    tree.draw(
        use_edge_lengths=False,
        node_labels=nls,
        node_color=ncs,  
        tip_labels=False,
    );
    image.png
    Whereas alternatively you can use a scatterplot to add markers at the tips:
    ## make list of node colors (reversed b/c in order from bottom to top)
    cols= [tree.colors[0] if tipname == "t-1" else tree.colors[1]
           for tipname in tree.get_tip_labels()][::-1]
    
    ## draw tree and return canvas and cartesian axes
    c, a = tree.draw(use_edge_lengths=False)
    a.scatterplot(a=[2]*6, b=range(6), size=12, color=cols);
    image.png
    The latter uses the cartesian coordinates of the canvas to add points. The tree tips align at x=0 and are each 1 unit apart on the y-axis. So we can add points by putting them all at the same x coordinate and at increasing y coordinates. Much of this needs to be added to the docs still.
    hattiechung
    @hattiechung
    ah fantastic, thank you so much @eaton-lab !!
    Bede Constantinides
    @bede
    What a cool package! Would you mind explaining the rationale behind not putting toytree on PyPI as well as Conda?
    Eaton Lab
    @eaton-lab
    I'd love to put it on PyPI, and definitely could use some extra hands if you want to help out!
    Eaton Lab
    @eaton-lab
    @/all toytree has undergone some major updates, as have the docs (https://toytree.rtfd.io), and the latest version is now on pip and conda.
    joqb
    @joqb

    @eaton-lab Hi I am having troubles with the generate_tests_from_tree
    rtre.draw(); outputs a tree but
    bb = ipa.baba(data=locifile, newick=rtre) followed by bb.generate_tests_from_tree() returns

    /home/dumortier/miniconda2/lib/python2.7/site-packages/ipyrad/analysis/baba.pyc in __init__(self, data, tests, newick, nboots, mincov)
         85 
         86         if isinstance(newick, toytree.tree):
    ---> 87             self.newick = newick.tree.write()
         88         else:
         89             self.newick = newick
    
    AttributeError: Toytree instance has no attribute 'tree'

    with ipyrad 0.7.19 but the error is similar with 0.7.28 (AttributeError: Toytree instance has no attribute 'tree' with more verbose).
    Any idea what could be the problem?

    PS: I know the generate_tests_from_tree is within ipyrad so sorry if this is not the place...

    Eaton Lab
    @eaton-lab
    @joqb this is a problem caused by developing these two packages separately. I'm still working on updating the ipyrad analysis tools to work with the latest toytree. Until then, you will need to downgrade your toytree version back to version 0.1.6. I hope to have both running compatible versions within about 2 weeks.
    joqb
    @joqb

    @eaton-lab Thanks for the quick reply!
    I tried to downgrade but I got an other error

    NameError                                 Traceback (most recent call last)
    <ipython-input-4-490fab463969> in <module>()
         33 tre = toytree.tree(newick=newick)
         34 myWildcardRoot = "Cal_1525"
    ---> 35 rtre=tre.root(wildcard=myWildcardRoot)
         36 nwk=rtre.draw();
    
    /home/dumortier/miniconda2/lib/python2.7/site-packages/toytree-0.1.6-py2.7.egg/toytree/tree.py in root(self, outgroup, wildcard, regex)
        422 
        423         ## split root node if more than di- as this is the unrooted state
    --> 424         if not nself.is_bifurcating():
        425             nself.tree.resolve_polytomy()
        426 
    
    /home/dumortier/miniconda2/lib/python2.7/site-packages/toytree-0.1.6-py2.7.egg/toytree/tree.py in is_bifurcating(self, include_root)
        301         ctn2 = -2 + (2 * len(self))
        302         if self.is_rooted():
    --> 303             if ctn == sum(1 for i in self.tree.traverse()):
        304                 return True
        305             else:
    
    NameError: global name 'ctn' is not defined

    ipyrad version: 0.7.28
    toyplot version: 0.17.0
    toytree version: 0.1.6
    CPUs used: 20

    What versions should I use?

    Eaton Lab
    @eaton-lab
    @joqb hmm, you seem to be stuck in a version limbo: the old version has a bug so it can't do what you want, and the latest version isn't compatible yet with the baba code in ipyrad. I'm doing my best to resolve it.
    joqb
    @joqb
    @eaton-lab OK I'll be patient then...
    mcfaddenlab
    @mcfaddenlab
    hey @eaton-lab having problems with toytree and the abba-baba cookbook. everything was working smoothly, and then i tried to upgrade to toytree 1.18 to prune tips. realizing i needed to use the 1.6 version for ipyrad abba-baba analyses, i downgraded my toytree to 1.6 and now it will not work! any advice? i also tried to update my path but that does not seem to work either...
    mcfaddenlab
    @mcfaddenlab
    ok...note above, it works again. i just had to restart everything...rookie mistake.
    Chris Owen
    @chris-owen
    toytree_error1.JPG
    @eaton-lab I was working a tree figure, but I ran into some errors. I decided to double-check the errors with the examples in your Quick Guide, but I am still getting an error. I took a screen shot and placed it above. If it matters, I installed toytree with conda. Thanks in advance for your help!
    Eaton Lab
    @eaton-lab
    Hi @chris-owen, Thanks, I'll look into it. I think that I didn't upload the Windows version correctly to conda, since it's working elsewhere on Linux and OSX (e.g., https://toytree.readthedocs.io/en/latest/2-try-it.html). It should be a simple fix.
    Chris Owen
    @chris-owen
    Hi @eaton-lab. Thanks for looking into this, I appreciate it!
    Eaton Lab
    @eaton-lab
    @chris-owen I just uploaded a new windows version 0.1.19, please let me know if it fixes your problem. Thanks.
    Chris Owen
    @chris-owen
    Hi @eaton-lab. I just tried to install v0.1.19 with conda, but it didn't work. I confirmed that conda can see it using the command conda search toytree. Then, when I try to install toytree, conda can not find it. I also did a fresh install of Anaconda and that didn't resolve the install issue. I did a little digging and came across conda/conda#7245 and identifies the same problem. Let me know if you would like any more information and thanks again for your time.
    toytree_failed_install.JPG
    tle003
    @tle003
    Thanks for dealing with the 'setattr' issue that was causing problems in toytree v. 0.1.16. I installed toytree v. 0.1.21 yesterday and I managed to plot the preliminary phylogenies that I had earlier wanted to make.
    Chris Owen
    @chris-owen
    Hi @eaton-lab. Is there a way to ladderize the phylogeny with the branch lengths ascending? It looks like the ladderize function comes from the ete3mini.py and is the same from ete3 toolkit. If that is the case, .ladderize(direction=1) should do the trick; however, when I use it I get an unexpected keyword argument for 'direction'. Any suggestions? Thanks in advance for your help!
    Eaton Lab
    @eaton-lab
    @chris-owen , oh, I didn't implement the direction argument yet, but it should be very easy to do. Yes, toytree calls the ete3 ladderize function under the hood, but instead of changing the tree in-place it returns a copy. I think you can hack around it for right now by doing the following. I'll add the direction arg soon to fix this:
    # ladderize treenode (ete) object
    tre.treenode.ladderize(direction=1)
    
    # update toytree drawing coordinates for new treenode 
    tre._coords.update()
    Chris Owen
    @chris-owen
    @eaton-lab ; it worked, thanks!
    Chris Owen
    @chris-owen
    Hi @eaton-lab . Instead of coloring branches or putting dots near terminals, is it possible to color the background of clades with ToyTree? An example of what I am talking about is located here. I have tried with no success using functions from ToyPlot. If it is possible, can you provide a quick example using the Cyathophora.tre from the Quick Guide examples? Thanks in advance for you time!
    Chris Owen
    @chris-owen
    @eaton-lab Perfect, thanks!
    tle003
    @tle003
    Is the collapse_nodes function available with Toytree ver. 0.1.22? I am trying to get it to work with the following rxtremin50 = rxtre.collapse_nodes(min_support=50), but it is not working. I have also been trying to get ver. 0.1.22 to inport, but instead I am getting Toytree ver. 0.1.21, even though I have tried to uninstall the older version. In addition, when I look through my installed packages, the new version (0.1.22) is listed, but not the older version.__requires__ = ["Toytree==0.1.22"] import pkg_resources import toytree pkg_resources.get_distribution("Toytree").version 0.1.21
    joqb
    @joqb

    Hi @eaton-lab,
    we are having troubles with running tetrad. First it told us to install toytree which we did but to my surprise this had some dramatic impact on the rest of the conda environment (i.e. ipyrad-0.6.18-0):

    conda install toytree -c eaton-lab
    Collecting package metadata: done
    Solving environment: done
    
    ## Package Plan ##
    
      environment location: /home/ghanavati/miniconda2
    
      added / updated specs:
        - toytree
    
    
    The following packages will be UPDATED:
    
      cryptography                         2.3.1-py27hc365091_0 --> 2.6.1-py27h1ba5d50_0
      curl                                    7.61.0-h84994c4_0 --> 7.64.1-hbc83047_0
      krb5                                    1.16.1-hc83ff2d_6 --> 1.16.1-h173b8e3_7
      libcurl                                 7.61.0-h1ad7b7a_0 --> 7.64.1-h20c2e04_0
      libssh2                                  1.8.0-h9cfc8f7_4 --> 1.8.2-h1ba5d50_0
      openssl                                 1.0.2r-h7b6447c_0 --> 1.1.1b-h7b6447c_1
      python                                  2.7.15-h77bded6_2 --> 2.7.16-h9bab390_0
      qt                                       5.9.6-h8703b6f_2 --> 5.9.7-h5867ecd_1
    
    The following packages will be SUPERSEDED by a higher-priority channel:
    
      ipyrad                       ipyrad::ipyrad-0.7.30-py27_7 --> eaton-lab::ipyrad-0.6.18-0
      pysam                         ipyrad::pysam-0.10.0-py27_3 --> pkgs/free::pysam-0.6-py27_0

    And yet, tetrad is still asking for toytree to be installed!

    What to do?

    espriggs
    @espriggs
    Screen Shot 2019-11-27 at 11.20.11 AM.png
    Hi @eaton-lab ! I'm trying to use toytree to plot a could tree, and I'm getting an error message with the example data. I have toytree v 1.0.5 and this is the error that I get. Everything else seems to be working great. I'd really appreciate any advice you have on fixing this!
    Eaton Lab
    @eaton-lab
    Hey @espriggs , did you install toytree using conda? It's supposed to pull in ghostscript automatically... if not you can install it with conda install ghostscript -c eaton-lab, or reinstall the whole thing with conda install toytree -c eaton-lab. Let me know if that fixes it.
    espriggs
    @espriggs
    Hey @eaton-lab , thanks for replying so fast! I tried the conda installation and it didn't work--I got "all requested packages are already installed." But I managed to install ghost script with "pip install ghostscript" and "brew install ghostscript" and now it's working great. Thanks!!
    Eaton Lab
    @eaton-lab
    @espriggs great. THanks for the tip about the installation problem, I'll look into it.
    @espriggs by the way, I'm coming up to HUH and the arboretum Sat-Mon.
    espriggs
    @espriggs
    @eaton-lab yes! I'm on your schedule Monday and I'm going to the Sunday dinner too