예제 #1
0
 def evolve_to_current_time(node, finalize=False):
     if node is None:
         return
     viruses = [virus for virus in node.viruses()]
     for virus in viruses:
         time = GC.time - virus.get_time()
         if time > 0:
             node.remove_virus(virus)
             try:
                 command = [
                     GC.dualbirth_path,
                     str(GC.rate_A),
                     str(GC.rate_B), '-t',
                     str(time)
                 ]
                 if GC.random_number_seed is not None:
                     command += ['-s', str(GC.random_number_seed)]
                     GC.random_number_seed += 1
                 treestr = check_output(command).decode()
             except FileNotFoundError:
                 from os import chdir
                 chdir(GC.START_DIR)
                 assert False, "dualbirth executable was not found: %s" % GC.dualbirth_path
             tree = read_tree_newick(treestr)
             virus.set_time(virus.get_time() + tree.root.edge_length)
             for c in tree.root.children:
                 GC.treenode_add_child(virus, c, node)
예제 #2
0
 def evolve_to_current_time(node, finalize=False):
     viruses = [virus for virus in node.viruses()]
     for virus in viruses:
         time = GC.time - virus.get_time()
         if time > 0:
             node.remove_virus(virus)
             success = False
             for _ in range(100):
                 tree = birth_death_tree(GC.bd_birth,
                                         GC.bd_death,
                                         birth_rate_sd=GC.bd_birth_sd,
                                         death_rate_sd=GC.bd_death_sd,
                                         max_time=time,
                                         repeat_until_success=True,
                                         rng=rng)
                 if tree.seed_node.num_child_nodes() > 1:
                     success = True
                     break
             assert success, "Failed to create non-empty Birth-Death tree after 100 attempts. Perhaps try a higher birth rate or lower death rate?"
             virus.set_time(virus.get_time() + tree.seed_node.edge_length)
             for c in tree.seed_node.child_node_iter():
                 GC.treenode_add_child(virus, c, node)