Utils¶
Run Length Encode¶
Return the run length encoding of a string
Usage:
dna = "A"*3 + "G"*2 + "C" + "T"*5 + "A"*6 + "GCCT"
dna_rle = run_length_encode(dna)
Source code in genespeak/utils.py
def run_length_encode(dna: str) -> str:
"""Return the run length encoding of a string
Usage:
```python
dna = "A"*3 + "G"*2 + "C" + "T"*5 + "A"*6 + "GCCT"
dna_rle = run_length_encode(dna)
```
"""
return _run_length_encode(dna, use_regex=True, return_list=False) # type: ignore
Run Length Decode¶
Source code in genespeak/utils.py
def run_length_decode(dna_rle: str) -> str:
pat = _PAT_RLE_DECODE
return "".join([c * int(n) for _, n, c in pat.findall(dna_rle)])
Last update: 2022-11-20