生物信息分析中,需要对很多的range数据进行merge,但是目前还没有对于大片段的range进行merge的方法,所以自己写了一个,发现其中也隐含很多的python使用经验。比如下面一个程序:
def region_redup(regionList1):
regionList1.sort()
indList = range(1, len(regionList1))
indList.sort(reverse=True)
for i in indList:
if regionList1[i][0] < regionList1[i-1][1]:
regionList1[i-1][1] = regionList1[i][1]
regionList1.remove(regionList1[i])
return regionList1
def region_merge(regionList1, regionList2):
print "redup 1"
region_redup(regionList1)
print "redup 2"
region_redup(regionList2)
for region2 in regionList2:
flag = 0
for region1 in regionList1:
if region2[0] < region1[1]:
flag = 1
if region2[1] > region1[0]:
regionList1.remove(region1)
regionList1.append([min(region1[0