cstag.utils.validator

 1from __future__ import annotations
 2
 3import re
 4
 5
 6def validate_cs_tag(cs_tag: str) -> None:
 7    pattern = re.compile(
 8        r"^(=[ACGTN]+|:[0-9]+|\*[acgtn][acgtn]|\+[acgtn]+|\-[acgtn]+|\~[acgtn][acgtn][0-9]+[acgtn][acgtn])*$"
 9    )
10
11    if not pattern.fullmatch(cs_tag.replace("cs:Z:", "")):
12        raise ValueError(f"Invalid cs tag: {cs_tag}")
13
14
15def validate_short_format(cs_tag: str) -> None:
16    if re.search(r"=[ACGTN]+", cs_tag):
17        raise ValueError("cs tag must be in short format")
18
19
20def validate_long_format(cs_tag: str) -> None:
21    if re.search(r":[0-9]+", cs_tag):
22        raise ValueError("cs tag must be in long format")
23
24
25def validate_threshold(threshold: int) -> None:
26    if not isinstance(threshold, int):
27        raise ValueError("threshold must be an integer")
28
29    if not 0 <= threshold <= 40:
30        raise ValueError("threshold must be within a range between 0 to 40")
31
32
33def validate_pos(pos: int) -> None:
34    if pos < 1:
35        raise ValueError(f"pos must be a positive integer, but got {pos}")
def validate_cs_tag(cs_tag: str) -> None:
 7def validate_cs_tag(cs_tag: str) -> None:
 8    pattern = re.compile(
 9        r"^(=[ACGTN]+|:[0-9]+|\*[acgtn][acgtn]|\+[acgtn]+|\-[acgtn]+|\~[acgtn][acgtn][0-9]+[acgtn][acgtn])*$"
10    )
11
12    if not pattern.fullmatch(cs_tag.replace("cs:Z:", "")):
13        raise ValueError(f"Invalid cs tag: {cs_tag}")
def validate_short_format(cs_tag: str) -> None:
16def validate_short_format(cs_tag: str) -> None:
17    if re.search(r"=[ACGTN]+", cs_tag):
18        raise ValueError("cs tag must be in short format")
def validate_long_format(cs_tag: str) -> None:
21def validate_long_format(cs_tag: str) -> None:
22    if re.search(r":[0-9]+", cs_tag):
23        raise ValueError("cs tag must be in long format")
def validate_threshold(threshold: int) -> None:
26def validate_threshold(threshold: int) -> None:
27    if not isinstance(threshold, int):
28        raise ValueError("threshold must be an integer")
29
30    if not 0 <= threshold <= 40:
31        raise ValueError("threshold must be within a range between 0 to 40")
def validate_pos(pos: int) -> None:
34def validate_pos(pos: int) -> None:
35    if pos < 1:
36        raise ValueError(f"pos must be a positive integer, but got {pos}")