Skip to content

Instantly share code, notes, and snippets.

@kozo2
Created December 15, 2018 17:17
Show Gist options
  • Save kozo2/0a5bbd701b01e6fa6d6300e501cd9056 to your computer and use it in GitHub Desktop.
Save kozo2/0a5bbd701b01e6fa6d6300e501cd9056 to your computer and use it in GitHub Desktop.
import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objs as go
import pandas
rrna_operons = ("rrsA-ileT-alaT-rrlA-rrfA", "rrsB-gltT-rrlB-rrfB", "rrsC-gltU-rrlC-rrfC", "rrsD-ileU-alaU-rrlD-rrfD-thrV-rrfF", "rrsE-gltV-rrlE-rrfE", "rrsG-gltW-rrlG-rrfG", "rrsH-ileV-alaV-rrlH-rrfH")
colors = ['rgb(67,67,67)', 'rgb(115,115,115)', 'rgb(49,130,189)', 'rgb(189,189,189)', 'rgb(67,67,67)', 'rgb(115,115,115)', 'rgb(49,130,189)']
df = pandas.read_parquet('2018-11-26-0-04_pa.parquet', engine='pyarrow')
operons = pandas.read_csv("data/operons.csv", names=['name', 'left', 'right', 'direction'])
#hoge = df[["mrna." + operon[0] for operon in operons.as_matrix() if operon[0] not in rrna_operons]].as_matrix().sum(axis=1)
fig1 = df[["mrna." + operon for operon in rrna_operons]]
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
# html.Label('plottypeDropdown'),
dcc.Graph(id='graph-line'),
dcc.Dropdown(
id='plottype-column',
options=[
{'label': 'timecourse', 'value': 'TC'},
{'label': 'San Francisco', 'value': 'SF'}
],
value='TC'
),
# html.Label('biotypeDropdown'),
dcc.Dropdown(
id='biotype-column',
options=[
{'label': 'operon', 'value': 'OPERON'},
{'label': 'foobar', 'value': 'FOOBAR'}
],
value='OPERON'
),
html.Div(id='output-container')
])
#], style={'columnCount': 2})
@app.callback(
dash.dependencies.Output('graph-line', 'figure'),
[dash.dependencies.Input('plottype-column', 'value'),
dash.dependencies.Input('biotype-column', 'value')])
def update_output(plottype_column_name, biotype_column_name):
traces = []
# The number of operons containing ribosomal RNA fig1
for i in range(0,7):
traces.append(go.Scatter(
x = fig1.index.values,
y = fig1.iloc[:,i].values,
text=i,
mode="lines",
name=rrna_operons[i]
))
# The total number of mRNA excepting rRNAs
# traces.append(go.Scatter(
# x=list(range(len(hoge))),
# y=hoge.astype(int),
# text="hoge",
# mode="lines",
# name="foo"
# ))
return {
'data': traces,
'layout': go.Layout(
title= 'The number of operons containing ribosomal RNA',
xaxis={'title': 'Time'},
yaxis={'title': 'The number of molecules'},
legend={'x':0.2, 'y':0.1},
hovermode='closest'
)
}
# for i in df.column:
# traces.append(go.Scatter(
# x=df[i].index,
# y=df[i],
# mode='lines',
# line=dict(color='rgb(67,67,67)', width=4),
# connectgaps=True,
# ))
#return 'You have selected "{}"'.format(plottype_column_name + ", " + biotype_column_name)
if __name__ == '__main__':
# app.run_server(debug=True, host='0.0.0.0')
app.run_server(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment