Coverage for seqbank/utils.py: 100.00%

16 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-11-27 04:47 +0000

1from typing import Optional 

2from pathlib import Path 

3 

4import plotly.graph_objs as go 

5 

6 

7def parse_filter(filter: Path | list[str] | set[str] | None = None) -> Optional[set[str]]: 

8 """Converts the input into a set of strings to use as a filter. 

9 

10 Args: 

11 filter (Path | list[str] | set[str] | None, optional): 

12 The filter can be: 

13 - A `Path` to a file where each line contains a string. 

14 - A `list` or `set` of strings. 

15 - `None`, in which case the function will return `None`. 

16 

17 Returns: 

18 Optional[set[str]]: 

19 A set of strings to use as a filter, or `None` if the input is `None`. 

20 """ 

21 if not filter: 

22 return None 

23 

24 if isinstance(filter, Path): 

25 return set(filter.read_text().strip().split("\n")) 

26 

27 return set(filter) 

28 

29 

30def format_fig(fig: go.Figure) -> None: 

31 """Formats a plotly figure in a nicer way.""" 

32 fig.update_layout( 

33 width=1200, 

34 height=550, 

35 plot_bgcolor="white", 

36 title_font_color="black", 

37 font=dict( 

38 family="Linux Libertine Display O", 

39 size=18, 

40 color="black", 

41 ), 

42 ) 

43 gridcolor = "#dddddd" 

44 fig.update_xaxes(gridcolor=gridcolor) 

45 fig.update_yaxes(gridcolor=gridcolor) 

46 

47 fig.update_xaxes(showline=True, linewidth=1, linecolor="black", mirror=True, ticks="outside") 

48 fig.update_yaxes(showline=True, linewidth=1, linecolor="black", mirror=True, ticks="outside")