【发布时间】:2021-09-19 19:34:43
【问题描述】:
此代码应该读取基因组的文本文件,并给定一个模式,应该返回该模式出现的次数及其位置。 相反,它只返回出现次数和第一次出现的位置。 this is an example of running the code 不是返回 35 次出现的位置,而是返回第一个位置 35 次。
# open the file with the original sequence
myfile = open('Vibrio_cholerae.txt')
# set the file to the variable Text to read and scan
Text = myfile.read()
# insert the pattern
Pattern = "TAATGGCT"
PatternLocations = []
def PatternCount(Text,Pattern):
count = 0
for i in range (len(Text)-len(Pattern)+1):
if Text [i:i+len(Pattern)] == Pattern:
count +=1
PatternLocations.append(Text.index(Pattern))
return count
# print the result of calling PatternCount on Text and Pattern.
print (f"Number of times the Pattern is repeated: {PatternCount(Text,Pattern)} time(s).")
print(f"List of Pattern locations: {PatternLocations}")
【问题讨论】:
-
这能回答你的问题吗? stackoverflow.com/q/3519565/967621
标签: python bioinformatics dna-sequence