Coverage for seqbank/utils.py: 100.00%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-12-02 04:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-12-02 04:29 +0000
1from typing import Optional
2from pathlib import Path
5def parse_filter(filter: Path | list[str] | set[str] | None = None) -> Optional[set[str]]:
6 """Converts the input into a set of strings to use as a filter.
8 Args:
9 filter (Path | list[str] | set[str] | None, optional):
10 The filter can be:
11 - A `Path` to a file where each line contains a string.
12 - A `list` or `set` of strings.
13 - `None`, in which case the function will return `None`.
15 Returns:
16 Optional[set[str]]:
17 A set of strings to use as a filter, or `None` if the input is `None`.
18 """
19 if not filter:
20 return None
22 if isinstance(filter, Path):
23 return set(filter.read_text().strip().split("\n"))
25 return set(filter)
28def format_fig(fig):
29 """Formats a plotly figure in a nicer way."""
30 fig.update_layout(
31 width=1200,
32 height=550,
33 plot_bgcolor="white",
34 title_font_color="black",
35 font=dict(
36 family="Linux Libertine Display O",
37 size=18,
38 color="black",
39 ),
40 )
41 gridcolor = "#dddddd"
42 fig.update_xaxes(gridcolor=gridcolor)
43 fig.update_yaxes(gridcolor=gridcolor)
45 fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True, ticks='outside')
46 fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True, ticks='outside')