-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utilities.py
More file actions
28 lines (20 loc) · 1.01 KB
/
Copy pathtest_utilities.py
File metadata and controls
28 lines (20 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import random
from typing import Set
class InvalidNucleotideError(Exception):
"""Raised when an invalid nucleotide is encountered."""
pass
STANDARD_NUCLEOTIDES: Set[str] = {'A', 'T', 'G', 'C'}
INVALID_CHARS: Set[str] = {'Z', 'U', 'X', 'L'}
def generate_random_sequence(length: int, nucleotides: Set[str] = STANDARD_NUCLEOTIDES) -> str:
"""Generates a random sequence string from a given set of nucleotides."""
return "".join(random.choices(list(nucleotides), k=length))
def generate_invalid_sequence(length: int) -> str:
"""Generates a sequence containing valid DNA bases and invalid characters."""
valid_part_len = length // 2
invalid_part_len = length - valid_part_len
valid_part = generate_random_sequence(valid_part_len, STANDARD_NUCLEOTIDES)
invalid_part = generate_random_sequence(invalid_part_len, INVALID_CHARS)
# Shuffle and join the parts
full_list = list(valid_part + invalid_part)
random.shuffle(full_list)
return "".join(full_list)