Skip to content

Commit

Permalink
Test synteny as well
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed May 8, 2024
1 parent 376d237 commit 45a8806
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
12 changes: 8 additions & 4 deletions jcvi/graphics/synteny.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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:])
50 changes: 50 additions & 0 deletions tests/graphics/data/blocks
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tests/graphics/data/blocks.layout
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/graphics/test_karyotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
16 changes: 15 additions & 1 deletion tests/graphics/test_synteny.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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)

0 comments on commit 45a8806

Please sign in to comment.