小编mor*_*del的帖子

Python 密钥错误:'\n'

我使用下面的脚本从 fastq 文件中提取分子条形码。但是,我不断收到以下关键错误。

File "extractMolecularBarcode.py", line 42, in <module>
    dicoBarcode[barcode] += 1
KeyError: '\n'
Run Code Online (Sandbox Code Playgroud)

我知道关键错误意味着字典中没有定义某些内容,但我无法找出问题所在。你能帮忙吗?太感谢了!

这是脚本:

import sys, itertools


iFastq=open(sys.argv[1], 'r')
oFastq=open(sys.argv[2], 'w')
oBarcode=open(sys.argv[3], 'w')
oLigation=open(sys.argv[4], 'w')

dicoBarcode={}
dicoLigation={}
nct='ACTGN'
for barcode in list(itertools.product(nct, repeat=6)):
    dicoBarcode["".join(barcode)] = 0
    dicoLigation["".join(barcode)] = 0


header= iFastq.readline().rstrip()
while header != '':
    totseq= iFastq.readline()
    plus = iFastq.readline()
    qual = iFastq.readline()
    barcode = totseq[0:6]
    ligation = totseq[3:9]
    seq = totseq[6:]
    oFastq.write(header.split(" ")[0]+'_MolecularBarcode:'+barcode+' '+header.split(" ")[1]+'\n')
    oFastq.write(seq)
    oFastq.write(plus)
    oFastq.write(qual[6:])
    header= iFastq.readline().rstrip()

    dicoBarcode[barcode] += 1
    if len(seq) >= 4 …
Run Code Online (Sandbox Code Playgroud)

python keyerror

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

keyerror ×1

python ×1