将有overlap 的区域进行合并,生成无overlap 的文件
本脚本仅实现中心算法部分,文件写入、写出部分,自行处理
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 14 08:18:15 2021
@author: dujidan
"""
bed_list = [[4,5], [8,9], [2,6], [1,2]]
sort_bed_list = list(sorted(bed_list))
result_list = []
low_est = sort_bed_list[0][0]
high_est = sort_bed_list[0][1]
for i in range(1, len(sort_bed_list)):
low, high = sort_bed_list[i]
if high_est >= low:
if high_est < high:
high_est = high
else:
result_list.append([low_est, high_est])
low_est, high_est = sort_bed_list[i]
result_list.append([low_est, high_est])
print(result_list)
可以使用 bedtools merge 进行合并,方便快捷。