Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 python:为什么我在计算间隔内的频率时得到不同的结果?;_Python 2.7_Intervals - Fatal编程技术网

Python 2.7 python:为什么我在计算间隔内的频率时得到不同的结果?;

Python 2.7 python:为什么我在计算间隔内的频率时得到不同的结果?;,python-2.7,intervals,Python 2.7,Intervals,以下代码是一个程序,旨在计算大型数据集中不等长度间隔内的频率。两个列表“snp”和“bin_列表”是测试数据。我必须按照下面的程序编写代码 我有一个问题,当代码中使用“continue”和“snp.remove(site)”时,结果是不同的 在代码中使用“continue”时,我得到了以下结果: Potri.001G000300up1k 26 Potri.001G000400down1k 26 Potri.001G000300part2 5 但是我在代码中使用“snp.remove(site)

以下代码是一个程序,旨在计算大型数据集中不等长度间隔内的频率。两个列表“snp”和“bin_列表”是测试数据。我必须按照下面的程序编写代码

我有一个问题,当代码中使用“continue”和“snp.remove(site)”时,结果是不同的

在代码中使用“continue”时,我得到了以下结果:

Potri.001G000300up1k 26
Potri.001G000400down1k 26
Potri.001G000300part2 5
但是我在代码中使用“snp.remove(site)”时得到了不同的结果:

Potri.001G000300up1k 26
Potri.001G000400down1k 25
Potri.001G000300part2 5
实际上,第一个结果在低速时是正确的,而第二个结果在高速时有点错误

所以,我的问题是,在代码中使用“snp.remove(site)”时,如何修复该错误?

我使用的是python 2.7.12

注意:我必须在每个循环中迭代列表“snp”

#!/usr/bin/env python

def locateBin(Start, End, site):
    return site >= Start and site <= End

snp = ['17', '24', '31', '36', '38', '43', '45', '50', '52', '58', '86', '224', '306', '369', '663', '665', '668', '740', '811', '844', '891', '942', '1059', '1097', '1186', '1371', '1437', '1458', '1487', '1537', '1571', '1720', '1853', '2066', '2238', '2292', '2296', '2332', '2367', '2387', '2483', '2585', '2772', '2856', '2935', '2944', '2966', '2967', '2991', '2992', '3048', '3166', '3211', '3241', '3280', '3350', '3351', '3367', '3373', '3378', '3406', '3449', '3454', '3533', '3573', '3621', '3623', '3643', '3644', '3697', '3745', '3757', '3822', '3867', '3893', '3949', '4094', '4142', '4149', '4260', '4457', '4462', '4511', '4528', '4535', '4622', '4719', '4722', '4775', '4790', '4801', '4863', '4873', '4879', '4928', '5044', '5454', '5498', '5557', '5584', '5805', '6215', '6231', '6243', '6293', '6346', '6365', '6401', '6421', '6616', '6812', '6861', '6925', '7023', '7126', '7341', '7342', '7369', '7412', '7413', '7483', '7501', '7645', '7679', '7681', '7799', '7828', '7896', '7928', '7944', '7950', '7971', '8002', '8003', '8038', '8058', '8092', '8134', '8213', '8224', '8275', '8292', '8323', '8378', '8444', '8481', '8498', '8499', '8504', '8556', '8616', '8660', '8676', '8710', '8773', '8817', '9158', '9228', '9232', '9302', '9321', '9340', '9383', '9429', '9538', '9602', '9691', '9723', '9880', '9914', '10044', '10046', '10068', '10073', '10176', '10192', '10237', '10241', '10300', '10368', '10618', '10742', '10835', '10959', '11025', '11028', '11260', '11275', '11528', '11912', '11986', '12062', '12095', '12347', '12366', '12513', '12560', '12592', '12648']

bin_list = [['Potri.001G000300up1k', 'Chr01', '7391', '8391'], ['Potri.001G000400down1k', 'Chr01', '7391', '8391'], ['Potri.001G000300part2', 'Chr01',  '8625', '8860']]


index = 0
count_list = []

while index < len(bin_list):
    num = 0
    el = bin_list[index]
    for site in snp:
        if int(site) < int(el[2]):
            continue
            #snp.remove(site)
        elif locateBin(int(el[2]), int(el[3]), int(site)):
            num += 1
        else:
            count_list.append([el[0], num]) 
            break
    index += 1

for line in count_list:
    print("%s\t%s\n" % (line[0], line[1])),
#/usr/bin/env python
def定位箱(开始、结束、站点):

return site>=Start and site通常不应该在迭代列表时修改它。一个简单的修复方法是为迭代制作一份副本(
,用于snp[:]:


snp[:]
创建列表的副本。

通常不应在迭代列表时修改列表。一个简单的修复方法是为迭代制作一份副本(
,用于snp[:]:

snp[:]
创建列表的副本