python - CS50 DNA: STR counter only works most of the time
问题描述
Here is a mock up of the function. A lot of the samples have one or two STRs coming back as 1. Can someone help me understand what I am doing wrong?
dnaSamp = input("DNA: ")
strSeq = ["TATC"]###["AGATC", "TTTTTTCT", "AATG", "TCTAG", "GATA", "TATC", "GAAA", "TCTG"]
hiScore = [0] * len(strSeq)
for i in range(len(strSeq)): # cycle throught the varios STRs
for j in range(len(dnaSamp) - (len(strSeq)-1)): # loop over dna sample
k = j + len(strSeq[i]) # variable to control the length of the STR sequence
if dnaSamp[j : k] == strSeq[i]:
counter = 0
for l in range(len(dnaSamp)): #if match look at next set
if dnaSamp[j + (l * len(strSeq[i])) : k + (l * len(strSeq[i]))] == strSeq[i]:
counter += 1
continue
break
if counter > hiScore[i]:
hiScore[i] = counter #save highest counter
print(f"{strSeq[i]} = {hiScore[i]}" )
解决方案
推荐阅读
- parameters - Blazor - 向 API 控制器发送参数
- python - 访问 python - tuple 时需要澄清
- angular-template - 角, element and #document-fragment
- If I add
<template><img src="url1" /></template>
in any basic HTML page, the img resource aturl1
is not downloaded, and according to Chrome De - python - How to solve error on sending game action
- multithreading - TCP/IP Multithreading Application
- php - How to unset or clear a global variable in php YII2 Recursive function?
- spring - 从 IBM MQ spring boot listner 接收 Payload,然后在功能 approch 中将数据发送到 rabbit mq
- sql-server - Stored procedure invocation template for ensure transaction (all or nothing)
- linux - How do we can use the live MongoDB database in the local system | MongoDB | Database backup
- python - 我可以在reduce函数中有两个迭代吗?(Python)
- If I add