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
RagnarGrootKoerkamp
wants to merge
5
commits into
rust-bio:master
Choose a base branch
from
RagnarGrootKoerkamp:newick_to_string
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: Add to_string method for Newick IO #468
RagnarGrootKoerkamp
wants to merge
5
commits into
rust-bio:master
from
RagnarGrootKoerkamp:newick_to_string
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
There was a problem hiding this comment.
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.
RagnarGrootKoerkamp
force-pushed
the
newick_to_string
branch
from
November 29, 2021 14:42
062bec7
to
1b255b9
Compare
Instead, loop over all vertices to find it, and return an error if the root is not unique.
This was referenced Nov 30, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the
to_string
,to_file
, andwrite
methods tonewick.rs
, mirroring the existingfrom_string
,from_file
andread
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 theempty 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.