-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
148 lines (124 loc) · 4.48 KB
/
app.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
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
import numpy as np
import pickle
# Method for loading Python objects.
def load_obj(file):
with open(file, 'rb') as fid:
return pickle.load(fid)
# Style sheet.
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
# Embeddings.
dualAll = np.load("./data/dimReduc/dualPCA/embeddedAll.npy")
dualNum = np.load("./data/dimReduc/dualPCA/embeddedNum.npy")
kernelAll = np.load("./data/dimReduc/kernelPCA/embeddedAll.npy")
kernelNum = np.load("./data/dimReduc/kernelPCA/embeddedNum.npy")
# Sample data.
df = pd.read_csv("./data/cleaned/sampleData.csv", index_col=0)
# Lists and dictionaries.
spops = ['AFR', 'AMR', 'EAS', 'EUR', 'SAS']
spop2descrip = load_obj("./data/cleaned/spop2descrip.pkl")
spop_colors = ['rgb(220,20,60)', 'rgb(30,144,255)', 'rgb(50,205,50)', 'rgb(255,69,0)', 'rgb(139,0,139)']
spop2rgb = dict(zip(spops, spop_colors))
pops = load_obj("./data/cleaned/pops.pkl")
pop2descrip = load_obj("./data/cleaned/pop2descrip.pkl")
pop2rgb = load_obj("./data/cleaned/pop2rgb.pkl")
genders = ['male', 'female']
gender2descrip = dict(zip(genders, ['Male', 'Female']))
gender_colors = ['rgb(0,191,255)', 'rgb(255,99,71)']
gender2rgb = dict(zip(genders, gender_colors))
app.layout = html.Div([
html.Div([
html.Div([
html.Label('PCA Type'),
dcc.Dropdown(
id='pca-type',
options=[{'label': 'Dual', 'value': 'dual'},
{'label': 'Kernel', 'value': 'kernel'}],
value='dual'
),
], style={'width': '20%', 'display': 'inline-block', 'padding': '10px 20px 10px 20px', 'text-align': 'left'}),
html.Div([
html.Label('Include Sex Chromosomes?'),
dcc.Dropdown(
id='include-xy',
options=[{'label': 'Yes', 'value': 'whole-genome'},
{'label': 'No', 'value': 'exclude-xy'}],
value='whole-genome'
),
], style={'width': '20%', 'display': 'inline-block', 'padding': '10px 20px 10px 20px', 'text-align': 'left'}),
html.Div([
html.Label('Group By'),
dcc.Dropdown(
id='group-by',
options=[{'label': 'Super Population', 'value': 'spop'},
{'label': 'Population', 'value': 'pop'},
{'label': 'Gender', 'value': 'gender'}],
value='spop'
),
], style={'width': '20%', 'display': 'inline-block', 'padding': '10px 20px 10px 20px', 'text-align': 'left'}),
], style={'text-align': 'center'}),
dcc.Graph(id='genome-scatter', style={'height': '800'})
])
@app.callback(
dash.dependencies.Output('genome-scatter', 'figure'),
[dash.dependencies.Input('pca-type', 'value'),
dash.dependencies.Input('include-xy', 'value'),
dash.dependencies.Input('group-by', 'value')])
def update_graph(pca_type, include_xy, group_by):
# Do some stuff here.
if pca_type == 'dual':
if include_xy == 'whole-genome':
data = dualAll
else:
data = dualNum
else:
if include_xy == 'whole-genome':
data = kernelAll
else:
data = kernelNum
if group_by == 'spop':
vals = df['Super Population'].values
groups = spops
descrip_dict = spop2descrip
color_dict = spop2rgb
elif group_by == 'pop':
vals = df['Population'].values
groups = pops
descrip_dict = pop2descrip
color_dict = pop2rgb
else:
vals = df['Gender'].values
groups = genders
descrip_dict = gender2descrip
color_dict = gender2rgb
traces = list()
for group in groups:
ind = vals == group
groupData = data[ind,:]
trace = go.Scatter3d(
x=groupData[:,0],
y=groupData[:,1],
z=groupData[:,2],
mode='markers',
marker={
'size': 5,
'opacity': 0.5,
'color': color_dict[group]
},
name=descrip_dict[group]
)
traces.append(trace)
return {
'data': traces,
'layout': go.Layout(
margin={'l': 0, 'b': 0, 't': 0, 'r': 0},
legend=dict(x=0, y=1)
)
}
if __name__ == '__main__':
app.run_server(debug=True)