cstag.to_sequence
1from __future__ import annotations 2 3from .split import split 4from .utils.validator import validate_cs_tag, validate_long_format 5 6 7def to_sequence(cs_tag: str) -> str: 8 """Reconstruct the reference subsequence in the alignment 9 10 Args: 11 cs_tag (str): cs tag in the **long** format 12 13 Returns: 14 str: The sequence string derived from the cs tag. 15 16 Example: 17 >>> import cstag 18 >>> cs_tag = "=AC*gt=T-gg=C+tt=A" 19 >>> cstag.to_sequence(cs_tag) 20 'ACTTCTTA' 21 """ 22 validate_cs_tag(cs_tag) 23 validate_long_format(cs_tag) 24 25 cs_tag = cs_tag.replace("cs:Z:", "") 26 sequence = [] 27 for cs in split(cs_tag): 28 if cs.startswith(("=", "+")): 29 sequence.append(cs[1:].upper()) 30 elif cs.startswith("*"): 31 sequence.append(cs[-1].upper()) 32 33 return "".join(sequence)
def
to_sequence(cs_tag: str) -> str:
8def to_sequence(cs_tag: str) -> str: 9 """Reconstruct the reference subsequence in the alignment 10 11 Args: 12 cs_tag (str): cs tag in the **long** format 13 14 Returns: 15 str: The sequence string derived from the cs tag. 16 17 Example: 18 >>> import cstag 19 >>> cs_tag = "=AC*gt=T-gg=C+tt=A" 20 >>> cstag.to_sequence(cs_tag) 21 'ACTTCTTA' 22 """ 23 validate_cs_tag(cs_tag) 24 validate_long_format(cs_tag) 25 26 cs_tag = cs_tag.replace("cs:Z:", "") 27 sequence = [] 28 for cs in split(cs_tag): 29 if cs.startswith(("=", "+")): 30 sequence.append(cs[1:].upper()) 31 elif cs.startswith("*"): 32 sequence.append(cs[-1].upper()) 33 34 return "".join(sequence)
Reconstruct the reference subsequence in the alignment
Args: cs_tag (str): cs tag in the long format
Returns: str: The sequence string derived from the cs tag.
Example:
import cstag cs_tag = "=AC*gt=T-gg=C+tt=A" cstag.to_sequence(cs_tag) 'ACTTCTTA'