Answer to Question #176919 in Python for Vignesh Blaze

Question #176919
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
1
Expert's answer
2021-03-30T14:36:48-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)])
 
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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS