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

feat: Add to_string method for Newick IO #468

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

RagnarGrootKoerkamp
Copy link
Contributor

@RagnarGrootKoerkamp RagnarGrootKoerkamp commented Nov 29, 2021

This adds the to_string, to_file, and write methods to
newick.rs, mirroring the existing from_string, from_file and
read methods.

A slight annoyance is that petgraph iterates outgoing edges in reverse
order of adding them. To keep input and output consistent, I manually
reverse that order back to the natural order in which they were added.
Another option would be to actually add them in the reverse order, but
that would change the representation which may not be desirable.

I'm also changing the "N/A" value for nodes without a name to just the
empty string as this heavily pollutes the to_string representation,
and "" is more naturaly IMO.

Using these two directions of conversions, we can now easily add tests for this :)

Also fixed one unused variable warning.

This adds the `to_string`, `to_file`, and `write` methods to
`newick.rs`, mirroring the existing `from_string`, `from_file` and
`read` methods.

A slight annoyance is that petgraph iterates outgoing edges in reverse
order of adding them. To keep input and output consistent, I manually
reverse that order back to the natural order in which they were added.
Another option would be to actually add them in the reverse order, but
that would change the representation which may not be desirable.

I'm also changing the `"N/A"` value for nodes without a name to just the
empty string as this heavily pollutes the `to_string` representation,
and `""` is more naturaly IMO.

Also fixed one unused variable warning.
@@ -159,7 +163,7 @@ fn newick_to_graph(root: TreeValue) -> Result<Tree> {
fn add_node(g: &mut TreeGraph, t: TreeValue) -> NodeIndex {
match t {
TreeValue::Node { name, children } => {
let node_id = g.add_node(name.unwrap_or("N/A".into()).into());
let node_id = g.add_node(name.unwrap_or("".into()).into());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be considered a breaking change. Happy to revert it.

Instead, loop over all vertices to find it, and return an error if the
root is not unique.
@coveralls
Copy link

coveralls commented Jul 21, 2022

Coverage Status

coverage: 81.851% (+0.9%) from 80.964% when pulling 1851096 on RagnarGrootKoerkamp:newick_to_string into 0181829 on rust-bio:master.

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.

None yet

3 participants