Example #1
0
def test_dbci002_inner_outer_radii(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.Circos(
            id=_COMPONENT_ID,
            layout=_data['GRCh37']
        )
    ))

    change_radii_config = {'innerRadius': 20, 'outerRadius': 100}

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='config',
        test_prop_value=json.dumps(change_radii_config),
        prop_value_type='dict',
        validation_fn=lambda x:
        x['innerRadius'] == change_radii_config['innerRadius']
        and x['outerRadius'] == change_radii_config['outerRadius']
    )

    chr_one_div = dash_duo.find_element('path#chr1')

    assert int(chr_one_div.size['width']) == 41
    assert int(chr_one_div.size['height']) == 81
Example #2
0
def test_dbsp006_custom_view(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(dash_bio.Speck(id=_COMPONENT_ID, data=_data)))

    new_view = {
        'ao': 0.1,
        'outline': 1,
        'dofStrength': 0.4,
        'resolution': 600,
        'atomScale': 0.15,
        'relativeAtomScale': 0.51,
        'bonds': True,
        'bondScale': 0.75
    }

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='view',
        test_prop_value=json.dumps(new_view),
        prop_value_type='dict',
        validation_fn=lambda x: json.dumps(x) == json.dumps(new_view),
        take_snapshot=True)
Example #3
0
def test_dbci001_graph_type(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.Circos(
            id=_COMPONENT_ID,
            layout=_data['GRCh37'],
        )
    ))

    histogram_layout = [
        {'type': 'HISTOGRAM', 'data': _data['histogram'][:5]}
    ]

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='tracks',
        test_prop_value=json.dumps(histogram_layout),
        prop_value_type='dict',
        validation_fn=lambda x: json.dumps(x) == json.dumps(histogram_layout)
    )

    # there should be five bins in the histogram
    assert len(dash_duo.find_elements('path.bin')) == 5
Example #4
0
def test_dbm3001_selection_type(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(
            dash_bio.Molecule3dViewer(id=_COMPONENT_ID,
                                      modelData=_model_data,
                                      styles=_styles_data)))

    simple_app_callback(app,
                        dash_duo,
                        component_id=_COMPONENT_ID,
                        test_prop_name='selectionType',
                        test_prop_value='chain',
                        prop_value_type='string')

    # find and click on one of the DNA strands
    mol3d = dash_duo.find_element('#test-mol3d canvas')
    ac = ActionChains(dash_duo.driver)
    ac.move_to_element(mol3d).move_by_offset(0, -50).click().perform()

    dash_duo.wait_for_element_by_css_selector('.molecule-3d')

    dash_duo.percy_snapshot('test-mol3d_selectionType_chain' +
                            generate_identifier(),
                            convert_canvases=True)
def test_dbm2003_select_atoms_via_callback(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(
            dash_bio.Molecule2dViewer(id=_COMPONENT_ID, modelData=_data)))

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='selectedAtomIds',
        test_prop_value=json.dumps([1, 4]),
        prop_value_type='list',
        validation_fn=lambda x: json.dumps(x) == json.dumps([1, 4]))

    assert len(
        dash_duo.find_elements(
            'g.nodes-container > g.node.selected[index="1"]')) == 1
    assert len(
        dash_duo.find_elements(
            'g.nodes-container > g.node.selected[index="2"]')) == 0
    assert len(
        dash_duo.find_elements(
            'g.nodes-container > g.node.selected[index="3"]')) == 0
    assert len(
        dash_duo.find_elements(
            'g.nodes-container > g.node.selected[index="4"]')) == 1
Example #6
0
def test_dbid002_click_rotation(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.Ideogram(
            id=_COMPONENT_ID
        )
    ))

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='rotatable',
        test_prop_value=str(True),
        prop_value_type='bool',
        validation_fn=lambda x: x is True
    )

    # ensure that it loads un-rotated
    WebDriverWait(dash_duo.driver, 1).until(
        lambda _: 'rotate(90)' in dash_duo.find_element(
            '#chr1-9606-chromosome-set').get_attribute('transform'))

    # click to rotate and ensure that the correct chromosome is rotated
    dash_duo.find_element('#chr1-9606-chromosome-set').click()

    # rotation shouldn't take more than 1-2 seconds
    WebDriverWait(dash_duo.driver, 1).until(
        lambda _: 'rotate(0)' in dash_duo.find_element(
            '#chr1-9606-chromosome-set').get_attribute('transform'))
Example #7
0
def test_dbid003_click_rotation_disabled(dash_duo):
    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.Ideogram(
            id=_COMPONENT_ID
        )
    ))

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='rotatable',
        test_prop_value=str(False),
        prop_value_type='bool',
        validation_fn=lambda x: x is False
    )

    WebDriverWait(dash_duo.driver, 1).until(
        lambda _: 'rotate(90)' in dash_duo.find_element(
            '#chr1-9606-chromosome-set').get_attribute('transform'))

    # click to rotate and ensure that the correct chromosome is rotated
    dash_duo.find_element('#chr1-9606-chromosome-set').click()

    WebDriverWait(dash_duo.driver, 1)

    assert 'rotate(90)' in dash_duo.find_element(
        '#chr1-9606-chromosome-set').get_attribute('transform')
Example #8
0
def test_dbsv002_selection(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.SequenceViewer(
            id=_COMPONENT_ID,
            sequence=_data
        )
    ))

    new_selection = [50, 75, 'rgb(120, 0, 200)']

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='selection',
        test_prop_value=json.dumps(new_selection),
        prop_value_type='list',
        validation_fn=lambda x: json.dumps(x) == json.dumps(new_selection),
        take_snapshot=True
    )

    selection = dash_duo.find_element('.fastaSeq span.stringSelected')

    match = re.search(
        r'.*background:\s*([\w\s,\(\)]+);.*',
        selection.get_attribute('style')
    )
    assert match.group(1) == new_selection[2]

    assert selection.get_attribute('innerHTML').replace(
        ' ', ''.replace('<br>', '')) == \
        _data[new_selection[0]:new_selection[1]]
Example #9
0
def test_dbid001_displayed_chromosomes(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.Ideogram(
            id=_COMPONENT_ID
        )
    ))

    chromosome_set_new = [str(i+1) for i in range(5)]

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='chromosomes',
        test_prop_value=json.dumps(chromosome_set_new),
        prop_value_type='dict',
        validation_fn=lambda x: json.dumps(x) == json.dumps(chromosome_set_new)
    )

    WebDriverWait(dash_duo.driver, 1).until(
        lambda _:
        len(dash_duo.find_elements('g.chromosome-set-container')) == 5
    )
def test_dbav003_change_conservation_colorscale(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(dash_bio.AlignmentChart(id=_COMPONENT_ID,
                                                  data=_data)))

    simple_app_callback(app,
                        dash_duo,
                        component_id=_COMPONENT_ID,
                        test_prop_name='conservationcolorscale',
                        test_prop_value='Blackbody',
                        prop_value_type='string')

    bars = dash_duo.find_elements('g.cartesianlayer g.subplot.xy2 g.plot path')

    # first bar should be black
    match = re.search(r'.*fill: ([\w\s,\(\)]+);.*',
                      bars[0].get_attribute('style'))
    assert match.group(1) == 'rgb(0, 0, 0)'

    # second bar should be orange
    match = re.search(r'.*fill: ([\w\s,\(\)]+);.*',
                      bars[1].get_attribute('style'))
    assert match.group(1) == 'rgb(230, 103, 0)'
Example #11
0
def test_dbsp005_preset_view_stickball(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(dash_bio.Speck(id=_COMPONENT_ID, data=_data)))

    simple_app_callback(app,
                        dash_duo,
                        component_id=_COMPONENT_ID,
                        test_prop_name='presetView',
                        test_prop_value='stickball',
                        prop_value_type='string',
                        take_snapshot=True)
def test_dbav002_change_colorscale(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(dash_bio.AlignmentChart(id=_COMPONENT_ID,
                                                  data=_data)))

    simple_app_callback(app,
                        dash_duo,
                        component_id=_COMPONENT_ID,
                        test_prop_name='colorscale',
                        test_prop_value='hydro',
                        prop_value_type='string',
                        take_snapshot=True)
def test_dbav001_hide_conservation(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(dash_bio.AlignmentChart(id=_COMPONENT_ID,
                                                  data=_data)))

    simple_app_callback(app,
                        dash_duo,
                        component_id=_COMPONENT_ID,
                        test_prop_name='showconservation',
                        test_prop_value=str(False),
                        prop_value_type='bool',
                        validation_fn=lambda x: x is False)

    assert len(dash_duo.find_elements('g.cartesianlayer.xy3')) == 0
def test_dbm3003_selected_atom_ids(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(
            dash_bio.Molecule3dViewer(id=_COMPONENT_ID,
                                      modelData=_model_data,
                                      styles=_styles_data)))

    simple_app_callback(app,
                        dash_duo,
                        component_id=_COMPONENT_ID,
                        test_prop_name='selectedAtomIds',
                        test_prop_value=json.dumps([1306, 1371, 1339, 1404]),
                        prop_value_type='list',
                        validation_fn=lambda x: json.dumps(x) == json.dumps(
                            [1306, 1371, 1339, 1404]),
                        take_snapshot=True)
Example #15
0
def test_dbop002_colorscale(dash_duo):

    app = dash.Dash(__name__)

    new_colorscale = {
        'AMP': 'rgb(10, 200, 100)',
        'FUSION': 'rgb(100, 10, 20)',
        'HOMDEL': 'rgb(200, 50, 60)'
    }
    # fusion deep del amp
    app.layout = html.Div(
        simple_app_layout(dash_bio.OncoPrint(id=_COMPONENT_ID, data=_data)))

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='colorscale',
        test_prop_value=json.dumps(new_colorscale),
        prop_value_type='dict',
        validation_fn=lambda x: json.dumps(x) == json.dumps(new_colorscale),
        take_snapshot=True)

    fus = dash_duo.find_elements(
        'g.cartesianlayer g.plot g.trace.bars:nth-child(2) g.point > path')
    for point in fus:
        match = re.search(r'.*fill: ([\w\s,\(\)]+);.*',
                          point.get_attribute('style'))
        assert match.group(1) == 'rgb(100, 10, 20)'

    deep_del = dash_duo.find_elements(
        'g.cartesianlayer g.plot g.trace.bars:nth-child(3) g.point > path')
    for point in deep_del:
        match = re.search(r'.*fill: ([\w\s,\(\)]+);.*',
                          point.get_attribute('style'))
        assert match.group(1) == 'rgb(200, 50, 60)'

    amp = dash_duo.find_elements(
        'g.cartesianlayer g.plot g.trace.bars:nth-child(4) g.point > path')
    for point in amp:
        match = re.search(r'.*fill: ([\w\s,\(\)]+);.*',
                          point.get_attribute('style'))
        assert match.group(1) == 'rgb(10, 200, 100)'
Example #16
0
def test_dbnp002_domainStyle(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.NeedlePlot(
            id=_COMPONENT_ID,
            mutationData=_data
        )
    ))

    new_domain_style = {
        'domainColor': ['rgb(200, 100, 0)',
                        'rgb(120, 246, 100)',
                        'rgb(150, 245, 170)',
                        'rgb(0, 200, 150)',
                        'rgb(100, 70, 25)'],
        'displayMinorDomains': False
    }

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='domainStyle',
        test_prop_value=json.dumps(new_domain_style),
        prop_value_type='dict',
        validation_fn=lambda x: json.dumps(x) == json.dumps(new_domain_style),
        take_snapshot=True
    )

    domains = dash_duo.find_elements('g.overplot g.scatterlayer.mlayer path.js-fill')

    for domain in domains:
        match = re.search(
            r'.*fill: ([\w\s,\(\)]+);.*',
            domain.get_attribute('style')
        )

        assert match.group(1) in new_domain_style['domainColor']
def test_dbm2001_load_mol_data(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(dash_bio.Molecule2dViewer(id=_COMPONENT_ID)))

    def compare_nodes_links(computed_props):
        given_nodes = _data['nodes']
        given_links = _data['links']
        computed_nodes = computed_props['nodes']
        computed_links = computed_props['links']

        defined_node_props = ['id', 'atom']
        for i in range(len(given_nodes)):
            for key in defined_node_props:
                if given_nodes[i][key] != computed_nodes[i][key]:
                    return False

        defined_link_props = ['bond', 'strength', 'distance']
        for i in range(len(given_links)):
            for key in defined_link_props:
                if given_links[i][key] != computed_links[i][key]:
                    return False
                if given_links[i]['source'] != \
                   computed_links[i]['source']['id']:
                    return False
                if given_links[i]['target'] != \
                   computed_links[i]['target']['id']:
                    return False
        return True

    simple_app_callback(app,
                        dash_duo,
                        component_id=_COMPONENT_ID,
                        test_prop_name='modelData',
                        test_prop_value=json.dumps(_data),
                        prop_value_type='dict',
                        validation_fn=lambda x: compare_nodes_links(x))
def test_dbdn002_change_background(dash_duo):

    stage_config = {
        "backgroundColor": "black",
        "quality": "medium",
        "cameraType": "perspective",
    }

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(viewer, ))

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name="stageParameters",
        test_prop_value=json.dumps(stage_config),
        prop_value_type="dict",
        validation_fn=lambda x: json.dumps(x) == json.dumps(stage_config),
        take_snapshot=True,
    )
Example #19
0
def test_dbop001_background_color(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        simple_app_layout(dash_bio.OncoPrint(id=_COMPONENT_ID, data=_data)))

    simple_app_callback(app,
                        dash_duo,
                        component_id=_COMPONENT_ID,
                        test_prop_name='backgroundcolor',
                        test_prop_value='rgb(25, 211, 243)',
                        prop_value_type='string',
                        take_snapshot=True)

    background = dash_duo.find_elements(
        'g.cartesianlayer g.plot g.trace.bars:nth-child(1) g.point > path')

    for point in background:

        match = re.search(r'.*fill: ([\w\s,\(\)]+);.*',
                          point.get_attribute('style'))
        assert match.group(1) == 'rgb(25, 211, 243)'
Example #20
0
def test_dbsv001_coverage(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.SequenceViewer(
            id=_COMPONENT_ID,
            sequence=_data
        )
    ))

    new_coverage = [
        {'start': 0, 'end': 10, 'color': 'rgb(255, 0, 0)',
         'bgcolor': 'rgb(0, 0, 255)', 'underscore': True,
         'tooltip': 'Coverage one'},

        {'start': 45, 'end': 80, 'color': 'rgb(200, 150, 150)',
         'bgcolor': 'rgb(0, 0, 0)', 'underscore': False}
    ]

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='coverage',
        test_prop_value=json.dumps(new_coverage),
        prop_value_type='list',
        validation_fn=lambda x: json.dumps(x) == json.dumps(new_coverage),
        take_snapshot=True
    )

    coverage_1 = dash_duo.find_element(
        '.sequenceBody .fastaSeq span:nth-child(1)')

    match = re.search(
        r'.*color:\s*([\w\s,\(\)]+);.*',
        coverage_1.get_attribute('style')
    )
    assert match.group(1) == new_coverage[0]['color']

    match = re.search(
        r'.*background:\s*([\w\s,\(\)]+);.*',
        coverage_1.get_attribute('style')
    )
    assert match.group(1) == new_coverage[0]['bgcolor']

    assert coverage_1.get_attribute('title') == new_coverage[0]['tooltip']
    assert coverage_1.get_attribute('innerHTML').replace(
        ' ', '').replace('<br>', '') == \
        _data[new_coverage[0]['start']:new_coverage[0]['end']]

    coverage_2 = dash_duo.find_element(
        '.sequenceBody .fastaSeq span:nth-child(3)')

    match = re.search(
        r'.*color:\s*([\w\s,\(\)]+);.*',
        coverage_2.get_attribute('style')
    )
    assert match.group(1) == new_coverage[1]['color']

    match = re.search(
        r'.*background:\s*([\w\s,\(\)]+);.*',
        coverage_2.get_attribute('style')
    )
    assert match.group(1) == new_coverage[1]['bgcolor']

    assert coverage_2.get_attribute('title') == ''
    assert coverage_2.get_attribute('innerHTML').replace(
        ' ', '').replace('<br>', '') == \
        _data[new_coverage[1]['start']:new_coverage[1]['end']]
Example #21
0
def test_dbnp001_needle_style(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(simple_app_layout(
        dash_bio.NeedlePlot(
            id=_COMPONENT_ID,
            mutationData=_data
        )
    ))

    new_needle_style = {
        'stemConstHeight': True,
        'stemColor': 'rgb(99, 110, 250)',
        'stemThickness': 4,
        'headColor': 'rgb(239, 85, 59)',
        'headSize': 10
    }

    simple_app_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        test_prop_name='needleStyle',
        test_prop_value=json.dumps(new_needle_style),
        prop_value_type='dict',
        validation_fn=lambda x: json.dumps(x) == json.dumps(new_needle_style),
        take_snapshot=True
    )

    # points should all be at the same height (y-value)
    points = dash_duo.find_elements('g.trace.scatter > g.points > path')
    lines = dash_duo.find_elements('g.trace.scatter > g.errorbars > g.errorbar > path')

    y_location = points[0].get_attribute('transform').strip(
        'translate(').strip(
            ')').split(',')[1]

    for point in points[1:]:
        point_y_location = point.get_attribute('transform').strip(
            'translate').strip(
                '(').strip(')').split(',')[1]
        assert point_y_location == y_location

        match = re.search(
            r'.*fill: ([\w\s,\(\)]+);.*',
            point.get_attribute('style')
        )
        assert match.group(1) == 'rgb(239, 85, 59)'

    for line in lines:
        match = re.search(
            r'.*stroke: ([\w\s,\(\)]+);.*',
            line.get_attribute('style')
        )
        assert match.group(1) == 'rgb(99, 110, 250)'

        match = re.search(
            r'.*stroke-width: ([\w]+);.*',
            line.get_attribute('style')
        )
        assert match.group(1) == '4px'