Exemplo n.º 1
0
 def test_add_track(self):
     figure = Figure()
     figure.add_track(
         Track(50,
               300,
               direction='f',
               label="Another\
         sequence",
               regions=[(50, 100, 'lightblue')]))
     figure.add_track(Track(110, 410, direction='r', label="Sequence 1",\
         regions=[(150, 200, 'salmon')]))
     figure.show()
Exemplo n.º 2
0
def summarize_figure(figure: Figure):
    """ Summarize the contents of a figure to text.

    Useful for testing.
    """
    figure.show()  # Test that all the display math works.

    summary = StringIO()
    for padding, track in figure.elements:
        spans = getattr(track, 'arrows', None)
        if spans is None:
            spans = getattr(track, 'tracks', [track])
        else:
            spans.sort(key=attrgetter('x', 'w', 'label'))
        for i, span in enumerate(spans):
            if i:
                summary.write(', ')
            ys = getattr(span, 'ys', None)
            if ys is not None:
                summary.write('Coverage ')
                summary.write(', '.join(map(str, ys)))
                continue
            coverage_groups = getattr(span, 'coverage_groups', None)
            if coverage_groups is not None:
                summary.write('Coverage ')
                for j, (y, count) in enumerate(coverage_groups):
                    if j:
                        summary.write(', ')
                    summary.write(str(y))
                    if count > 1:
                        summary.write(f'x{count}')
                continue
            direction = getattr(span, 'direction', None)
            if direction is not None and direction != '':
                if direction >= 0:
                    summary.write(f'{span.x}--{span.label}->{span.x+span.w}')
                else:
                    summary.write(f'{span.x}<-{span.label}--{span.x+span.w}')
                continue
            span_text = getattr(span.label, 'text', span.label) or ''
            summary.write(span_text)
            color = getattr(span, 'color')
            if span.a or span.b:
                if color != 'none':
                    summary.write(f'[{span.a}-{span.b}]')
                else:
                    summary.write(f'({span.a}-{span.b})')
            regions = getattr(span, 'regions', [])
            for start, end, colour in regions:
                summary.write(f', {colour}{{{start}-{end}}}')
        summary.write('\n')
    return summary.getvalue()
Exemplo n.º 3
0
 def test_multitrack(self):
     figure = Figure()
     for i in range(0, 10):
         figure.add_track(
             Multitrack([
                 Track(
                     i, i + 10, direction='f', label='Track {}F'.format(i)),
                 Track(i + 20,
                       i + 30,
                       direction='r',
                       label='Track {}R'.format(i))
             ],
                        join=True))
     figure.show()
Exemplo n.º 4
0
def test_draw_coverage(svg_differ):
    expected_figure = Figure()
    expected_figure.add(Track(0, 1, color='', h=-4))  # Just a spacer.
    expected_figure.add(Track(100, 200, label='Bar'))
    expected_svg = expected_figure.show()
    expected_svg.insert(0, draw.Rectangle(100, 20, 25, 5, fill='blue'))
    expected_svg.insert(1, draw.Rectangle(125, 20, 25, 10, fill='blue'))
    expected_svg.insert(2, draw.Rectangle(175, 20, 25, 1, fill='blue'))

    figure = Figure()
    coverage_depths = 25 * [5] + 25 * [10] + 25 * [0] + 25 * [1]
    figure.add(SmoothCoverage(100, 200, coverage_depths), gap=-4)
    figure.add(Track(100, 200, label="Bar"))

    svg = figure.show()

    svg_differ.assert_equal(svg, expected_svg, 'test_draw_coverage')
Exemplo n.º 5
0
def test_arrow_group_reverse_overlap(svg_differ):
    expected_figure = Figure()
    expected_figure.add(Track(1, 500, label='Header'))
    h = 20
    expected_figure.add(Arrow(1, 300, label='X', h=h), gap=3)
    expected_figure.add(Arrow(400, 250, label='Y', h=h))
    expected_svg = expected_figure.show()

    f = Figure()
    f.add(Track(1, 500, label='Header'))
    f.add(
        ArrowGroup(
            [Arrow(1, 300, label='X', h=h),
             Arrow(400, 250, label='Y', h=h)]))
    svg = f.show()

    svg_differ.assert_equal(svg, expected_svg, 'test_arrow_group')
Exemplo n.º 6
0
def test_arrow_group(svg_differ):
    expected_figure = Figure()
    expected_figure.add(Track(1, 500, label='Header'))
    h = 30
    expected_figure.add(Arrow(1, 200, label='X', h=h), gap=-h)
    expected_figure.add(Arrow(300, 500, label='Y', h=h))
    expected_svg = expected_figure.show()

    f = Figure()
    f.add(Track(1, 500, label='Header'))
    f.add(
        ArrowGroup(
            [Arrow(1, 200, label='X', h=h),
             Arrow(300, 500, label='Y', h=h)]))
    svg = f.show()

    svg_differ.assert_equal(svg, expected_svg, 'test_arrow_group')
Exemplo n.º 7
0
def test_arrow_group_small_neighbour(svg_differ):
    expected_figure = Figure()
    expected_figure.add(Track(1, 500, label='Header'))
    h = 20
    expected_figure.add(Arrow(301, 315, elevation=-1, label='1.2', h=h),
                        gap=-h)
    expected_figure.add(Arrow(1, 300, elevation=-1, label='1.1', h=h))
    expected_svg = expected_figure.show()

    f = Figure()
    f.add(Track(1, 500, label='Header'))
    f.add(
        ArrowGroup([
            Arrow(1, 300, elevation=-1, label='1.1', h=h),
            Arrow(301, 315, elevation=-1, label='1.2', h=h)
        ]))
    svg = f.show()

    svg_differ.assert_equal(svg, expected_svg, 'test_arrow_group')
Exemplo n.º 8
0
def test_tiny_arrow_at_edge(svg_differ):
    expected_svg = Drawing(210, 35, origin=(0, 0))
    expected_svg.append(Circle(197.5, 20, 10, stroke='black', fill='ivory'))
    expected_svg.append(
        Text('2.3', 11, 197.5, 20, text_anchor='middle', dy="0.35em"))
    expected_svg.append(
        Lines(200, 10, 195, 13.5, 195, 6.5, 200, 10, fill='black'))

    f = Figure()
    f.add(ArrowGroup([Arrow(195, 200, h=20, elevation=-1, label='2.3')]))
    svg = f.show()

    svg_differ.assert_equal(svg, expected_svg, 'test_arrow')
Exemplo n.º 9
0
def test_scaled_arrow(svg_differ):
    expected_svg = Drawing(100, 35, origin=(0, 0))
    expected_svg.append(Line(0, 10, 93, 10, stroke='black'))
    expected_svg.append(Circle(50, 20, 10, stroke='black', fill='ivory'))
    expected_svg.append(
        Text('2.3', 11, 50, 20, text_anchor='middle', dy="0.35em"))
    expected_svg.append(
        Lines(100, 10, 93, 13.5, 93, 6.5, 100, 10, fill='black'))

    f = Figure()
    f.add(Arrow(0, 200, h=20, elevation=-1, label='2.3'))
    svg = f.show(w=100)

    svg_differ.assert_equal(svg, expected_svg, 'test_arrow')