From 23cff17769b9c61dc9668efd2d835ca59c3c8a7a Mon Sep 17 00:00:00 2001 From: Jerome Kelleher Date: Fri, 27 Nov 2015 12:00:03 +0000 Subject: [PATCH] Added precision option for Newick command. --- msprime/cli.py | 5 ++++- tests/test_cli.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/msprime/cli.py b/msprime/cli.py index be497d116..f94a077c9 100644 --- a/msprime/cli.py +++ b/msprime/cli.py @@ -282,7 +282,7 @@ def mspms_main(arg_list=None): def run_dump_newick(args): tree_sequence = msprime.load(args.history_file) - for l, ns in tree_sequence.newick_trees(): + for l, ns in tree_sequence.newick_trees(args.precision): print(ns) @@ -407,6 +407,9 @@ def get_msp_parser(): "newick", help="Dump results in newick format.") add_history_file_argument(newick_parser) + newick_parser.add_argument( + "--precision", "-p", type=int, default=3, + help="The number of decimal places in branch lengths") newick_parser.set_defaults(runner=run_dump_newick) return parser diff --git a/tests/test_cli.py b/tests/test_cli.py index ed326a156..82b290caf 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -471,6 +471,25 @@ def test_newick_default_values(self): history_file = "test3.hdf5" args = parser.parse_args([cmd, history_file]) self.assertEqual(args.history_file, history_file) + self.assertEqual(args.precision, 3) + + def test_newick_short_args(self): + parser = cli.get_msp_parser() + cmd = "newick" + history_file = "test.hdf5" + args = parser.parse_args([ + cmd, history_file, "-p", "10"]) + self.assertEqual(args.history_file, history_file) + self.assertEqual(args.precision, 10) + + def test_newick_long_args(self): + parser = cli.get_msp_parser() + cmd = "newick" + history_file = "test.hdf5" + args = parser.parse_args([ + cmd, history_file, "--precision=5"]) + self.assertEqual(args.history_file, history_file) + self.assertEqual(args.precision, 5) class TestMspSimulateOutput(unittest.TestCase):