Valid characters in a String

For DNA sequences of a small size (around a thousand characters), this is a practical implementation def is_valid_sequence (dna): # base case if len (dna) == 0: return True # check if first character is valid elif dna [0] not in [‘A’, ‘T’, ‘C’, ‘G’]: return False # otherwise, recurse on the rest of the … Read more

Search for string allowing for one mismatch in any location of the string

Before you read on, have you looked at biopython? It appears that you want to find approximate matches with one substitution error, and zero insertion/deletion errors i.e. a Hamming distance of 1. If you have a Hamming distance match function (see e.g. the link provided by Ignacio), you could use it like this to do … Read more