def test_tree_output(self): # Add characters to all test trees trees = [ ngesh.add_characters(Tree(newick), 100, k=4.0, th=1.0, e=1.05, seed="myseed") for newick in _TREES ] # Assert the first one digest_nx = hashlib.sha256( str(ngesh.tree2nexus(trees[0])).encode("utf-8")).digest() digest_wl = hashlib.sha256( str(ngesh.tree2wordlist(trees[0])).encode("utf-8")).digest() assert ( digest_nx == b"E\xf8\x97\xb6*\x7f\xf4_j\x89\x02dn\x1d\xbe\xb0\xb6\xcd\xd9.\xca:\x9ft\xe2m\xc5y\xa5\xaa\x0fa" ) assert ( digest_wl == b"\xb6\xc8i\xf4!\xf4l\x91\xb9\x8d\xb5Kae\x1aF\x9c\xfd\n \x06\xf2D\x1e<\xdd(U]6(\xbf" ) # Test output for a tree without characters tree_nochar = Tree(_TREES[0]) digest_nx_nochar = hashlib.sha256( str(ngesh.tree2nexus(tree_nochar)).encode("utf-8")).digest() assert ( digest_nx_nochar == b"A\x06N\x97n1iD\x01n\x07T\x99al\xa8)m\n\x93\x9ajKp\x07\x9bc\x8a\x03\x1a\x8d\xb7" )
def test_bad_sampling(self): """ Test bad sampling simulation on an existing tree. """ tree = Tree(_TREES[-1]) ngesh.add_characters( tree, 10, k=4.0, th=1.0, z=1.045, k_hgt=2.0, th_hgt=1.1, seed="myseed", ) previous = tree.write() ngesh.simulate_bad_sampling(tree, 0.5, seed="myseed") digest = hashlib.sha256( str(ngesh.tree2wordlist(tree)).encode("utf-8")).digest() assert tree.write() != previous assert ( digest == b'\x8e\xe3\x9fzN\xbe0\xaa\xe2a\xc5\x854\x87>\xe6"s1?\xc1\x08YqM\xc4\xdd9Zh\xb37' )
def test_add_characters_with_hgt(self): tree_hgt = Tree(_TREES[0]) ngesh.add_characters( tree_hgt, 10, k=4.0, th=1.0, z=1.045, k_hgt=2.0, th_hgt=1.1, seed="myseed", ) digest = hashlib.sha256( str(ngesh.tree2wordlist(tree_hgt)).encode("utf-8")).digest() assert ( digest == b"\xc0\x84\x8a\xa8\x0b\xd6\xf8\x1b\x9c\xc7\xe6\xaf]\xe7\xee\x105\x989\x9b\xcfke\xe5\xf3\x03\xdc\x17U\x14 \xac" )
def main(): """ Main function for tree generation from the command line. """ # Parse command-line arguments args = parse_arguments() # Generate the tree tree = new_tree(args) # Output the tree according to the requested format if args.output == "newick": print(tree.write()) elif args.output == "ascii": print(tree) elif args.output == "nexus": print(ngesh.tree2nexus(tree)) elif args.output == "wl": print(ngesh.tree2wordlist(tree))
def test_add_characters(self): # gamma parameters NUM_CONCEPTS = 10 k = 4.0 # shape th = 1.0 # scale z = 1.045 # "zipf" correction # Add characters to all trees, for coverage trees = [ ngesh.add_characters(Tree(newick), NUM_CONCEPTS, k=k, th=th, z=z, seed="myseed") for newick in _TREES ] # Assert the first one digest = hashlib.sha256( str(ngesh.tree2wordlist(trees[0])).encode("utf-8")).digest() assert ( digest == b"\xdc<\x1f\x10N\xbf\xcc\xc4|l26\x10\xfc\xbaN\xb7\\c\x8bB\xca\x95.\xcbH\x82T\xa3\xbd\xff\x15" )