diff --git a/phylogenetic/defaults/clade-i/auspice_config.json b/phylogenetic/defaults/clade-i/auspice_config.json index a924efc..cfd44cd 100644 --- a/phylogenetic/defaults/clade-i/auspice_config.json +++ b/phylogenetic/defaults/clade-i/auspice_config.json @@ -21,6 +21,16 @@ "title": "Country", "type": "categorical" }, + { + "key": "division", + "title": "Province", + "type": "categorical" + }, + { + "key": "location", + "title": "Health Zone", + "type": "categorical" + }, { "key": "host", "title": "Host", @@ -53,13 +63,16 @@ } ], "geo_resolutions": [ - "country" + "region", + "country", + "division", + "location" ], "display_defaults": { "color_by": "country", "map_triplicate": true, "distance_measure": "num_date", - "transmission_lines": false + "transmission_lines": true }, "filters": [ "country", diff --git a/phylogenetic/defaults/clade-i/config.yaml b/phylogenetic/defaults/clade-i/config.yaml index ea40698..f5e61a7 100644 --- a/phylogenetic/defaults/clade-i/config.yaml +++ b/phylogenetic/defaults/clade-i/config.yaml @@ -45,8 +45,9 @@ clock_rate: 1.465e-06 clock_std_dev: 6.7e-07 divergence_units: "mutations" + traits: - columns: "country" + columns: region country sampling_bias_correction: 3 ## recency @@ -56,3 +57,6 @@ mask: from_beginning: 800 from_end: 6422 maskfile: "defaults/mask.bed" + +colors: + ignore_categories: "division location" diff --git a/phylogenetic/defaults/lat_longs.tsv b/phylogenetic/defaults/lat_longs.tsv index 5fe1b97..7aab9d4 100644 --- a/phylogenetic/defaults/lat_longs.tsv +++ b/phylogenetic/defaults/lat_longs.tsv @@ -26,3 +26,559 @@ country Central African Republic 6.207918975163378 20.72869278708794 region West Asia 34.604403366209084 43.32277708212641 country France 46.2276 2.2137 country Netherlands 52.1326 5.2913 + +division Bas-Uele 3.626 25.145 +division Equateur 0.229 18.914 +division Haut-Katanga -10.469 27.836 +division Haut-Lomami -8.237 25.429 +division Haut-Uele 3.345 28.588 +division Ituri 1.754 29.497 +division Kasai -4.947 21.106 +division Kasai-Central -6.226 22.489 +division Kasai-Oriental -6.151 23.519 +division Kinshasa -4.437 15.904 +division Kongo-Central -5.293 14.317 +division Kwango -6.434 17.865 +division Kwilu -4.783 18.655 +division Lomami -6.214 24.682 +division Lualaba -9.838 23.893 +division Maindombe -2.696 18.529 +division Maniema -3.085 26.423 +division Mongala 2.097 21.513 +division Nord Kivu -0.607 28.702 +division Nord-Ubangi 3.867 21.068 +division Sankuru -3.482 23.605 +division Sud Kivu -3.221 28.258 +division Sud-Ubangi 3.091 19.355 +division Tanganyika -6.567 28.2 +division Tshopo 0.481 25.207 +division Tshuapa -0.668 21.756 +division Yandongi 2.838 22.334 + +location Aba 3.664 30.301 +location Abuzi 3.366 22.146 +location Adi 3.469 30.725 +location Adja 3.058 30.431 +location Aketi 2.674 23.78 +location Alimbongo -0.367 28.917 +location Alunguli -2.952 25.958 +location Ango 4.475 26.069 +location Angumu 2.026 31.024 +location Ankoro -6.928 26.737 +location Ariwara 3.19 30.746 +location Aru 2.853 30.738 +location Aungba 2.598 30.597 +location Bafwagbogbo 1.456 26.537 +location Bafwasende 0.831 26.885 +location Bagata -3.776 17.897 +location Bagira -2.494 28.819 +location Baka -8.655 25.227 +location Bambo -1.21 29.243 +location Bambu 1.874 30.22 +location Banalia 1.806 25.678 +location Bandalungwa -4.347 15.281 +location Bandundu -3.498 17.48 +location Banga-Lubaka -5.621 20.528 +location Bangabola 2.3 19.401 +location Banjow-Moke -1.841 17.642 +location Barumbu -4.317 15.325 +location Basali 1.757 24.459 +location Basankusu 0.935 19.87 +location Basoko 1.363 23.637 +location Befale 0.58 20.886 +location Bena-Dibele -3.69 22.748 +location Bena-Leka -5.108 22.096 +location Bena-Tshiadi -4.551 22.807 +location Bengamisa 1.102 25.095 +location Beni 0.505 29.498 +location Bibanga -6.089 23.912 +location Biena 0.235 28.99 +location Bikoro -0.466 18.231 +location Bili 4.193 24.7 +location Bili2 4.794 19.715 +location Bilomba -6.546 22.267 +location Binga 2.15 20.41 +location Binza -0.816 29.52 +location Binza-Meteo -4.396 15.252 +location Binza-Ozone -4.348 15.235 +location Bipemba -6.09 23.574 +location Birambizo -1.219 29.118 +location Biringi 2.743 30.346 +location Biyela -4.445 15.407 +location Bobozo -5.965 22.391 +location Boende -0.337 20.772 +location Boga 0.982 29.991 +location Bogose-Nubea 3.793 19.726 +location Boko -4.937 16.697 +location Boko-Kivulu -5.317 15.021 +location Bokonzi 2.242 18.572 +location Bokoro -2.895 18.458 +location Bokenda 0.481 21.349 +location Bokungu -0.288 22.053 +location Bolenge -0.196 18.059 +location Bolobo -2.683 16.382 +location Bolomba 0.316 19.09 +location Boma -5.816 13.053 +location Boma-Bungu -5.748 12.979 +location Boma-Mangbetu 2.213 27.772 +location Bominenge 3.296 20.085 +location Bomongo 1.498 18.439 +location Bondo 4.091 23.764 +location Bongandanga 1.262 21.354 +location Bonzola -6.15 23.613 +location Bosomanzi 2.807 21.188 +location Boso-Mondanda 1.668 19.825 +location Bosobe -3.36 18.655 +location Bosobolo 4.355 19.852 +location Bosondjo 1.982 22.035 +location Boto 2.992 18.945 +location Budjala 2.466 19.703 +location Bukama -9.353 25.947 +location Bulape -4.368 21.755 +location Bulu 2.59 20.031 +location Bulungu -4.62 18.872 +location Bumba 2.244 22.707 +location Bumbu -4.372 15.294 +location Bunia 1.599 30.268 +location Bunkeya -10.271 26.794 +location Bunkonde -6.363 22.582 +location Bunyakiri -2.025 28.465 +location Busanga -0.953 21.995 +location Businga 3.196 21.398 +location Buta 2.726 25.008 +location Butembo 0.138 29.26 +location Butumba -8.931 26.414 +location Bwamanda 3.355 19.394 +location Cilundu -6.39 23.294 +location Citenge -6.138 23.738 +location Damas 2.185 30.179 +location Dekese -3.287 21.374 +location Demba -5.499 22.3 +location Dibaya -6.482 22.969 +location Dibindi -6.129 23.62 +location Dikungu -4.311 24.239 +location Dilala -10.575 25.234 +location Dilolo -10.611 22.626 +location Diulu -6.101 23.599 +location Djalo-Ndjeka -3.203 24.12 +location Djolu 0.361 22.68 +location Djombo 1.367 20.311 +location Djuma -4.201 18.592 +location Doruma 4.404 27.673 +location Drodro 1.745 30.562 +location Dungu 3.821 28.99 +location Faradje 3.751 29.831 +location Fataki 1.914 30.555 +location Ferekeni -1.755 26.176 +location Feshi -6.247 18.254 +location Fizi -4.394 28.942 +location Fungurume -10.725 26.27 +location Ganga 3.089 25.969 +location Gbadolite 4.29 20.874 +location Gemena 3.209 19.843 +location Gety 1.242 30.165 +location Goma -1.649 29.175 +location Gombari 2.747 28.99 +location Gombe -4.31 15.299 +location Gombe-Matadi -5.044 14.623 +location Gungu -5.946 19.31 +location Hauts-Plateaux -3.258 28.927 +location Ibanda -2.525 28.865 +location Iboko -0.981 18.555 +location Idiofa -5.075 19.468 +location Idjwi -2.03 29.043 +location Ikela -1.491 23.467 +location Ilebo -4.306 20.741 +location Inga -5.474 13.481 +location Ingende -0.49 18.817 +location Inongo -1.918 18.447 +location Ipamu -4.35 19.767 +location Irebu -0.744 17.67 +location Isangi 0.892 24.39 +location Isiro 2.468 27.293 +location Itebero -1.713 28.069 +location Itombwe -3.545 28.597 +location Jiba 1.837 30.727 +location Kabalo -6.243 26.882 +location Kabambare -4.672 28.059 +location Kabare -2.438 28.712 +location Kabeya-Kamwanga -5.968 23.167 +location Kabinda -6.253 24.443 +location Kabondo 0.631 25.383 +location Kabondo-Dianda -8.723 25.833 +location Kabongo -7.384 25.568 +location Kadutu -2.515 28.842 +location Kafakumba -9.399 23.78 +location Kafubu -11.53 28.012 +location Kahemba -7.183 19.312 +location Kailo -2.505 25.684 +location Kajiji -7.454 18.572 +location Kakenge -4.47 22.149 +location Kalamba -8.487 23.253 +location Kalambayi-Kabanga -6.733 24.399 +location Kalamu-I -4.352 15.313 +location Kalamu-II -4.35 15.32 +location Kalehe -2.052 28.744 +location Kalemie -6.291 28.864 +location Kalenda -7.435 23.448 +location Kalima -2.754 26.645 +location Kalole -3.618 27.566 +location Kalomba -6.785 21.678 +location Kalonda-Est -6.423 25.097 +location Kalonda-Ouest -6.105 20.844 +location Kalonge -2.329 28.484 +location Kalunguta 0.32 29.327 +location Kamalondo -11.684 27.486 +location Kamana -5.816 25.397 +location Kamango 0.66 29.846 +location Kambala 2.336 30.481 +location Kambove -10.774 26.792 +location Kamiji -6.719 23.224 +location Kamina -8.746 24.801 +location Kamituga -3.154 28.159 +location Kamonia -6.983 20.905 +location Kampemba -11.674 27.55 +location Kampene -3.505 26.481 +location Kamuesha -6.425 21.319 +location Kananga -5.928 22.432 +location Kanda-Kanda -6.92 23.754 +location Kangu -5.245 12.77 +location Kaniama -7.847 24.158 +location Kaniola -2.537 28.409 +location Kansele -6.116 23.61 +location Kansimba -7.299 29.101 +location Kanzala -6.521 20.816 +location Kanzenze -10.027 25.445 +location Kapanga -8.346 22.363 +location Kapolowe -11.214 27.09 +location Karawa 3.295 20.406 +location Karisimbi -1.639 29.199 +location Kasa-Vubu -4.342 15.305 +location Kasaji -10.501 23.599 +location Kasansa -6.561 23.616 +location Kasenga -10.713 28.283 +location Kashobwe -9.979 28.21 +location Kasongo -4.205 26.759 +location Kasongolunda -6.44 16.968 +location Katako-Kombe -3.03 24.733 +location Katana -2.218 28.785 +location Katende -5.461 22.92 +location Katoka -5.877 22.333 +location Katoyi -1.671 28.71 +location Katuba -11.723 27.455 +location Katwa 0.114 29.323 +location Kayamba -6.941 24.946 +location Kayna -0.609 29.088 +location Kaziba -2.86 28.824 +location Kenge -4.731 17.319 +location Kenya -11.74 27.509 +location Kiambi -7.35 28.125 +location Kibirizi -0.88 29.208 +location Kibombo -4.074 25.658 +location Kibua -1.226 28.473 +location Kibunzi -5.029 13.688 +location Kikimi -4.437 15.432 +location Kikongo -4.156 17.162 +location Kikula -10.498 27.261 +location Kikwit-Nord -5.021 18.856 +location Kikwit-Sud -5.068 18.796 +location Kilela-Balanda -11.596 26.649 +location Kilo 1.762 30.085 +location Kilwa -8.949 28.127 +location Kimbanseke -4.449 15.376 +location Kimbao -5.473 17.237 +location Kimbi-Lulenge -4.278 28.39 +location Kimpangu -5.746 14.929 +location Kimpese -5.446 14.308 +location Kimputu -4.458 19.399 +location Kimvula -5.465 16.03 +location Kinda -9.535 24.857 +location Kindu -2.951 25.901 +location Kingabwa -4.356 15.354 +location Kingandu -5.786 18.722 +location Kingasani -4.408 15.402 +location Kinkondja -8.281 26.273 +location Kinkonzi -4.816 13.149 +location Kinshasa -4.322 15.312 +location Kintambo -4.346 15.269 +location Kipushi -11.745 27.464 +location Kiri -1.837 19.244 +location Kirotshe -1.539 29.006 +location Kisanga -11.73 27.426 +location Kisangani 0.516 25.167 +location Kisanji -6.493 18.959 +location Kisantu -5.077 15.26 +location Kisenso -4.417 15.345 +location Kitangwa -6.476 20.085 +location Kitenda -7.025 17.273 +location Kitenge -6.78 25.861 +location Kitona -5.993 12.56 +location Kitutu -3.49 28.069 +location Kizu -5.024 12.98 +location Kokolo -4.333 15.295 +location Kole -3.675 22.263 +location Komanda 1.135 29.64 +location Kongolo -5.383 26.616 +location Koshibanda -5.13 19.887 +location Kowe -11.613 27.477 +location Kuimba -5.056 12.685 +location Kunda -3.915 26.279 +location Kungu 2.643 18.951 +location Kwamouth -3.589 16.66 +location Kwilu-Ngongo -5.519 14.689 +location Kyondo 0.01 29.512 +location Laybo 3.348 30.503 +location Lemba -4.403 15.321 +location Lemera -3.005 29.03 +location Libenge 4.113 19.039 +location Likasi -10.976 26.739 +location Likati 3.322 23.749 +location Lilanga-Bobangi 0.18 17.977 +location Limete -4.355 15.336 +location Linga 1.957 30.773 +location Lingomo 1.156 22.169 +location Lingwala -4.326 15.3 +location Lisala 2.28 21.234 +location Lita 1.583 30.373 +location Lodja -3.42 23.516 +location Logo 2.171 30.915 +location Loko 3.725 20.744 +location Lolanga-Mampoko 0.818 18.723 +location Lolo 2.319 23.219 +location Lolwa 1.531 29.507 +location Lomela -2.233 23.836 +location Lotumbe -0.706 19.646 +location Lowa -1.297 25.616 +location Lualaba -11.492 26.069 +location Luambo -7.424 22.062 +location Lubao -5.513 25.87 +location Lubero -0.185 28.984 +location Lubilanji -6.136 23.611 +location Lubondaie -6.71 22.798 +location Lubudi -10.078 26.107 +location Lubumbashi -11.576 27.472 +location Lubunga -5.522 23.405 +location Lubunga 0.414 25.13 +location Lubutu -0.616 26.852 +location Ludimbi-Lukula -5.71 24.489 +location Luebo -5.597 21.491 +location Luiza -7.029 22.494 +location Lukafu -10.671 27.676 +location Lukelenge -6.118 23.652 +location Lukolela -1.434 17.111 +location Lukonga -5.869 22.467 +location Lukula -5.452 12.874 +location Lulingu -2.325 27.333 +location Luozi -4.788 13.954 +location Luputa -7.485 23.787 +location Lusambo -5.033 23.322 +location Lusanga -5.064 18.761 +location Lusangi -4.68 27.225 +location Lwamba -7.711 26.365 +location Mabalako 0.499 29.171 +location Mahagi 2.31 30.942 +location Mai-Ndombe-I -4.03 15.747 +location Makala -4.381 15.308 +location Makanza 1.392 18.916 +location Makiso-Kisangani 0.511 25.246 +location Makoro 2.959 30.006 +location Makota -7.021 23.417 +location Malemba-Nkulu -7.953 26.71 +location Maluku-I -4.436 15.784 +location Maluku-II -4.489 16.156 +location Mambasa 1.45 28.701 +location Mandima 0.911 29.194 +location Mangala 1.985 30.423 +location Mangembo -4.584 14.233 +location Mangobo 0.54 25.154 +location Manguredjipa 0.393 28.447 +location Manika -11.001 25.6 +location Manono -7.215 27.305 +location Masa -4.661 15.328 +location Masereka -0.113 29.346 +location Masi-Manimba -4.933 17.764 +location Masina-I -4.381 15.379 +location Masina-II -4.392 15.406 +location Masisi -1.395 28.772 +location Masuika -7.582 22.514 +location Matadi -5.834 13.465 +location Matete -4.39 15.351 +location Mawuya 3.279 18.83 +location Mbandaka 0.22 18.392 +location Mbanza-Ngungu -5.262 14.809 +location Mbaya 2.683 20.369 +location Mbulula -5.323 27.353 +location Miabi -6.165 23.337 +location Mikalayi -6.03 22.113 +location Mikope -4.915 20.538 +location Mindembo -2.444 21.966 +location Mimia -2.597 20.188 +location Minembwe -4.024 28.567 +location Minga -4.872 24.124 +location Minova -1.79 28.933 +location Miti-Murhesa -2.329 28.861 +location Mitwaba -8.831 27.3 +location Moanda -5.819 12.473 +location Moanza -5.423 17.733 +location Moba -7.81 29.966 +location Mobayi-Mbongo 4.082 21.036 +location Mokala -3.999 19.041 +location Mompono 0.343 21.833 +location Mondombe -0.649 22.82 +location Monga 4.318 23.039 +location Mongbwalu 2.104 29.5 +location Monieka 0.059 20.018 +location Monkoto -1.675 20.914 +location Mont-Ngafula-I -4.549 15.281 +location Mont-Ngafula-II -4.433 15.194 +location Mosango -5.016 18.142 +location Mpokolo -6.084 23.544 +location Mubumbano -2.751 28.557 +location Muetshi -4.909 22.692 +location Mufunga-Sampwe -9.687 27.058 +location Mukanga -8.273 26.993 +location Mukedi -5.755 19.824 +location Mukumbi -5.878 23.589 +location Mulongo -7.8 27.371 +location Mulumba -6.599 23.866 +location Mulungu -2.602 27.946 +location Mumbunda -11.653 27.401 +location Mungindu -5.493 19.072 +location Mushenge -4.422 21.218 +location Mushie -2.541 17.202 +location Musienene 0.012 28.715 +location Mutena -7.023 21.389 +location Mutoto -5.624 22.641 +location Mutshatsha -10.69 24.684 +location Mutwanga 0.294 29.721 +location Muya -6.1 23.634 +location Mwana -2.913 28.702 +location Mweka -5.006 21.606 +location Mwela-Lembwa -6.17 17.683 +location Mwene-Ditu -6.931 23.414 +location Mwenga -3.086 28.525 +location Mweso -1.178 28.913 +location Ndage 2.737 20.702 +location Ndekesha -6.331 21.868 +location Ndesha -5.826 22.406 +location Ndjili -4.406 15.374 +location Ndjoko-Punda -5.694 21.072 +location Ngaba -4.38 15.323 +location Ngandajika -6.761 24.048 +location Ngidinga -5.636 15.483 +location Ngiri-Ngiri -4.357 15.299 +location Nia-Nia 1.315 27.97 +location Niangara 3.52 27.898 +location Nioki -2.9 17.677 +location Nizi 1.781 30.323 +location Nsele -4.423 15.567 +location Nselo -5.196 15.63 +location Nsona-Pangu -5.584 13.882 +location Ntandembelo -2.063 16.971 +location Ntondo -1.074 17.914 +location Nundu -3.734 28.952 +location Nyanga -6.044 20.383 +location Nyangezi -2.726 28.905 +location Nyankunde 1.473 29.948 +location Nyantende -2.592 28.867 +location Nyarambe 2.167 31.131 +location Nyemba -5.499 28.849 +location Nyirangongo -1.539 29.244 +location Nyunzu -5.749 27.941 +location Nzaba -6.136 23.551 +location Nzanza -5.829 13.413 +location Obokote -1.097 26.597 +location Oicha 0.752 29.614 +location Omendjadi -3.075 23.388 +location Opala -1.085 24.281 +location Opienge 0.084 27.457 +location Oshwe -3.558 19.785 +location Ototo -4.574 23.45 +location Panda -11.448 26.69 +location Pangi -3.159 26.607 +location Pania-Mutombo -5.224 23.833 +location Panzi -7.124 18.029 +location Pawa 2.343 27.61 +location Pay-Kongila -5.529 18.282 +location Pendjua -1.135 19.097 +location Pimu 1.804 21.113 +location Pinga -0.628 28.462 +location Poko 2.975 26.682 +location Popokabaka -5.648 16.602 +location Punia -1.698 27.01 +location Pweto -8.152 29.042 +location Rethy 2.075 30.741 +location Rimba 2.221 30.754 +location Rungu 2.845 27.974 +location Rutshuru -1.279 29.385 +location Ruzizi -3.118 29.166 +location Rwampara 1.581 30.14 +location Rwanguba -1.253 29.52 +location Rwashi -11.673 27.609 +location Sakania -12.571 28.927 +location Samba -4.724 26.309 +location Sandoa -9.471 22.591 +location Saramabila -4.151 27.39 +location Seke-Banza -5.186 13.301 +location Selembao -4.406 15.277 +location Shabunda -2.875 27.299 +location Sia -3.774 18.473 +location Sona-Bata -4.824 15.262 +location Songa -7.986 25.049 +location Sud Kivu -3.221 28.258 +location Tandala 2.977 19.533 +location Tchomia 1.482 30.458 +location Tembo -7.656 17.592 +location Titule 2.961 25.487 +location Tshamilemba -11.618 27.539 +location Tshela -4.883 12.885 +location Tshibala -6.891 21.999 +location Tshikaji -5.993 22.466 +location Tshikapa -6.647 20.551 +location Tshikula -6.038 22.758 +location Tshilenge -6.301 23.706 +location Tshishimbi -6.191 23.485 +location Tshofa -5.24 24.994 +location Tshopo 0.868 25.545 +location Tshudi-Loto -2.45 22.608 +location Tshumbe -4.686 24.653 +location Tunda -4.062 25.135 +location Ubundu -0.489 25.089 +location Uvira -3.408 29.097 +location Vaku -5.18 13.028 +location Vanga -4.484 18.378 +location Vanga-Kete -3.847 23.453 +location Vangu -11.619 27.482 +location Viadana 3.2 27.328 +location Vuhovi 0.19 29.452 +location Walikale -1.129 27.804 +location Walungu -2.634 28.696 +location Wamba 2.026 27.904 +location Wamba-Lwadi -6.348 17.339 +location Wangata 0.054 18.231 +location Wanie-Rukula 0.111 25.98 +location Wapinda 3.709 22.94 +location Wasolo 3.768 22.093 +location Watsa 2.75 29.665 +location Wema -0.795 21.336 +location Wembo-Nyama -4.047 24.673 +location Wikong -7.858 23.312 +location Yabaondo 0.661 23.955 +location Yahisuli -0.018 23.907 +location Yahuma 0.776 23.138 +location Yakoma 4.033 22.204 +location Yakusu 0.664 24.651 +location Yaleko 0.034 24.58 +location Yalifafu -1.36 22.433 +location Yalimbongo 1.925 23.471 +location Yalufi 0.725 24.425 +location Yamaluka 2.425 22.177 +location Yambuku 2.839 22.335 +location Yandongi 2.838 22.334 +location Yamongili 2.55 22.768 +location Yangala -7.388 22.974 +location Yangambi 0.802 24.459 +location Yasa-Bonga -4.48 17.925 +location Yelenge 0.57026 25.03594 +location Yumbi -2.151 16.522 +location Zongo 4.22 18.695 \ No newline at end of file diff --git a/phylogenetic/rules/annotate_phylogeny.smk b/phylogenetic/rules/annotate_phylogeny.smk index 6a15627..9dea6a3 100644 --- a/phylogenetic/rules/annotate_phylogeny.smk +++ b/phylogenetic/rules/annotate_phylogeny.smk @@ -116,6 +116,8 @@ rule rename_clades: build_dir + "/{build_name}/clades_raw.json", output: node_data=build_dir + "/{build_name}/clades.json", + wildcard_constraints: + build_name="(?!clade-i).*", shell: """ python scripts/clades_renaming.py \ @@ -124,6 +126,27 @@ rule rename_clades: """ +rule assign_clades_via_metadata: + """ + For clade-i builds run a custom script rather than using `augur clades` as that approach can't reliably + identify basal clades due to the stochastic way `augur ancestral` assigns mutations on basal branches + """ + input: + metadata=build_dir + "/{build_name}/metadata.tsv", + tree=build_dir + "/{build_name}/tree.nwk", + output: + node_data=build_dir + "/{build_name}/clades.json", + wildcard_constraints: + build_name="clade-i", + shell: + r""" + python scripts/assign-clades-via-metadata.py \ + --metadata {input.metadata} \ + --tree {input.tree} \ + --output-node-data {output.node_data} + """ + + rule mutation_context: input: tree=build_dir + "/{build_name}/tree.nwk", diff --git a/phylogenetic/rules/export.smk b/phylogenetic/rules/export.smk index 1501eb2..e814c22 100644 --- a/phylogenetic/rules/export.smk +++ b/phylogenetic/rules/export.smk @@ -48,12 +48,17 @@ rule colors: metadata=build_dir + "/{build_name}/metadata.tsv", output: colors=build_dir + "/{build_name}/colors.tsv", + params: + ignore_categories=lambda w: config.get("colors", {}).get( + "ignore_categories", "" + ), shell: - """ + r""" python3 scripts/assign-colors.py \ --ordering {input.ordering} \ --color-schemes {input.color_schemes} \ --output {output.colors} \ + --ignore-categories {params.ignore_categories} \ --metadata {input.metadata} 2>&1 """ diff --git a/phylogenetic/scripts/assign-clades-via-metadata.py b/phylogenetic/scripts/assign-clades-via-metadata.py new file mode 100644 index 0000000..bc8738e --- /dev/null +++ b/phylogenetic/scripts/assign-clades-via-metadata.py @@ -0,0 +1,63 @@ +""" +Use provided metadata to assign clade to terminal nodes. If the metadata is complete (i.e. all tips are assigned a clade) +then for each clade we assign the clade to internal nodes and set a label for the MRCA node, iff the tips are monophyletic. +""" + +import argparse +from sys import stderr, stdout, exit +from Bio import Phylo +import json +from augur.io import read_metadata +from augur.argparse_ import ExtendOverwriteDefault +from collections import defaultdict + + +def assign_internal_nodes(clade_name, terminal_nodes, node_data): + print(f"Assigning {clade_name} to internal nodes") + mrca = t.is_monophyletic(terminal_nodes) + if not mrca: + print(f"WARNING: {clade_name} wasn't monophyletic! Clades will not be assigned to internal nodes") + return + for node in mrca.get_nonterminals(): + node_data['nodes'][node.name] = {'clade_membership': clade_name} + node_data['branches'][mrca.name] = {'labels': {'clade': clade_name}} + +if __name__=="__main__": + parser = argparse.ArgumentParser(description = __doc__) + parser.add_argument('--metadata', required=True, type=str, help="Metadata TSV") + parser.add_argument('--clade-column', required=False, type=str, default='clade', help="Column name in the metadata TSV where clade is defined") + parser.add_argument('--metadata-id-columns', default=['accession'], nargs="+", action=ExtendOverwriteDefault, help="names of possible metadata columns containing identifier information, ordered by priority. Only one ID column will be inferred.") + parser.add_argument('--tree', required=True, type=str, help="Newick tree") + parser.add_argument('--output-node-data', required=True, type=str, help="Node-data JSON") + args = parser.parse_args() + + metadata = read_metadata(args.metadata, id_columns=args.metadata_id_columns) + try: + clades = metadata[args.clade_column] + except KeyError: + print("Column {args.clade_column} not found in provided metadata {args.metadata}") + exit(2) + + t = Phylo.read(args.tree, "newick") + + node_data = {'nodes': {}, 'branches': {}} + counts = [0,0] + terminals = defaultdict(list) + + for node in t.get_terminals(): + counts[0]+=1 + if node.name in clades: + counts[1]+=1 + node_data['nodes'][node.name] = {'clade_membership': clades[node.name]} + terminals[clades[node.name]].append(node) + + print(f"Metadata defined clades for {counts[1]}/{counts[0]} tips in tree", file=stderr) + + if counts[0]==counts[1]: + for clade_name, clade_terminals in terminals.items(): + assign_internal_nodes(clade_name, clade_terminals, node_data) + else: + print(f"WARNING: incomplete metadata. Assignment of clade labels is uncertain and thus we are skipping it") + + with open(args.output_node_data, 'w') as fh: + json.dump(node_data, fh) diff --git a/phylogenetic/scripts/assign-colors.py b/phylogenetic/scripts/assign-colors.py index e7587f5..3e400c2 100644 --- a/phylogenetic/scripts/assign-colors.py +++ b/phylogenetic/scripts/assign-colors.py @@ -16,6 +16,8 @@ parser.add_argument('--color-schemes', type=str, required=True, help="input color schemes file") parser.add_argument('--metadata', type=str, help="if provided, restrict colors to only those found in metadata") parser.add_argument('--output', type=str, required=True, help="output colors tsv") + parser.add_argument('--ignore-categories', type=str, required=False, nargs='*', + help="Do not create colors for these categories") args = parser.parse_args() assignment = {} @@ -25,6 +27,8 @@ if len(array) == 2: name = array[0] trait = array[1] + if name in args.ignore_categories: + continue if name not in assignment: assignment[name] = [trait] else: