Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Bio/Restriction/Restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@
def _make_FormattedSeq_table() -> bytes:
table = bytearray(256)
upper_to_lower = ord("A") - ord("a")
for c in b"ABCDGHKMNRSTVWY": # Only allow IUPAC letters
# Only allow alphabetic characters
# (although only ACGT are used for finding restriction sites)
for c in b"ABCDEFGHIJKLMNOPQRSTUVWXYZ":
table[c] = c # map uppercase to uppercase
table[c - upper_to_lower] = c # map lowercase to uppercase
return bytes(table)
Expand Down
9 changes: 6 additions & 3 deletions Tests/test_Restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ def test_sequence_object(self):
EcoRI.search(Seq("ATGC"))
EcoRI.search(MutableSeq("TCAG"))

def test_non_iupac_letters(self):
"""Test if non-IUPAC letters raise a TypeError."""
def test_non_allowed_characters(self):
"""Test if non-allowed characters raise a TypeError."""
# Any letter is accepted, even if it's not a nucleotide
FormattedSeq(Seq("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
# Other characters are not accepted
with self.assertRaises(TypeError):
seq = FormattedSeq(Seq("GATCZ"))
FormattedSeq(Seq("GATCZE-"))

def test_formatted_seq(self):
"""Test several methods of FormattedSeq."""
Expand Down