【数据科学系列】基于Python的Web应用框架Dash-Dash Bio Components快速入门

    xiaoxiao2024-12-24  67

    Dash Bio Components

    Dash Bio是一套生物信息学组件,可以更简单地分析和可视化生物信息学数据,并在Dash应用程序中与它们进行交互。

    快速入门

    准备工作

    pip install dash-bio==0.0.10

    Molecule3dViewer

    import json import six.moves.urllib.request as urlreq import dash import dash_bio as dashbio import dash_html_components as html external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] app = dash.Dash(__name__, external_stylesheets=external_stylesheets) model_data = urlreq.urlopen('https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/mol3d/model_data.js').read() styles_data = urlreq.urlopen('https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/mol3d/styles_data.js').read() model_data = json.loads(model_data) styles_data = json.loads(styles_data) app.layout = html.Div([ dashbio.Molecule3dViewer( id='my-dashbio-molecule3d', styles=styles_data, modelData=model_data ), "Selection data", html.Hr(), html.Div(id='molecule3d-output') ]) @app.callback( dash.dependencies.Output('molecule3d-output', 'children'), [dash.dependencies.Input('my-dashbio-molecule3d', 'selectedAtomIds')] ) def show_selected_atoms(atom_ids): if atom_ids is None or len(atom_ids) == 0: return 'No atoms have been selected. Click somewhere on the molecular structure to select an atom.' return [html.Div([ html.Div('Element: {}'.format(model_data['atoms'][atm]['element'])), html.Div('Chain: {}'.format(model_data['atoms'][atm]['chain'])), html.Div('Residue name: {}'.format(model_data['atoms'][atm]['residue_name'])), html.Br() ]) for atm in atom_ids] if __name__ == '__main__': app.run_server(debug=True)


    更多资料,请访问:https://dash.plot.ly/dash-bio

    最新回复(0)