【发布时间】:2022-11-11 04:24:49
【问题描述】:
所以我做到了这一点:
- 名称[]- 是一个带有 CSV 数据的字典
- 字符串[]- 来自 CSV 的列名 - 访问 STR 名称
- 序列[]- 来自 TXT 的 DNA 序列
-
检查序列[]- 列出序列中的 STR 计数
我现在陷入了最后的任务:
- 需要将 STR 计数与每个人的 CSV 数据进行比较
- 输出匹配
这是我的代码:
# Read database file into a variable names = [] # Read data from the file with open(sys.argv[1], "r") as file: # Loop through the names reader = csv.DictReader(file) for name in reader: names.append(name) # Read STRs with open(sys.argv[1], "r", newline='') as file: readstr = csv.reader(file) rows = list(readstr) str = rows[0] # Read DNA sequence file into a variable sequence = [] with open(sys.argv[2], "r") as file: sequence = file.read() # TODO: Find longest match of each STR in DNA sequence checked_seq = [] for i in range(len(str)): subsequence = str[i] reps = longest_match(sequence, subsequence) checked_seq.append(reps)我正在打印沿线创建的每个数据结构,看起来 STR 计数有效。
现在这是我最后一项任务的思路:
for i in range(1, len(str) - 1): match = 0 while True: if checked_seq[i] == names[i - 1][str[i]]: match += 1 else: break if match == len(str) - 1: print(names[i - 1][str[0]]) else: print("No match")我打算循环遍历每个人的数据,并将 STR 计数与检查的 TXT 文件中的 STR 计数进行比较。每次有匹配时,我都必须检查同一个人的下一个 STR,如果它不匹配,或者如果 STR 再次匹配,则将匹配计数增加一个。
我会查的匹配算计STR数如果这些值相同,则打印出该人的姓名。
有人可以给我一个线索我哪里出错了吗?
【问题讨论】: