Function order_tree_list

Source
pub fn order_tree_list(tree: &mut Tree, opt: &[String])
Expand description

Sort the children of each node by a list of names

use phylotree::tree::Tree;

// Simple case with only leaf nodes
let newick = "(A,B,C);";
let mut tree = Tree::from_newick(newick).unwrap();
nwr::order_tree_list(&mut tree, &["C".to_string(), "B".to_string(), "A".to_string()]);
assert_eq!(tree.to_newick().unwrap(), "(C,B,A);".to_string());

// Case with internal nodes
let newick = "((A,B),(C,D));";
let mut tree = Tree::from_newick(newick).unwrap();
nwr::order_tree_list(&mut tree, &["C".to_string(), "B".to_string(), "A".to_string()]);
assert_eq!(tree.to_newick().unwrap(), "((C,D),(B,A));".to_string());

// Case with internal nodes and names
let newick = "((A,B)X,(C,D)Y);";
let mut tree = Tree::from_newick(newick).unwrap();
nwr::order_tree_list(&mut tree, &["C".to_string(), "B".to_string(), "A".to_string()]);
assert_eq!(tree.to_newick().unwrap(), "((C,D)Y,(B,A)X);".to_string());

// Case with unlisted nodes
let newick = "((A,B),(C,E));";
let mut tree = Tree::from_newick(newick).unwrap();
nwr::order_tree_list(&mut tree, &["C".to_string(), "B".to_string()]);
assert_eq!(tree.to_newick().unwrap(), "((C,E),(B,A));".to_string());