-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworldmap_1000G.py
105 lines (91 loc) · 3.31 KB
/
worldmap_1000G.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
import altair as alt
from altair.expr import datum, substring
from vega_datasets import data
from sys import argv
import pandas as pd
df = pd.read_csv(argv[1])
df = df.dropna(subset=['longitude', 'latitude'])
countries = alt.topo_feature(data.world_110m.url, 'countries')
selection = alt.selection_multi(fields=['population'])
brush = alt.selection_interval()
hover = selection
color = alt.condition(selection,
alt.Color('population:N', legend=None),
alt.value('#EEEEEE'))
chart = alt.Chart(countries).mark_geoshape(
fill='#CCCCCC',
stroke='white',
opacity=0.4
).properties(
width=850,
height=850
)
chart += alt.Chart().mark_circle(size=300, stroke="black", strokeWidth=0.3).encode(
longitude='longitude:Q',
latitude='latitude:Q',
color=color,
tooltip=['population', '1000G population code',
'1000G superpopulation code']
).project(type="orthographic").transform_filter(brush).add_selection(hover)
chart_GTM = alt.Chart().mark_circle(size=30, strokeWidth=0.4).encode(
x=alt.X("GTM axis 1", scale=alt.Scale(domain=[-1.0, 1.0]), axis=alt.Axis(
ticks=False, labels=False, grid=False,
)),
y=alt.Y("GTM axis 2", scale=alt.Scale(domain=[-1.0, 1.0]), axis=alt.Axis(
ticks=False, labels=False, grid=False,
)),
color=color,
tooltip=['id', 'population', '1000G population code',
'1000G superpopulation code'],
).properties(
width=250,
height=250,
).add_selection(brush)
minsne1 = df["t-SNE axis 1"].min()
minsne2 = df["t-SNE axis 2"].min()
maxsne1 = df["t-SNE axis 1"].max()
maxsne2 = df["t-SNE axis 2"].max()
minpca1 = df["Principal component 1"].min()
minpca2 = df["Principal component 2"].min()
maxpca1 = df["Principal component 1"].max()
maxpca2 = df["Principal component 2"].max()
chart_tSNE = alt.Chart().mark_circle(size=30, strokeWidth=0.4).encode(
x=alt.X("t-SNE axis 1",
scale=alt.Scale(domain=[minsne1, maxsne1]),
axis=alt.Axis(ticks=False, labels=False, grid=False)),
y=alt.Y("t-SNE axis 2",
scale=alt.Scale(domain=[minsne2, maxsne2]),
axis=alt.Axis(ticks=False, labels=False, grid=False)),
color=color,
tooltip=['id', 'population', '1000G population code',
'1000G superpopulation code']
).properties(
width=250,
height=250,
).add_selection(brush)
chart_PCA = alt.Chart().mark_circle(size=30, strokeWidth=0.4).encode(
x=alt.X("Principal component 1",
scale=alt.Scale(domain=[minpca1, maxpca1]),
axis=alt.Axis(
ticks=False, labels=False, grid=False)),
y=alt.Y("Principal component 2",
scale=alt.Scale(domain=[minpca2, maxpca2]),
axis=alt.Axis(
ticks=False, labels=False, grid=False)),
color=color,
tooltip=['id', 'population', '1000G population code',
'1000G superpopulation code']
).properties(
width=250,
height=250,
).add_selection(brush)
legend = alt.Chart().mark_rect().encode(
y=alt.Y('population:N', axis=alt.Axis(orient='left', title="Populations")),
color=color
).add_selection(
selection
).transform_filter(brush)
hcharts = alt.hconcat(chart_GTM, chart_tSNE, chart_PCA, data=df)
chart = alt.hconcat(legend, chart, data=df)
vcharts = alt.vconcat(hcharts, chart, data=df)
vcharts.save(argv[2]+'.html')