Coverage for /home/deng/Projects/ete4/hackathon/ete4/ete4/smartview/renderer/layouts/evol_events_layouts.py: 26%

23 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-03-21 09:19 +0100

1from ..treelayout import TreeLayout 

2 

3 

4__all__ = [ "LayoutEvolEvents" ] 

5 

6 

7class LayoutEvolEvents(TreeLayout): 

8 def __init__(self, name="Evolutionary events", 

9 prop="evol_event", 

10 speciation_color="blue", 

11 duplication_color="red", 

12 legend=True): 

13 super().__init__(name) 

14 

15 self.prop = prop 

16 self.speciation_color = speciation_color 

17 self.duplication_color = duplication_color 

18 self.legend = legend 

19 

20 self.active = True 

21 

22 def set_tree_style(self, tree, tree_style): 

23 super().set_tree_style(tree, tree_style) 

24 if self.legend: 

25 colormap = { "Speciation event": self.speciation_color, 

26 "Duplication event": self.duplication_color } 

27 tree_style.add_legend(title=self.name, 

28 variable="discrete", 

29 colormap=colormap) 

30 

31 def set_node_style(self, node): 

32 if not node.is_leaf: 

33 if node.props.get(self.prop, "") == "S": 

34 node.sm_style["fgcolor"] = self.speciation_color 

35 node.sm_style["size"] = 2 

36 

37 elif node.props.get(self.prop, "") == "D": 

38 node.sm_style["fgcolor"] = self.duplication_color 

39 node.sm_style["size"] = 2