Permalink
Browse files

Fix childHeight bug, add papers using baltic.

  • Loading branch information...
evogytis committed Oct 4, 2018
1 parent dc9dce3 commit 3b472e9dc494c24d3e14105cdafdf5676f3f4922
Showing with 13 additions and 16 deletions.
  1. +4 −0 README.md
  2. +9 −16 baltic.py
@@ -98,6 +98,10 @@ for k in myTree.Objects:
--------------------
## baltic was used in the following publications:
- Bell SM, Katzelnick L, Bedford T, 2018. _Dengue antigenic relationships predict evolutionary dynamics_, __bioRxiv__ 432054; [doi](https://doi.org/10.1101/432054).
- Lee JM, Huddleston J, Doud MB, Hooper KA, Wu NC, Bedford T, Bloom JD, 2018. _Deep mutational scanning of hemagglutinin helps predict evolutionary fates of human H3N2 influenza variants_, __PNAS__ 115(35): 8276-8285.
- Dokubo EK, Wendland A, Mate SE, Ladner JT, ..., Palacios G, Fallah MP, 2018. _Persistence of Ebola virus after the end of widespread transmission in Liberia: an outbreak report_, __Lancet Infect Dis__ 18: 1015–1024.
- Venkatesh D, Poen MJ, Bestebroer TM, ..., Brown IH, Fouchier RAM, Lewis NS, 2018. _Avian influenza viruses in wild birds: virus evolution in a multi-host ecosystem_, __J Virol__ 92:e00433-18.
- Chu DKW, Hui Kenrie PY, Perera RAPM, Miguel E, Niemeyer D, Zhao J, Channappanavar R, Dudas G, Oladipo JO, Traoré A, Fassi-Fihri O, Ali A, Demissie GF, Muth D, Chan MCW, Nicholls JM, Meyerholz DK, Kuranga SA, Mamo G, Zhou Z, So RTY, Hemida MG, Webby RJ, Roger F, Rambaut A, Poon LLM, Perlman S, Drosten C, Chevalier V, Peiris M, 2018. _MERS coronaviruses from camels in Africa exhibit region-dependent genetic diversity_. __PNAS__ 115(12): 3144-3149.
- Whitmer SLM, Ladner JT, Wiley MR, Patel K, Dudas G, Rambaut A, Sahr F, Prieto K, Shepard SS, Carmody E, Knust B, Naidoo D, Deen G, Formenty P, Nichol ST, Palacios G, Ströher U, 2018. _Active Ebola Virus Replication and Heterogeneous Evolutionary Rates in EVD Survivors_. __Cell Reports__ 22(5): 1159-1168.
- Dudas G, Carvalho L, Rambaut A, Bedford T. _MERS-CoV spillover at the camel-human interface_, 2017. __eLife__ 7: e31257.
@@ -4,11 +4,6 @@
import datetime as dt
import json
def unique(o, idfun=repr):
"""Reduce a list down to its unique elements."""
seen = {}
return [seen.setdefault(idfun(e),e) for e in o if idfun(e) not in seen]
def decimalDate(date,fmt="%Y-%m-%d",variable=False,dateSplitter='-'):
""" Converts calendar dates in specified format to decimal date. """
if variable==True: ## if date is variable - extract what is available
@@ -243,7 +238,6 @@ def traverse_tree(self,startNode=None,include_all=False,verbose=False):
seen=[] ## remember what's been visited
collected=[] ## collect leaf objects along the way
maxHeight=0 ## check what the maximum distance between the root and the most recent tip is
if startNode!=None and startNode.height!=None:
height=startNode.height
else:
@@ -268,11 +262,9 @@ def traverse_tree(self,startNode=None,include_all=False,verbose=False):
while sum([1 if x.index in seen else 0 for x in cur_node.children])==len(cur_node.children) and cur_node!=startNode.parent:
if verbose==True:
print('seen all children of node %s'%(cur_node.index))
## check wheteher current node's most recent child is higher than the known highest point in the tree
if cur_node.childHeight <= highestTip:
cur_node.childHeight = highestTip
elif cur_node.childHeight > highestTip:
highestTip = cur_node.childHeight
## check wheteher current node's most recent child is higher than the parent's
if cur_node.parent and cur_node.childHeight > cur_node.parent.childHeight:
cur_node.parent.childHeight=cur_node.childHeight
if cur_node.index==startNode.index: ## if currently at root - set the root flag to True and break the while loop
if verbose==True:
@@ -285,7 +277,7 @@ def traverse_tree(self,startNode=None,include_all=False,verbose=False):
print('heading to parent of %s'%(cur_node.index))
cur_node.parent.numChildren+=cur_node.numChildren ## add the number of current node's children to its parent
cur_node.parent.leaves+=cur_node.leaves ## add the list of tip names descended from current node to its parent
cur_node.parent.leaves=unique(cur_node.parent.leaves) ## reduce to only unique names
cur_node.parent.leaves=list(set(cur_node.parent.leaves)) ## reduce to only unique names
cur_node.parent.leaves=sorted(cur_node.parent.leaves) ## sort children
cur_node.height=height ## set height
height-=float(cur_node.length) ## prepare height value for the eventual descent downwards in the tree
@@ -318,14 +310,15 @@ def traverse_tree(self,startNode=None,include_all=False,verbose=False):
#if cur_node not in collected: ## if leaf hasn't been collected - add it for reporting later
collected.append(cur_node)
if maxHeight<=float(cur_node.height): ## is this the highest point we've seen in the tree so far?
maxHeight=float(cur_node.height)
if cur_node.height>cur_node.parent.childHeight:
cur_node.parent.childHeight=cur_node.height
height-=float(cur_node.length) ## prepare for heading back
cur_node=cur_node.parent ## current node is now leaf's parent
self.treeHeight=float(maxHeight) ## tree height of this tree is the height of the highest tip
return unique(collected) ## return a list of collected leaf objects
self.treeHeight=max([k.childHeight for k in self.Objects if k.branchType=='node']) ## tree height of this tree is the height of the highest tip
return [k for k in collected if k in set(collected)] ## return a list of collected leaf objects
def renameTips(self,d=None):
""" Give each tip its correct label using a dictionary. """

0 comments on commit 3b472e9

Please sign in to comment.