diff --git a/jcvi/utils/cbook.py b/jcvi/utils/cbook.py index 4dda9439..ecf16ab3 100644 --- a/jcvi/utils/cbook.py +++ b/jcvi/utils/cbook.py @@ -260,8 +260,11 @@ def human_size(size, a_kilobyte_is_1024_bytes=False, precision=1, target=None): return "{0:.{1}f}{2}".format(size, precision, suffix) -def autoscale(bp: int, optimal: int = 6): +def autoscale(bp: int, optimal: int = 8): """ + Autoscale the basepair length to a more human readable number. + The optimal is the number of ticks we want to see on the axis. + >>> autoscale(150000000) 20000000 >>> autoscale(97352632) diff --git a/tests/utils/test_cbook.py b/tests/utils/test_cbook.py index 65d04ab0..482bf87e 100644 --- a/tests/utils/test_cbook.py +++ b/tests/utils/test_cbook.py @@ -1,14 +1,26 @@ import os.path as op import pytest +from jcvi.apps.base import cleanup +from jcvi.utils.cbook import autoscale, depends, gene_name, seqid_parse + + +@pytest.mark.parametrize( + "input,output", + [ + (150000000, 20000000), + (97352632, 10000000), + ], +) +def test_autoscale(input, output): + assert autoscale(input) == output + @pytest.mark.parametrize( "input,output", [("AT5G54690.2", "AT5G54690"), ("evm.test.1", "evm.test.1")], ) def test_gene_name(input, output): - from jcvi.utils.cbook import gene_name - assert gene_name(input) == output @@ -25,15 +37,10 @@ def test_gene_name(input, output): ], ) def test_seqid_parse(seqid, sep, stdpf, output): - from jcvi.utils.cbook import seqid_parse - assert seqid_parse(seqid, sep, stdpf) == output def test_depends(): - from jcvi.apps.base import cleanup - from jcvi.utils.cbook import depends - @depends def func1(infile="a", outfile="b"): assert op.exists(infile)