@@ -517,32 +517,36 @@ def abstract_asexual_phylogeny(phylogeny, attribute_list,
517517
518518 # Start with the root nodes
519519 # TODO: Make work for forests (multiple roots)
520- root_id = get_root_ids (phylogeny )[0 ]
520+ to_process = []
521+ root_ids = get_root_ids (phylogeny )
521522 state_id = 0
523+ next_id = 1
522524 # Add the first phylogeny state to the abstract phylogeny
523- abstract_phylogeny .add_node (state_id )
524- abstract_phylogeny .nodes [state_id ]["state_id" ] = state_id
525- abstract_phylogeny .nodes [state_id ]["node_state" ] = \
526- [phylogeny .nodes [root_id ][attr ] for attr in attribute_list ]
527- # Add attributes to state
528- for attr in attribute_list :
529- abstract_phylogeny .nodes [state_id ][attr ] = phylogeny .nodes [root_id ][attr ]
530- if track_origin :
531- abstract_phylogeny .nodes [state_id ]["origin_time" ] = \
532- phylogeny .nodes [root_id ][origin_time_attr ]
533- if track_destruction : # (this might get updated as we go)
534- dest_time = phylogeny .nodes [root_id ][destruction_time_attr ]
535- if dest_time == "none" or float (dest_time ) == float ("inf" ):
536- dest_time = - 1
537- dest_time = float (dest_time )
538- abstract_phylogeny .nodes [state_id ]["destruction_time" ] = dest_time
539-
540- # Add first member
541- abstract_phylogeny .nodes [state_id ]["members" ] = {root_id :
542- phylogeny .nodes [root_id ]}
543-
544- next_id = state_id + 1
545- to_process = [(root_id , state_id )]
525+ for root_id in root_ids :
526+ abstract_phylogeny .add_node (state_id )
527+ abstract_phylogeny .nodes [state_id ]["state_id" ] = state_id
528+ abstract_phylogeny .nodes [state_id ]["node_state" ] = \
529+ [phylogeny .nodes [root_id ][attr ] for attr in attribute_list ]
530+ # Add attributes to state
531+ for attr in attribute_list :
532+ abstract_phylogeny .nodes [state_id ][attr ] = phylogeny .nodes [root_id ][attr ]
533+ if track_origin :
534+ abstract_phylogeny .nodes [state_id ]["origin_time" ] = \
535+ phylogeny .nodes [root_id ][origin_time_attr ]
536+ if track_destruction : # (this might get updated as we go)
537+ dest_time = phylogeny .nodes [root_id ][destruction_time_attr ]
538+ if dest_time == "none" or float (dest_time ) == float ("inf" ):
539+ dest_time = - 1
540+ dest_time = float (dest_time )
541+ abstract_phylogeny .nodes [state_id ]["destruction_time" ] = dest_time
542+
543+ # Add first member
544+ abstract_phylogeny .nodes [state_id ]["members" ] = {root_id :
545+ phylogeny .nodes [root_id ]}
546+
547+ to_process .append ((root_id , state_id ))
548+ state_id = next_id
549+ next_id += 1
546550
547551 while to_process :
548552 phylogeny_id , state_id = to_process .pop ()
@@ -592,7 +596,7 @@ def abstract_asexual_phylogeny(phylogeny, attribute_list,
592596 phylogeny .nodes [id ][attr ]
593597 # Add first member
594598 abstract_phylogeny .nodes [next_state_id ]["members" ] = \
595- {phylogeny_id : phylogeny .nodes [id ]}
599+ {id : phylogeny .nodes [id ]}
596600 to_process .append ((id , next_state_id ))
597601
598602 return abstract_phylogeny
0 commit comments