Skip to content
Snippets Groups Projects

feat: function to generate poly(A) tail sequence

Merged MihaelaZavolan requested to merge polyAtail into main
2 files
+ 17
5
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 15
5
@@ -33,6 +33,10 @@ def generate_poly_a(
bases: Tuple[str, str, str, str] = ('A', 'C', 'G', 'U')
# check parameters
if not isinstance(length, int):
raise ValueError(
f"The provided length is not an integer: {length}"
)
if not 1 <= int(length) <= max_len:
raise ValueError(
"The provided length is outside of the accepted range "
@@ -43,15 +47,21 @@ def generate_poly_a(
"There is not a weight provided for each of the bases '{bases}': "
"{weights}"
)
if any(freq < 0 for freq in weights):
try:
sum(weights)
except TypeError:
raise ValueError(
"At least one of the provided weights is not a number: {weights}"
)
if any(w < 0 for w in weights):
raise ValueError(
"At least one of the provided 'weights' is negative: {weights}"
"At least one of the provided weights is negative: {weights}"
)
if all(n == 0 for n in weights):
raise ValueError(f"All 'weights' are zero: {weights}")
if all(w == 0 for w in weights):
raise ValueError(f"All weights are zero: {weights}")
# ensure that the values are normalized
s: float = sum(weights)
s: float = float(sum(weights))
norm_weights: List[float] = [freq/s for freq in weights]
tail_bases: List[str] = choices(bases, weights=norm_weights, k=length)
return "".join(tail_bases)
Loading