Skip to content

Commit

Permalink
add first pandemic to multi plot
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmeaton committed Aug 4, 2021
1 parent 8596622 commit fd67797
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 13 deletions.
43 changes: 42 additions & 1 deletion workflow/notebooks/beast_auspice_clade.py.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"{'country': {'India': '#8000ff', 'Kazakhstan': '#7215ff', 'Iran': '#652afe', 'Democratic Republic of the Congo': '#573ffd', 'Indonesia': '#4a53fc', 'England': '#3c66fa', 'Mongolia': '#2f79f7', 'Canada': '#228bf4', 'Switzerland': '#149df1', 'Italy': '#07adee', 'Germany': '#07bcea', 'Kenya': '#14c9e5', 'Zimbabwe': '#22d5e0', 'Brazil': '#2fe0db', 'United States of America': '#3cead5', 'Turkmenistan': '#4af1d0', 'Kyrgyzstan': '#57f7c9', 'Bolivia': '#65fcc3', 'Russia': '#72febc', 'Georgia': '#80ffb4', 'Madagascar': '#8dfead', 'Tajikistan': '#9afca5', 'China': '#a8f79d', 'Uganda': '#b5f194', 'Uzbekistan': '#c3ea8b', 'Nepal': '#d0e083', 'Vietnam': '#ddd579', 'Algeria': '#ebc970', 'Norway': '#f8bc66', 'Myanmar': '#ffad5d', 'Peru': '#ff9d53', 'Poland': '#ff8b49', 'Armenia': '#ff793f', 'The Netherlands': '#ff6634', 'Lithuania': '#ff532a', 'France': '#ff3f20', 'Spain': '#ff2a15', 'Azerbaijan': '#ff150b', 'Estonia': '#ff0000', 'NA': '#969696'}, 'province': {'Shymkent': '#8000ff', 'California': '#7b07ff', 'Qazakh District': '#760eff', 'Maharashtra': '#7215ff', 'Altai Republic': '#6d1cff', 'Ingushetia': '#6923fe', 'Central Java': '#642afe', 'Zavkhan Province': '#6031fe', 'La Libertad': '#5b38fd', 'Texas': '#573ffd', 'Xinjiang': '#5246fd', 'Nagorno-Karabakh Republic': '#4e4dfc', 'Talas Region': '#4954fb', 'Sečuán': '#455afb', 'Övörkhangai': '#4061fa', 'Shirak Province': '#3c67f9', 'Pärnu maakond': '#376ef9', 'Midlands': '#3374f8', 'Bayan-Ölgii': '#2e7af7', 'Kabardino-Balkaria': '#2a81f6', 'Brandenburg': '#2587f5', 'West Kazakhstan region': '#218df4', 'Karachay-Cherkessia': '#1c92f3', 'Shamkir District': '#1898f2', 'Cajamarca': '#139ef1', 'Gandaki Pradesh': '#0fa3f0', 'Nidwalden': '#0aa9ef', 'State of Mato Grosso': '#06aeed', 'New Mexico': '#01b3ec', 'Goranboy District': '#03b8eb', 'East of England': '#08bde9', 'Tatarstan': '#0cc2e8', 'Colorado': '#11c6e6', 'Rostov Oblast': '#15cae5', 'Navoiy Region': '#1acfe3', 'Ömnögovi': '#1ed3e1', 'Atyrau': '#23d7e0', 'Nairobi': '#27dade', 'Province de Fianarantsoa': '#2cdedc', 'Krasnoyarsk Krai': '#31e1da', 'Inner Mongolia': '#35e5d9', 'Greater London': '#3ae8d7', 'Jilin': '#3eebd5', 'Dornogovi': '#43edd3', 'Osh Region': '#47f0d1', 'Lazio': '#4cf2cf', 'Ningxia': '#50f4cd', 'Gansu': '#55f6ca', 'Qinghai': '#59f8c8', 'Occitanie': '#5ef9c6', 'Shaanxi': '#62fbc4', 'St. Petersberg': '#67fcc2', 'Gujarat': '#6bfdbf', 'Almaty Region': '#70febd', 'Saskatchewan': '#74feba', 'Vilnius County': '#79ffb8', 'Khánh Hoà Province': '#7dffb6', 'NA': '#969696', 'Stavropol Krai': '#86ffb1', 'Baden-Württemberg': '#8bfeae', 'Himachal Pradesh': '#8ffeab', 'MSila': '#94fda9', 'Guangxi Zhuang': '#98fca6', 'Fizuli District': '#9dfba3', 'Nevada': '#a1f9a1', 'Mangystau Province': '#a6f89e', 'Balkan': '#aaf69b', 'Valencia Community': '#aff498', 'Kyzylorda Province': '#b3f295', 'Tamil Nadu': '#b8f092', 'Tibet': '#bced90', 'Republic of Dagestan': '#c1eb8d', 'Khovd': '#c5e88a', 'Govi-Altai': '#cae587', 'Heilongjiang': '#cee184', 'Tuva Republic': '#d3de81', 'Issyk-Kul Region': '#d8da7d', 'Irkutsk Oblast': '#dcd77a', 'Samtskhe-Javakheti': '#e1d377', 'West Kazakhstan Region': '#e5cf74', 'Samara Oblast': '#eaca71', 'Aktobe Region': '#eec66e', 'Chechnya': '#f3c26b', 'Atyrau Region': '#f7bd67', 'Kyzylorda Region': '#fcb864', 'Oslo': '#ffb361', 'Yunnan': '#ffae5d', 'Republic of Kalmykia': '#ffa95a', 'Altai Krai': '#ffa357', 'Centre-Loire Valley': '#ff9e54', 'Panevezys County': '#ff9850', 'Baku': '#ff924d', 'La Paz': '#ff8d49', 'Arizona': '#ff8746', 'Hovsgel': '#ff8143', 'Sughd Province': '#ff7a3f', 'Bavaria': '#ff743c', 'Naryn Region': '#ff6e38', 'Ho Chi Minh City': '#ff6735', 'Hebei': '#ff6131', 'Lâm Đồng Province': '#ff5a2e', 'Catalonia': '#ff542a', 'Astrakhan Oblast': '#ff4d27', 'Pomeranian Voivodeship': '#ff4623', 'Fujian': '#ff3f20', 'Bayankhongor': '#ff381c', 'Kurdistan': '#ff3119', \"Provence-Alpes-Côte d'Azur\": '#ff2a15', 'Zabaykalsky Krai': '#ff2312', 'Shahbuz Rayon': '#ff1c0e', 'Syunik Province': '#ff150b', 'Kirov Oblast': '#ff0e07', 'North Brabant': '#ff0704', 'Gegharkunik Province': '#ff0000'}, 'branch_major': {'0.PRE': '#8000ff', '0.PE': '#5148fc', '0.ANT4': '#238af5', '0.ANT': '#0cc1e8', '3.ANT': '#3ae8d7', '4.ANT': '#68fcc1', '2.ANT': '#97fca7', '2.MED': '#c5e88a', '1.PRE': '#f3c16a', '1.ANT': '#ff8a48', '1.IN': '#ff4824', '1.ORI': '#ff0000', 'NA': '#969696'}, 'branch_minor': {'1.IN3': '#8000ff', '1.IN1': '#7116ff', '0.ANT2': '#632cfe', '0.ANT1': '#5542fd', '4.ANT1': '#4757fb', '0.PE4t': '#396cf9', '1.ORI2': '#2b7ff6', '1.PRE3': '#1c92f3', '0.ANT3': '#0ea4f0', '0.PE4m': '#00b4ec', '3.ANT1': '#0ec3e7', '1.PRE2': '#1cd1e2', '1.ORI1': '#2adddd', '0.PE4h': '#39e7d7', '0.PE4a': '#47f0d1', '3.ANT2': '#55f6ca', '2.ANT3': '#63fbc3', '0.PRE1': '#71febc', '1.PRE1': '#80ffb4', '1.PRE0': '#8efeac', '2.MED0': '#9cfba4', '0.ANT5': '#aaf69b', '0.ANT4': '#b8f092', '2.MED2': '#c6e789', '2.MED1': '#d4dd80', '2.MED3': '#e3d176', '0.PE5': '#f1c36c', '1.ORI3': '#ffb462', '2.ANT2': '#ffa457', '0.PE7': '#ff924d', '0.PE10': '#ff8042', '0.PRE2': '#ff6c37', '0.PE8': '#ff572c', '1.ANT1': '#ff4221', '2.ANT1': '#ff2c16', '0.PE2': '#ff160b', '1.IN2': '#ff0000', 'NA': '#969696'}, 'continent': {'South America': '#8000ff', 'Europe': '#00b4ec', 'North America': '#80ffb4', 'Africa': '#ffb462', 'Asia': '#ff0000', 'NA': '#969696'}}\n"
"{'country': {'Kyrgyzstan': '#8000ff', 'Uzbekistan': '#7215ff', 'Myanmar': '#652afe', 'France': '#573ffd', 'England': '#4a53fc', 'Tajikistan': '#3c66fa', 'Algeria': '#2f79f7', 'Armenia': '#228bf4', 'Canada': '#149df1', 'Lithuania': '#07adee', 'Azerbaijan': '#07bcea', 'Zimbabwe': '#14c9e5', 'Brazil': '#22d5e0', 'Germany': '#2fe0db', 'Iran': '#3cead5', 'Bolivia': '#4af1d0', 'Norway': '#57f7c9', 'Spain': '#65fcc3', 'Poland': '#72febc', 'Kazakhstan': '#80ffb4', 'Mongolia': '#8dfead', 'Georgia': '#9afca5', 'Turkmenistan': '#a8f79d', 'Vietnam': '#b5f194', 'Kenya': '#c3ea8b', 'Switzerland': '#d0e083', 'China': '#ddd579', 'Nepal': '#ebc970', 'Indonesia': '#f8bc66', 'India': '#ffad5d', 'Russia': '#ff9d53', 'Uganda': '#ff8b49', 'Italy': '#ff793f', 'Democratic Republic of the Congo': '#ff6634', 'The Netherlands': '#ff532a', 'Estonia': '#ff3f20', 'United States of America': '#ff2a15', 'Peru': '#ff150b', 'Madagascar': '#ff0000', 'NA': '#969696'}, 'province': {'Shaanxi': '#8000ff', 'Hovsgel': '#7b07ff', 'Tibet': '#760eff', 'Almaty Region': '#7215ff', 'Xinjiang': '#6d1cff', 'Krasnoyarsk Krai': '#6923fe', 'Shymkent': '#642afe', 'Talas Region': '#6031fe', 'Cajamarca': '#5b38fd', 'Greater London': '#573ffd', 'Kurdistan': '#5246fd', 'Brandenburg': '#4e4dfc', 'Khovd': '#4954fb', 'Texas': '#455afb', 'Lazio': '#4061fa', 'Midlands': '#3c67f9', 'Bavaria': '#376ef9', 'Baku': '#3374f8', 'Gegharkunik Province': '#2e7af7', 'Zabaykalsky Krai': '#2a81f6', 'Shahbuz Rayon': '#2587f5', 'Nidwalden': '#218df4', 'Tamil Nadu': '#1c92f3', 'Govi-Altai': '#1898f2', 'Qazakh District': '#139ef1', 'Kyzylorda Region': '#0fa3f0', 'Mangystau Province': '#0aa9ef', 'Astrakhan Oblast': '#06aeed', 'Rostov Oblast': '#01b3ec', 'Central Java': '#03b8eb', 'Syunik Province': '#08bde9', 'Centre-Loire Valley': '#0cc2e8', 'Osh Region': '#11c6e6', 'Lâm Đồng Province': '#15cae5', 'West Kazakhstan region': '#1acfe3', 'Issyk-Kul Region': '#1ed3e1', 'Kabardino-Balkaria': '#23d7e0', 'Irkutsk Oblast': '#27dade', 'Yunnan': '#2cdedc', 'Fujian': '#31e1da', 'Saskatchewan': '#35e5d9', 'Catalonia': '#3ae8d7', 'Nevada': '#3eebd5', 'California': '#43edd3', 'Panevezys County': '#47f0d1', 'NA': '#969696', 'State of Mato Grosso': '#50f4cd', 'Ömnögovi': '#55f6ca', 'Heilongjiang': '#59f8c8', 'Province de Fianarantsoa': '#5ef9c6', 'Pomeranian Voivodeship': '#62fbc4', 'East of England': '#67fcc2', \"Provence-Alpes-Côte d'Azur\": '#6bfdbf', 'New Mexico': '#70febd', 'La Libertad': '#74feba', 'Kyzylorda Province': '#79ffb8', 'Baden-Württemberg': '#7dffb6', 'Sughd Province': '#82ffb3', 'North Brabant': '#86ffb1', 'Tatarstan': '#8bfeae', 'Tuva Republic': '#8ffeab', 'Övörkhangai': '#94fda9', 'Altai Republic': '#98fca6', 'Vilnius County': '#9dfba3', 'Colorado': '#a1f9a1', 'Republic of Dagestan': '#a6f89e', 'Inner Mongolia': '#aaf69b', 'Samtskhe-Javakheti': '#aff498', 'Sečuán': '#b3f295', 'Shirak Province': '#b8f092', 'Himachal Pradesh': '#bced90', 'Hebei': '#c1eb8d', 'MSila': '#c5e88a', 'St. Petersberg': '#cae587', 'Goranboy District': '#cee184', 'Occitanie': '#d3de81', 'Karachay-Cherkessia': '#d8da7d', 'Gujarat': '#dcd77a', 'Naryn Region': '#e1d377', 'Khánh Hoà Province': '#e5cf74', 'Shamkir District': '#eaca71', 'Ho Chi Minh City': '#eec66e', 'Altai Krai': '#f3c26b', 'Ingushetia': '#f7bd67', 'Valencia Community': '#fcb864', 'Oslo': '#ffb361', 'Maharashtra': '#ffae5d', 'Gansu': '#ffa95a', 'Stavropol Krai': '#ffa357', 'Jilin': '#ff9e54', 'Atyrau Region': '#ff9850', 'Guangxi Zhuang': '#ff924d', 'Republic of Kalmykia': '#ff8d49', 'Nagorno-Karabakh Republic': '#ff8746', 'Qinghai': '#ff8143', 'Zavkhan Province': '#ff7a3f', 'Aktobe Region': '#ff743c', 'Gandaki Pradesh': '#ff6e38', 'Navoiy Region': '#ff6735', 'Fizuli District': '#ff6131', 'Nairobi': '#ff5a2e', 'Samara Oblast': '#ff542a', 'Balkan': '#ff4d27', 'Bayan-Ölgii': '#ff4623', 'Chechnya': '#ff3f20', 'Atyrau': '#ff381c', 'Kirov Oblast': '#ff3119', 'Ningxia': '#ff2a15', 'Arizona': '#ff2312', 'La Paz': '#ff1c0e', 'West Kazakhstan Region': '#ff150b', 'Dornogovi': '#ff0e07', 'Bayankhongor': '#ff0704', 'Pärnu maakond': '#ff0000'}, 'branch_major': {'0.PRE': '#8000ff', '0.PE': '#5148fc', '0.ANT4': '#238af5', '0.ANT': '#0cc1e8', '3.ANT': '#3ae8d7', '4.ANT': '#68fcc1', '2.ANT': '#97fca7', '2.MED': '#c5e88a', '1.PRE': '#f3c16a', '1.ANT': '#ff8a48', '1.IN': '#ff4824', '1.ORI': '#ff0000', 'NA': '#969696'}, 'branch_minor': {'0.PE4m': '#8000ff', '0.PE4a': '#7116ff', '0.PE2': '#632cfe', '1.PRE0': '#5542fd', '0.PE7': '#4757fb', '0.PE4t': '#396cf9', '3.ANT2': '#2b7ff6', '1.ORI3': '#1c92f3', '0.ANT5': '#0ea4f0', '1.PRE2': '#00b4ec', '1.PRE1': '#0ec3e7', '0.PE4h': '#1cd1e2', '1.ORI2': '#2adddd', '0.PE8': '#39e7d7', '0.PRE1': '#47f0d1', '2.ANT1': '#55f6ca', '3.ANT1': '#63fbc3', '1.IN2': '#71febc', '0.ANT2': '#80ffb4', '2.MED2': '#8efeac', '1.ANT1': '#9cfba4', '2.MED1': '#aaf69b', '0.PE10': '#b8f092', '0.ANT1': '#c6e789', '2.ANT3': '#d4dd80', '4.ANT1': '#e3d176', '2.MED0': '#f1c36c', '1.IN1': '#ffb462', '1.PRE3': '#ffa457', '0.PRE2': '#ff924d', '1.ORI1': '#ff8042', '2.ANT2': '#ff6c37', '0.ANT3': '#ff572c', '0.ANT4': '#ff4221', '0.PE5': '#ff2c16', '1.IN3': '#ff160b', '2.MED3': '#ff0000', 'NA': '#969696'}, 'continent': {'North America': '#8000ff', 'Europe': '#00b4ec', 'South America': '#80ffb4', 'Asia': '#ffb462', 'Africa': '#ff0000', 'NA': '#969696'}}\n"
]
}
],
Expand Down Expand Up @@ -1379,6 +1379,47 @@
" #display(df)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "surface-confidentiality",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"branch\thigh\tinternal\t% high\n",
"1.ORI\t102\t116\t88.0\n",
"1.PRE\t17\t39\t44.0\n",
"2.MED\t80\t115\t70.0\n",
"0.ANT4\t8\t11\t73.0\n",
"0.PRE\t3\t7\t43.0\n"
]
}
],
"source": [
"## State Confidence Summary\n",
"print(\"{}\\t{}\\t{}\\t{}\".format(\"branch\", \"high\", \"internal\", \"% high\" ))\n",
"for branch in tree_dict:\n",
" \n",
" tree = tree_dict[branch][\"tree\"]\n",
" df = tree_dict[branch][\"df\"]\n",
" internal_nodes = 0\n",
" high_state_prob = 0\n",
" \n",
" for rec in df.iterrows():\n",
" sample = rec[0]\n",
" # Focus on internal branches\n",
" if rec[1][\"node_type\"] == \"terminal\": continue\n",
" state_prob = rec[1][\"state_prob\"]\n",
" internal_nodes += 1\n",
" if state_prob >= 95:\n",
" high_state_prob += 1\n",
" perc = round((high_state_prob / internal_nodes) * 100, 0)\n",
" print(\"{}\\t{}\\t{}\\t{}\".format(branch, high_state_prob, internal_nodes, perc))"
]
},
{
"cell_type": "markdown",
"id": "robust-tracker",
Expand Down
53 changes: 41 additions & 12 deletions workflow/scripts/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,64 @@
from pyppeteer import launch
import time

# dataset = (
# "https://nextstrain.org/community/" +
# "ktmeaton/plague-phylogeography-projects@main/main/full/all"
# )
# query = "?d=tree&legend=open&m=div&onlyPanels&p=full&sidebar=closed"
# ------------------------------------------
# URL Construction

# LOCAL
dataset = "http://localhost:4000/1.PRE"
query = "?c=date_mean&d=map&m=div&onlyPanels&p=full&sidebar=closed&tl=blank"
url = dataset + query
clade = "1.ORI"
dataset = "main/beast/geo/" + clade
geo_res = "province"
color = "continent"
panel = "map"
transmissions = "show"
repo = "plague-phylogeography-projects"
base_url = "https://nextstrain.org/community/ktmeaton"
branch = "main"

project = base_url + "/" + repo + "@" + branch + "/" + dataset
options = [
"r=" + geo_res,
"c=" + color,
"d=" + panel,
"sidebar=closed",
"transmissions=" + transmissions,
"legend=closed",
"p=full",
"onlyPanels",
]
query = "?" + "&".join(options)
url = project + query

output = "{}_{}_{}.pdf".format(clade, panel, color)

print(url)
print()

wait = 10
width = 450
height = 450
width = 720
height = 720
options = {
"path": output,
"format": "A0",
"printBackground": True,
"landscape": True,
}


async def main():
browser = await launch()
page = await browser.newPage()

await page.setViewport({"width": width, "height": height, "deviceScaleFactor": 4})
print("Waiting {} seconds for Nextstrain to load page...".format(wait))

# Navigate to page
await page.goto(url)
# Change to landscape
time.sleep(wait)
print("Taking a pdf screenshot...")
await page.emulateMedia("screen")
await page.pdf({"path": "screenshot.pdf"})
await page.pdf(options)
print("Saved screenshot to " + output)
await browser.close()


Expand Down

0 comments on commit fd67797

Please sign in to comment.