Question #176628

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 and slicing by 32 bases


Expert's answer

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)])
# example work 
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS