diff --git a/jcvi/graphics/synteny.py b/jcvi/graphics/synteny.py index 2e12c553..7f56e770 100644 --- a/jcvi/graphics/synteny.py +++ b/jcvi/graphics/synteny.py @@ -18,9 +18,11 @@ """ import sys -from typing import Optional + +from typing import List, Optional import numpy as np + from matplotlib import transforms from matplotlib.path import Path @@ -626,7 +628,7 @@ def draw_gene_legend( ax.text(xr, ytop + d / 2, "repeat", ha="center") -def main(): +def main(args: List[str]): p = OptionParser(__doc__) p.add_argument("--switch", help="Rename the seqid with two-column file") p.add_argument("--tree", help="Display trees on the bottom of the figure") @@ -684,7 +686,7 @@ def main(): action="store_true", help="If set, do not exclude small features from annotation track (<1%% of region)", ) - opts, args, iopts = p.set_image_options(figsize="8x7") + opts, args, iopts = p.set_image_options(args, figsize="8x7") if len(args) != 3: sys.exit(not p.print_help()) @@ -728,6 +730,8 @@ def main(): image_name = pf + "." + iopts.format savefig(image_name, dpi=iopts.dpi, iopts=iopts) + return image_name + if __name__ == "__main__": - main() + main(sys.argv[1:]) diff --git a/tests/graphics/data/blocks b/tests/graphics/data/blocks new file mode 100644 index 00000000..1a557029 --- /dev/null +++ b/tests/graphics/data/blocks @@ -0,0 +1,50 @@ +GSVIVT01012261001 . +GSVIVT01012259001 . +GSVIVT01012258001 . +GSVIVT01012257001 . +GSVIVT01012255001 Prupe.1G290900.1 +GSVIVT01012253001 Prupe.1G290800.2 +GSVIVT01012252001 Prupe.1G290700.1 +GSVIVT01012250001 Prupe.1G290600.1 +GSVIVT01012249001 Prupe.1G290500.1 +GSVIVT01012248001 Prupe.1G290400.1 +GSVIVT01012247001 Prupe.1G290200.2 +GSVIVT01012246001 Prupe.1G290100.3 +GSVIVT01012245001 Prupe.1G290000.1 +GSVIVT01012244001 Prupe.1G289800.1 +GSVIVT01012243001 . +GSVIVT01012242001 . +GSVIVT01012241001 . +GSVIVT01012240001 . +GSVIVT01012239001 Prupe.1G289700.1 +GSVIVT01012238001 . +GSVIVT01012237001 Prupe.1G289300.1 +GSVIVT01012236001 Prupe.1G289200.2 +GSVIVT01012235001 . +GSVIVT01012234001 Prupe.1G289100.1 +GSVIVT01012233001 Prupe.1G289000.1 +GSVIVT01012232001 . +GSVIVT01012231001 Prupe.1G288900.1 +GSVIVT01012230001 Prupe.1G288700.1 +GSVIVT01012229001 . +GSVIVT01012228001 Prupe.1G288300.1 +GSVIVT01012227001 Prupe.1G288100.3 +GSVIVT01012226001 . +GSVIVT01012225001 Prupe.1G288000.1 +GSVIVT01012224001 Prupe.1G287800.1 +GSVIVT01012223001 Prupe.1G287500.1 +GSVIVT01012222001 Prupe.1G287300.2 +GSVIVT01012221001 Prupe.1G287300.1 +GSVIVT01012220001 Prupe.1G287200.1 +GSVIVT01012219001 Prupe.1G286800.1 +GSVIVT01012218001 Prupe.1G286700.2 +GSVIVT01012217001 . +GSVIVT01012216001 Prupe.1G285700.1 +GSVIVT01012215001 Prupe.1G286600.2 +GSVIVT01012214001 Prupe.1G286500.1 +GSVIVT01012213001 Prupe.1G286400.1 +GSVIVT01012212001 Prupe.1G286200.1 +GSVIVT01012211001 Prupe.1G286100.1 +GSVIVT01012210001 Prupe.1G286000.1 +GSVIVT01012209001 Prupe.1G286000.1 +GSVIVT01012208001 Prupe.1G285900.1 diff --git a/tests/graphics/data/blocks.layout b/tests/graphics/data/blocks.layout new file mode 100644 index 00000000..497ad787 --- /dev/null +++ b/tests/graphics/data/blocks.layout @@ -0,0 +1,5 @@ +# x, y, rotation, ha, va, color, ratio, label +0.5, 0.6, 0, left, center, m, 1, grape Chr1 +0.5, 0.4, 0, left, center, #fc8d62, 1, peach scaffold_1 +# edges +e, 0, 1 diff --git a/tests/graphics/test_karyotype.py b/tests/graphics/test_karyotype.py index cdb18745..65240f48 100644 --- a/tests/graphics/test_karyotype.py +++ b/tests/graphics/test_karyotype.py @@ -5,6 +5,7 @@ import os.path as op import pytest +from jcvi.apps.base import cleanup from jcvi.graphics.karyotype import main as karyotype_main, make_circle_name @@ -27,6 +28,7 @@ def test_make_circle_name(sid, rev, expected): def test_main(): cwd = os.getcwd() os.chdir(op.join(op.dirname(__file__), "data")) + cleanup("karyotype.pdf") image_name = karyotype_main(["seqids", "layout"]) assert op.exists(image_name) os.chdir(cwd) diff --git a/tests/graphics/test_synteny.py b/tests/graphics/test_synteny.py index c510b628..3401ef87 100644 --- a/tests/graphics/test_synteny.py +++ b/tests/graphics/test_synteny.py @@ -1,10 +1,14 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- +import os +import os.path as op import pytest +from jcvi.apps.base import cleanup +from jcvi.formats.bed import merge +from jcvi.graphics.synteny import LayoutLine, main as synteny_main from jcvi.utils.validator import ValidationError -from jcvi.graphics.synteny import LayoutLine @pytest.mark.parametrize( @@ -43,3 +47,13 @@ def test_valid_layoutline(row, delimiter): def test_invalid_layoutline(row, delimiter, error): with pytest.raises(error): _ = LayoutLine(row, delimiter) + + +def test_main(): + cwd = os.getcwd() + os.chdir(op.join(op.dirname(__file__), "data")) + cleanup("grape_peach.bed", "blocks.pdf") + merge(["grape.bed", "peach.bed", "-o", "grape_peach.bed"]) + image_name = synteny_main(["blocks", "grape_peach.bed", "blocks.layout"]) + assert op.exists(image_name) + os.chdir(cwd)