-2

Given a string/pattern, how would you search within a long sequence, for strings of the same length as the given pattern that match exactly or with a difference of one character?

For example: Looking for ATGG in "ATCGGGATTGGGG..." --- you would find: ATCGGGATTGGGG...

Also, I'd like know how to record the locations of these matches

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
N K Han
  • 21
  • 1

1 Answers1

0

for strings of the same length as the given pattern that match exactly or with a difference of one character?

For a toy example like this, the simplest approach is probably brute force: with a pattern like ATGG|.TGG|A.GG|AT.G|ATG..

how to record the locations of these matches

The match object returned by re.match or re.search (or in the iterator produced by .finditer; but not with .findall which just gives you the text of the matches) has a .start method that provides this information.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153