Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uncaught exception when using "plot_metric='length'" without lengths #70

Closed
daveuu opened this issue Sep 19, 2016 · 2 comments
Closed

Comments

@daveuu
Copy link

daveuu commented Sep 19, 2016

Hi

Possible minor bug in that function call looks for a non-existent attribute. Perhaps a more informative Error pointing to the lack of edge lengths rather than the more indirect lack of an attribute?

import dendropy

t = dendropy.Tree.get_from_string("(('A1','A2'),('B1','B2'),('C1','C2'));", schema = "newick")
print(t.as_ascii_plot(plot_metric='length'))

# AttributeError: 'Tree' object has no attribute 'as_newick_string'

t = dendropy.Tree.get_from_string("(('A1':0.1,'A2':0.1):0.2,('B1':0.1,'B2':0.1):0.2,('C1':0.1,'C2':0.1):0.2);", schema = "newick")
print(t.as_ascii_plot(plot_metric='length'))

# prints OK
@daveuu
Copy link
Author

daveuu commented Sep 19, 2016

That's in dendropy_version_info(major=4, minor=0, micro=3, releaselevel='') and Python 3.
I notice t.as_newick_string() is now t.as_string(schema='newick').

@jeetsukumaran
Copy link
Owner

Hi,

Thank you for reporting this error. As it turned out, this was a case of the error message confusing the error message. What was happening was that the plotting encountered an error due the width not being able to be properly calculated as there were no branch lengths even thought the requested plot metric was "length":

        if max_width == 0:
            raise AsciiTreePlot.NullEdgeLengthError("Tree cannot be plotted under metric '%s' due to zero or null edge lengths: '%s'" % (self.plot_metric, tree.as_newick_string()))

Unfortunately, the error message composition called on an obsolete function (as_newick_string of older code rather than the internal _as_newick_string of the newer code), and it was this error that caused the failure and an associated error message.

This has now been fixed in the top the development-master branch, revision a7bfde4 .

You will still get an error if you try to plot a tree with the plot metric being branch lengths and the tree has no branch lengths! But at least now, the error message should be meaningful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants