Created
February 21, 2021 23:51
-
-
Save ArianK16a/85b22d6591084df03c87374ebbc46bbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
seq = "ATAGCTGCCGATCGAGTAACCTAGAACGATCGATCGATCGGATACTAGGAATTCTAGCTAGCCGTAGCTAGGGATCGCCTAAAGTCGATGCTAATTAGCTATAACGGCTGAATTCTAGCTAGCCTTAAGCTAGCATAGCTAACTAGTAGCTAGAATTCTAGGGCTAATAGCTAGCTAGTAGCTTTATAACGCGATCGGATCG" | |
pattern = "GAATTC" | |
seq1 = [char for char in seq] | |
pattern1 = [char for char in pattern] | |
list = [] | |
match_streak = 0 | |
first_hit = [] | |
where = [] | |
occurances = 0 | |
i = 0 | |
while i < len(seq1): | |
""" Wenn das gesamte pattern getroffen wird, speichere | |
den ersten Wert falls nötig, hänge an die Liste where | |
eine Liste mit dem ersten und letzen Index des Treffers | |
an. Danach setzt die match_streak und list zurück und | |
erhöhe occurances um 1. """ | |
if match_streak > len(pattern1) - 1: | |
if not first_hit: | |
first_hit = list | |
where.append([i - len(pattern1), i - 1]) | |
list = [] | |
match_streak = 0 | |
occurances += 1 | |
""" Wenn der Wert von seq1 an der Stelle i dem gesuchten Muster | |
and der Stelle match_streak entspricht hänge diesen Wert an | |
list an und erhöhe match_streak. """ | |
if seq1[i] == pattern1[match_streak]: | |
list.append(seq1[i]) | |
match_streak += 1 | |
""" Falls der Wert nicht dem gesuchten Muster entspricht, setzt | |
list und match_streak zurück. Im Falle, dass der aktuelle Wert | |
dem Anfangswert des Musters entspricht, erhöhe i nicht um die | |
while Schleife mit dem Anfangswert erneut zu starten. """ | |
else: | |
list = [] | |
match_streak = 0 | |
if seq1[i] == pattern1[0]: | |
continue | |
i += 1 | |
print(occurances) | |
print(first_hit) | |
print(where) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment