Skip to content

Commit

Permalink
Added precision option for Newick command.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Nov 27, 2015
1 parent 7a1b4e0 commit 23cff17
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion msprime/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 23cff17

Please sign in to comment.