def _recon_lca(self, coal_tree): # get coal tree, and LCA coal_recon coal_recon = phylo.reconcile(coal_tree, self._locus_tree, lambda x: x) # we do not explore the reconciliation space now self._coal_recon_enum = phylo.enum_recon(coal_tree, self._locus_tree, recon=coal_recon, depth=self._coal_recon_depth) return Recon(coal_tree, coal_recon, self._locus_tree, self._locus_recon, self._locus_events, self._daughters)
def _recon_lca(self, locus_tree): # get locus tree, and LCA locus_recon locus_recon = phylo.reconcile(locus_tree, self._stree, self._gene2species) locus_events = phylo.label_events(locus_tree, locus_recon) # propose LCA coal_recon coal_recon = phylo.reconcile(self._coal_tree, locus_tree, lambda x: x) # propose daughters (TODO) daughters = self._propose_daughters( self._coal_tree, coal_recon, locus_tree, locus_recon, locus_events) self._coal_recon_enum = phylo.enum_recon( self._coal_tree, locus_tree, recon=coal_recon, depth=self._coal_recon_depth) return Recon(coal_recon, locus_tree, locus_recon, locus_events, daughters)
def test_enum_recon(self): """Recon enumeration should always produce valid recons""" expected_recons = [ {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 1, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 1, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 1, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 1, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 1, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 1, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b'}, {'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 2, 'b': 'b'}, ] expected_events = [ {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'spec', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'spec', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'spec', 'b': 'gene'}, {'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'spec', 'b': 'gene'}, {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene'}, {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'spec', 'b': 'gene'}, {'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'spec', 'b': 'gene'}, ] tree = parse_newick("((a,b),(c,d))") stree = parse_newick("((a,b),(c,d))") gene2species = lambda x: x for i, (recon, events) in enumerate(phylo.enum_recon( tree, stree, depth=None, gene2species=gene2species)): phylo.assert_recon(tree, stree, recon) recon_names = dict((node.name, snode.name) for node, snode in recon.items()) event_names = dict((node.name, event) for node, event in events.items()) self.assertEqual(recon_names, expected_recons[i]) self.assertEqual(event_names, expected_events[i])
def test_enum_recon(self): """Recon enumeration should always produce valid recons""" expected_recons = [ { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 1, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 1, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 1, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 1, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 1, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 1, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 3, 'd': 'd', 2: 2, 'b': 'b' }, { 'a': 'a', 1: 1, 'c': 'c', 3: 1, 'd': 'd', 2: 2, 'b': 'b' }, ] expected_events = [ { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'spec', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'spec', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'spec', 'b': 'gene' }, { 'a': 'gene', 1: 'dup', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'spec', 'b': 'gene' }, { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'spec', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'dup', 'b': 'gene' }, { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'spec', 'b': 'gene' }, { 'a': 'gene', 1: 'spec', 'c': 'gene', 3: 'dup', 'd': 'gene', 2: 'spec', 'b': 'gene' }, ] tree = parse_newick("((a,b),(c,d))") stree = parse_newick("((a,b),(c,d))") gene2species = lambda x: x for i, (recon, events) in enumerate( phylo.enum_recon(tree, stree, depth=None, gene2species=gene2species)): phylo.assert_recon(tree, stree, recon) recon_names = dict( (node.name, snode.name) for node, snode in recon.items()) event_names = dict( (node.name, event) for node, event in events.items()) self.assertEqual(recon_names, expected_recons[i]) self.assertEqual(event_names, expected_events[i])