-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathexperiment.py
189 lines (140 loc) · 4.85 KB
/
experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import itertools
import json
from dashapp_functions import *
import base64
import datetime
import io
import numpy as np
import pandas as pd
app = dash.Dash()
app.config.supress_callback_exceptions = True
def create_outputs():
def single_output(i):
return html.Div([
html.P('output_{}'.format(i)),
dcc.Input('input_{}'.format(i), type='number', min=0, max=3, step=0.5, value=0),
dcc.RadioItems('radio_{}'.format(i), options=[{'label': i, 'value': i} for i in ['Mono', 'By chromosome', 'Custom']], value='Custom'),
], id='single_output_{}'.format(i),
style={'display': 'inline-block'}
)
return html.Div([single_output(i) for i in range(5)])
app.layout = html.Div([
html.P('Type the number of components to show'),
dcc.Input(id='number', type='number', value=0, step=1, min=0, max=5),
html.Div([create_outputs()]),
dcc.Store(id='output_print'),
html.Div([expand_histogram()]),
dcc.Upload(
id='upload-data',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files')
])),
html.Div(id='output-upload')
])
def parse_contents(contents):
try:
_, content_string = contents.split(',')
decoded = base64.b64decode(content_string)
df = pd.read_csv(io.StringIO(decoded.decode('utf-8')), sep='\t', header='infer')
print(df.head())
return html.Div([str(df.iloc[0,0])])
except Exception:
return html.Div('Error occur')
@app.callback(
Output('output-upload', 'children'),
[Input('upload-data', 'contents')]
)
def upload_output(contents):
_, content_string = contents.split(',')
decoded = base64.b64decode(content_string)
df = pd.read_csv(io.StringIO(decoded.decode('utf-8')), sep='\t', header='infer')
print(df.tail())
return parse_contents(contents)
@app.callback(
Output('single_output_0', 'style'),
[Input('number', 'value')]
)
def toggle_0(number):
if number >= 1: return {'display': 'block'}
else: return {'display': 'none'}
@app.callback(
Output('single_output_1', 'style'),
[Input('number', 'value')]
)
def toggle_1(number):
if number >= 2: return {'display': 'block'}
else: return {'display': 'none'}
@app.callback(
Output('single_output_2', 'style'),
[Input('number', 'value')]
)
def toggle_2(number):
if number >= 3: return {'display': 'block'}
else: return {'display': 'none'}
@app.callback(
Output('single_output_3', 'style'),
[Input('number', 'value')]
)
def toggle_3(number):
if number >= 4: return {'display': 'block'}
else: return {'display': 'none'}
@app.callback(
Output('single_output_4', 'style'),
[Input('number', 'value')]
)
def toggle_4(number):
if number >= 5: return {'display': 'block'}
else: return {'display': 'none'}
@app.callback(
Output('output_print', 'data'),
[
Input('number', 'value'),
Input('input_0', 'value'),
Input('radio_0', 'value'),
Input('input_1', 'value'),
Input('radio_1', 'value'),
Input('input_2', 'value'),
Input('radio_2', 'value'),
Input('input_3', 'value'),
Input('radio_3', 'value'),
Input('input_4', 'value'),
Input('radio_4', 'value'),
]
)
def display_result(number, *arg):
res = []
for i in range(number):
di = {'input': arg[2*i],
'radio': arg[2*i+1]
}
res.append(di)
#res.append(arg[2*i+1])
#res.append({'input': arg[i*2], 'radio': arg[i*2+1]})
print(res)
return res
'''
for i in range(20):
@app.callback(
Output('single_output_{}'.format(i), 'style'),
[Input('number', 'value')]
)
def toggle_hide_i(number):
if i <= number:
return {'display': 'inline-block'}
else:
print(i, number)
return {'display': 'block'}
'''
if __name__ == '__main__':
app.run_server(debug=True, port=8051)
self.get_data_array_dict(key)
self.get_read_data(key)
self.get_data[key]['data_array']
self.get_data[key]['sortindex']
self.get_data[key]['read_data']
{'file': {'path': <_io.StringIO object at 0x11cdbe4c8>, 'sep': '\t', 'header': 'infer'}, 'hovertextformat': ' "Chromosome: {}<br>Position: {}<br>Value: {:.2f}".format(a[i,0], a[i,1], float(a[i,2])) ', 'radius': {'R0': 0.4, 'R1': 0.5}, 'marker': {'size': 2}, 'line': {'width': 2, 'opacity': 0.9, 'smoothing': 0}, 'colorcolumn': 'ideogram', 'show': True, 'sortbycolor': False, 'trace': {'hoverinfo': 'text', 'mode': 'lines+markers', 'opacity': 0.9, 'marker': {'symbol': 0, 'size': 3, 'color': 'black'}, 'line': {'color': 'black', 'width': 2, 'shape': 'linear', 'smoothing': 0}}}