1
1
import re
2
- from typing import Any , Optional
2
+ from typing import Any
3
3
4
4
import numpy as np
5
5
import pandas as pd
6
6
from pyranges import PyRanges
7
7
8
8
9
- def parse_region_string (region : str ) -> tuple [str , Optional [ int ], Optional [ int ] ]:
9
+ def parse_region_string (region : str ) -> tuple [str , int | None , int | None ]:
10
10
"""Return the contig, start position and end position from a region string."""
11
11
if re .search (r":\d+-\d*$" , region ):
12
12
contig , start_end = region .rsplit (":" , 1 )
@@ -21,7 +21,7 @@ def parse_region_string(region: str) -> tuple[str, Optional[int], Optional[int]]
21
21
22
22
23
23
def regions_to_pyranges (
24
- regions : list [tuple [str , Optional [ int ], Optional [ int ] ]], all_contigs : list [str ]
24
+ regions : list [tuple [str , int | None , int | None ]], all_contigs : list [str ]
25
25
) -> PyRanges :
26
26
"""Convert region tuples to a PyRanges object."""
27
27
@@ -44,7 +44,7 @@ def regions_to_pyranges(
44
44
return PyRanges (chromosomes = chromosomes , starts = starts , ends = ends )
45
45
46
46
47
- def parse_regions (regions : Optional [ str ] , all_contigs : list [str ]) -> Optional [ PyRanges ] :
47
+ def parse_regions (regions : str | None , all_contigs : list [str ]) -> PyRanges | None :
48
48
"""Return a PyRanges object from a comma-separated set of region strings."""
49
49
if regions is None :
50
50
return None
@@ -54,8 +54,8 @@ def parse_regions(regions: Optional[str], all_contigs: list[str]) -> Optional[Py
54
54
55
55
56
56
def parse_targets (
57
- targets : Optional [ str ] , all_contigs : list [str ]
58
- ) -> tuple [Optional [ PyRanges ] , bool ]:
57
+ targets : str | None , all_contigs : list [str ]
58
+ ) -> tuple [PyRanges | None , bool ]:
59
59
"""Return a PyRanges object from a comma-separated set of region strings,
60
60
optionally preceeded by a ^ character to indicate complement."""
61
61
if targets is None :
@@ -68,8 +68,8 @@ def parse_targets(
68
68
69
69
70
70
def regions_to_chunk_indexes (
71
- regions : Optional [ PyRanges ] ,
72
- targets : Optional [ PyRanges ] ,
71
+ regions : PyRanges | None ,
72
+ targets : PyRanges | None ,
73
73
complement : bool ,
74
74
regions_index : Any ,
75
75
):
@@ -113,8 +113,8 @@ def regions_to_chunk_indexes(
113
113
114
114
115
115
def regions_to_selection (
116
- regions : Optional [ PyRanges ] ,
117
- targets : Optional [ PyRanges ] ,
116
+ regions : PyRanges | None ,
117
+ targets : PyRanges | None ,
118
118
complement : bool ,
119
119
variant_contig : Any ,
120
120
variant_position : Any ,
0 commit comments