Answer to Question #176628 in Python for CLASH CODER

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


1
Expert's answer
2021-03-29T18:46:13-0400
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!

Comments

Assignment Expert
30.03.21, 13:58

Dear clash coders there are no error in the code

clash coders
30.03.21, 10:20

when the program compiles and it shows an error The pattern was found in the following positions [start, end] Traceback (most recent call last): File "function3.py", line 22, in for i in result: TypeError: 'NoneType' object is not iterable

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS