【问题标题】:cs50 dna when i debug my code i got this errorcs50 dna 调试代码时出现此错误
【发布时间】:2020-08-25 22:17:55
【问题描述】:

这是我的代码 好的我知道我的代码在算法上具有 o^234234324 复杂度但是 它适用于所有序列,除了序列/15.txt 和序列/16.txt

import sys
import csv
if len(sys.argv) != 3:
    print("useage: filenameofdata.cvs filenameofsequence.txt")
    sys.exit(1)
with open(sys.argv[1], "r") as datafile:
    readdata = list(csv.reader(datafile))
with open(sys.argv[2], "r") as sequencefile:
    readsequence = list(csv.reader(sequencefile))
strs = list(readdata[0][1:])
conlist = []
dnanum = 0
for move in (strs):
    sequence = list(readsequence[0][0])
    consecutively = 0
    l = len(move)
    cursor = [None] * 2
    temp = [None] * l
    x = 0
    counter = 0
    while counter == 0:
        if sequence == []:
            conlist.append(consecutively)
            break
        for oneletter in (sequence):
            if x < 2:
                cursor[x] = oneletter
            temp[x] = oneletter
            x += 1
            if x == l:
                asstring = ''.join(map(str, temp))
                if asstring == move:
                    dnanum += 1
                    move
                    temp = [None] * l
                    x = 0
                    continue
                else:
                    if consecutively < dnanum:
                        consecutively = dnanum
                    oneletter = sequence.remove(cursor[0])
                    temp = [None] * l
                    x = 0
                    dnanum = 0
                    break
# this print was for check if i got the right str consecutively
print(conlist)
conlist = ''.join(map(str, conlist))
for y in readdata:
    x = ''.join(map(str, y[1:]))
    if conlist == x:
        print(y[0])
        sys.exit(1)
print("No match")

当我尝试在sequence/15.txt 和sequence/16.txt 中调试它时,或者如果我尝试运行它们,我没有输出 调试时的按摩错误

~/pset6/dna/ $ debug50 python dna.py databases/large.csv sequences/15.txt                                                                                                                        
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/site-packages/ikp3db.py", line 2105, in <module>
    ikp3db.main()
  File "/usr/local/lib/python3.7/site-packages/ikp3db.py", line 2011, in main
    debug_socket.bind((cmd_line_args.IKPDB_ADDRESS, cmd_line_args.IKPDB_PORT,))
OSError: [Errno 98] Address already in use

【问题讨论】:

  • 你到底想达到什么目的?
  • @VedantMehta Mehta 我正在尝试读取某人的 dna 序列并在他们提供的数据库中进行比较(根据他们的 DNA 识别一个人)
  • 错误意味着程序使用套接字(网络连接)并尝试使用已使用的 IP:PORT。这可能意味着其他程序正在使用它,您必须找到该程序并关闭它。或者套接字在之前使用时没有正确关闭/断开连接,现在系统将阻塞此 IP:PORT 几秒钟/分钟。

标签: python python-3.x cs50


【解决方案1】:

这太复杂了。为了获得每个 STR 的最大连续 STR 数,我只写了 6 行代码:

for i in range(1, len(data[0])):  # loop through all STR

    count = 1

    string = data[0][i]  # assign each STR to a string

    while string * count in dna:  # if find 1 string, then try to find string*2, and so on

        count += 1

    counts.append(str(count - 1))  # should be decreased by 1 as initialized to 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 2019-01-26
    • 2021-12-24
    • 2012-04-18
    相关资源
    最近更新 更多