Skip to content
Browse files

By default, read support values from node labels. Support values from…

… branch lengths or comments are available as options.
  • Loading branch information...
1 parent 754642a commit f382f550f49f73301663ad949a6c1e40f5d71c0c @bendmorris bendmorris committed with etal
Showing with 11 additions and 2 deletions.
  1. +7 −1 Bio/Phylo/NewickIO.py
  2. +2 −1 Tests/Nexus/test.new
  3. +2 −0 Tests/test_Phylo.py
View
8 Bio/Phylo/NewickIO.py
@@ -85,7 +85,7 @@ def from_string(cls, treetext):
handle = StringIO(treetext)
return cls(handle)
- def parse(self, values_are_confidence=False, comments_are_confidence=True, rooted=False):
+ def parse(self, values_are_confidence=False, comments_are_confidence=False, rooted=False):
"""Parse the text stream this object was initialized with."""
self.values_are_confidence = values_are_confidence
self.comments_are_confidence = comments_are_confidence
@@ -196,6 +196,12 @@ def new_clade(self, parent=None):
def process_clade(self, clade):
"""Final processing of a parsed clade. Removes the node's parent and
returns it."""
+ if (clade.name and not (self.values_are_confidence or self.comments_are_confidence)
+ and clade.confidence is None):
+ clade.confidence = _parse_confidence(clade.name)
+ if not clade.confidence is None:
+ clade.name = None
+
if hasattr(clade, 'parent'):
parent = clade.parent
parent.clades.append(clade)
View
3 Tests/Nexus/test.new
@@ -1 +1,2 @@
-((((((((((('Bos taurus',('Gazella dorcas',(('Capra hircus','Capra ibex')))),('Cervus elaphus',(('Rangifer tarandus','Odocoileus hemionus'),'Alces alces')))),'Sus scrofa'),('Camelus dromedarius','Lama glama')),'Equus caballus'[wild horse; also 'Equus ferus caballus']),('Canis lupus',(((((('Halichoerus grypus','Phoca groenlandica'),'Cystophora cristata'),'Erignathus barbatus'),(('Callorhinus ursinus','Arctocephalus australis'))),(('Mustela vison','Mephitis mephitis'))),('Ursus americanus'[American black bear],'Ursus arctos'[brown bear])))),'Phyllostomus hastatus'),('Homo sapiens'[modern human],((('Cavia porcellus',(('Rattus norvegicus'[brown rat],'Mus musculus'[house mouse])))),('Oryctolagus cuniculus','Lepus europaeus'))))),(('Macropus eugenii','Bettongia penicillata'),'Pseudocheirus peregrinus'))[100];
+80((((((((((('Bos taurus',('Gazella dorcas',(('Capra hircus','Capra ibex')))),('Cervus elaphus',(('Rangifer
+tarandus','Odocoileus hemionus'),'Alces alces')))),'Sus scrofa'),('Camelus dromedarius','Lama glama')),'Equus caballus'[wild horse; also 'Equus ferus caballus']),('Canis lupus',(((((('Halichoerus grypus','Phoca groenlandica'),'Cystophora cristata'),'Erignathus barbatus'),(('Callorhinus ursinus','Arctocephalus australis'))),(('Mustela vison','Mephitis mephitis'))),('Ursus americanus'[American black bear],'Ursus arctos'[brown bear])))),'Phyllostomus hastatus'),('Homo sapiens'[modern human],((('Cavia porcellus',(('Rattus norvegicus'[brown rat],'Mus musculus'[house mouse])))),('Oryctolagus cuniculus','Lepus europaeus'))))),(('Macropus eugenii','Bettongia penicillata'),'Pseudocheirus peregrinus'))[100];
View
2 Tests/test_Phylo.py
@@ -37,6 +37,8 @@ def test_newick_read_single(self):
self.assertEqual(len(tree.get_terminals()), 33)
self.assertEqual(tree.find_any('Homo sapiens').comment, 'modern human')
self.assertEqual(tree.find_any('Equus caballus').comment, "wild horse; also 'Equus ferus caballus'")
+ self.assertEqual(tree.root.confidence, 80)
+ tree = Phylo.read(EX_NEWICK2, 'newick', comments_are_confidence=True)
self.assertEqual(tree.root.confidence, 100)
tree = Phylo.read(EX_NEXUS2, 'nexus')

0 comments on commit f382f55

Please sign in to comment.
Something went wrong with that request. Please try again.