Python键错误:'\n';
我使用下面的脚本从fastq文件中提取分子条形码。但是,我一直得到以下关键错误Python键错误:'\n';,python,keyerror,Python,Keyerror,我使用下面的脚本从fastq文件中提取分子条形码。但是,我一直得到以下关键错误 File "extractMolecularBarcode.py", line 42, in <module> dicoBarcode[barcode] += 1 KeyError: '\n' 文件中有一个换行符,当您使用 dicoBarcode[barcode] += 1 条形码值是一个换行符或“\n”,它会导致错误 您可以通过提供默认值来克服它: discoBarcode.get(bar
File "extractMolecularBarcode.py", line 42, in <module>
dicoBarcode[barcode] += 1
KeyError: '\n'
文件中有一个换行符,当您使用
dicoBarcode[barcode] += 1
条形码值是一个换行符或“\n”,它会导致错误
您可以通过提供默认值来克服它:
discoBarcode.get(barcode,YOURDEFAULT)
或者您可以先删除换行符,然后处理文件;)
问题在于,您没有在
条码
值的实际行上调用rstrip()
。您需要编辑以下行:
totseq= iFastq.readline()
plus = iFastq.readline()
qual = iFastq.readline()
所以它们看起来像这样:
totseq= iFastq.readline().rstrip()
plus = iFastq.readline().rstrip()
qual = iFastq.readline().rstrip()
谢谢你的回答。你有什么建议来消除这个问题吗?我不理解使用双叶编码.get(条形码,你的默认值)的那个。你能再解释一下吗?非常感谢。谢谢你的回答。当我在其他问题中寻找关于键错误的答案时,我尝试了rstrip,但它仍然给了我相同的错误:/
KeyError
只是意味着特定键\n
不在词典中,因此读取/增量失败。我尝试解决原始问题。我已再次尝试在两个rstrip中添加\n(在“while”开始之前的一个和在“while”循环结束时的一个)。它不起作用。这又给了我同样的错误。在上一步中,我完成了适配器的拆卸。可能是这一步中的问题导致了这个错误?@mordel很抱歉,我在两个方面弄错了。编辑了答案。1. rstrip()
会删除\n
和2。您可以从另一个readline()
中获取条形码值,该行没有rstrip
我按照您的建议将rstrip添加到这三行的末尾(totseq、plus和qual)。仍然没有改变:(
totseq= iFastq.readline()
plus = iFastq.readline()
qual = iFastq.readline()
totseq= iFastq.readline().rstrip()
plus = iFastq.readline().rstrip()
qual = iFastq.readline().rstrip()