我得到一个错误:以10为基数的int()的文本无效'0 | 0'。我不确定问题是格式0 | 0而不是0:0,因为它看起来像是用“:”分隔字段,还是与自我深度位置. 回溯显示:
Traceback (most recent call last):
File "vcftopf_p1_commandline.py", line 200, in <module>
snps[i]=snp(lin)
File "vcftopf_p1_commandline.py", line 140, in __init__
if int(gtype[self.depthpos])>=cutoff:
ValueError: invalid literal for int() with base 10: '0|0'
一段代码看起来像:
^{pr2}$输入如下:
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT HG01112 HG01113 HG01119
1 14674 . G A 100 PASS . GT 0|0 0|0 0|0
你这里有几个问题。首先,对于那些花了大量时间编写特定Python风格标准的人来说,代码的格式设置使他们很难阅读。我建议你从PEP8开始,然后从那里发展你的风格。在
我认为这个代码重新格式化保留了代码的含义。如果我错了,请纠正我。在
第一个问题
最初的问题是
^{pr2}$ValueError: invalid literal for int() with base 10: '0|0'
-这是因为调用时有以下值
gtype = gtypestr.split(':')
使用示例输入:str.split(delimiter)
的输出总是一个列表,因此gtype
的值是['0|0']
。在gtype[self.depthpos]
等于gtype[-1]
,这等于gtype[0]
,因为gtype
是长度为1的列表。在因此,您调用
int('0|0')
,这会给您错误。在第二个问题
将
gtypestr.split(':')
更改为gtypestr.split('|')
的建议假定错误来自于对错误字符的拆分。这变化给了你cutoff
没有在您给我们的代码示例中定义,但是我假设0 >= cutoff
然后我们运行这个块:这就是当你调用
gtype[0][2]
时给你的IndexError: string index out of range
-这相当于调用'0'[2]
,并且在一个字符串中没有第三个字符。在这个块看起来像是在尝试处理
.split(':')
调用返回的第一个子字符串中间的分隔符。在所以我不知道如何前进:
gtype[0]
子字符串调用以针对不同的字符串工作?在.split(':')
并更改截止测试?在你能告诉我们更多关于输入格式的信息吗?在
需要使用字符串调用eval
结果:1
异常意味着字符串
'0|0'
是传递给int()
函数的无效值。要解决此问题,请确保字符串包含有效的integer literal。在相关问题 更多 >
编程相关推荐