''' ============================================================ http://rosalind.info/problems/hamm Given: Two DNA strings s and t of equal length (not exceeding 1 kbp). Return: The Hamming distance dH(s,t). ============================================================ ''' import rosalind.rosutil as ro if __name__ == "__main__": # import doctest # doctest.testmod() print ro.hamm(*ro.read_lines('rosalind_hamm_sample.dat')) print ro.hamm(*ro.read_lines('rosalind_hamm.dat'))
def apm(s, p, d): '''Return a list of all positions where p appears in s with at most d mismatches.''' m = len(p) return [i for i in xrange(len(s) - m) if ro.hamm(s[i:i + m], p) <= d]