Write a function to parse the below pattern onto a text file and highlight the matched pattern using the sliding window concept.
AATAA
ATTAAA
TATA
CAT
ATAGTCGC
Expected output
Sliding window 1: First 32 bases from 2048
TTTATGTGCCCCCCCCCATTTTATTTT
----
Till you get last 32 bases
REG = 'AATAA,ATTAAA,TATA,CAT,ATAGTCGC'
def find_reg(path_file, reg = REG):
res = []
with open(path_file, 'r') as f:
text = f.read()
size = len(text) - len(reg)
for i in range(size):
for j in reg:
if text[i] != j:
break
else:
res.append([i,i+len(reg)])
file = input('Enter path and file name')
result = find_reg(file)
print('The pattern was found in the following positions [start, end]')
for i in result:
print(i)
Comments
Leave a comment