def sub_regions(regions, region):
"""
Get regions from a list the overlap with another region.
:param regions: List of :class:`~GenomicRegion`
:param region: :class:`~GenomicRegion` used for overlap calculation
"""
if isinstance(region, string_types):
region = GenomicRegion.from_string(region)
sr = []
start_ix = None
end_ix = None
for i, r in enumerate(regions):
if r.chromosome == region.chromosome and r.start <= region.end and r.end >= region.start:
if start_ix is None:
start_ix = i
end_ix = i
sr.append(r.copy())
else:
if end_ix is not None:
break
if start_ix is None or end_ix is None:
raise ValueError("Region not found in dataset! {}:{}-{}".format(region.chromosome, region.start, region.end))
return sr, start_ix, end_ix
评论列表
文章目录