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

Refactor logic to read trees from multiple formats into a function #310

Merged
merged 1 commit into from
Jul 10, 2019

Conversation

huddlej
Copy link
Contributor

@huddlej huddlej commented Jul 10, 2019

Adds a new function read_tree to the utils module that tries to safely
handle reading trees in multiple input formats. This kind of try/except approach
to loading trees is necessary because Bio.Phylo.read requires a specified tree
format, but we do not know the format of a given tree by the filename extension
alone.

A side effect of this commit is that missing input files are also now properly
caught and reported to the user on the command line instead of raising a Python
exception.

Closes #302.

Adds a new function `read_tree` to the `utils` module that tries to safely
handle reading trees in multiple input formats. This kind of try/except approach
to loading trees is necessary because Bio.Phylo.read requires a specified tree
format, but we do not know the format of a given tree by the filename extension
alone.

A side effect of this commit is that missing input files are also now properly
caught and reported to the user on the command line instead of raising a Python
exception.

Closes #302.
@huddlej huddlej requested review from emmahodcroft and rneher July 10, 2019 13:27
@rneher rneher merged commit 2bda188 into master Jul 10, 2019
@rneher rneher deleted the read-trees-safely branch July 10, 2019 13:33
@emmahodcroft
Copy link
Member

This is great @huddlej, thanks!

To add a little more clarity for anyone following this, the issue with my previous fix was that it cycles through checking both 'newick' and 'nexus' format, and thus if you exit on an exception from not being able to read newick, you never try to read nexus.

John's new code gives us a great way to standardise reading in trees and checking all the stuff we should!

@jameshadfield
Copy link
Member

Turned

UnboundLocalError: local variable 'T' referenced before assignment

into

Bio.Phylo.NewickIO.NewickError: Parenthesis mismatch.

🎉 big win. Thanks @huddlej

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

Successfully merging this pull request may close these issues.

Refine: Unable to Read Tree Not Handled
4 participants