def test_find_max_overlapping_returns_least_index(self): query_range = ranges.make_range('1', 0, 10) search_ranges = [ ranges.make_range('1', 0, 5), ranges.make_range('1', 5, 10) ] for to_search in [search_ranges, list(reversed(search_ranges))]: self.assertEqual(0, ranges.find_max_overlapping(query_range, to_search))
def test_find_max_overlapping_allows_unordered_search_ranges(self): query_range = ranges.make_range('1', 4, 12) search_ranges = [ ranges.make_range('1', 0, 10), ranges.make_range('1', 10, 20), ranges.make_range('1', 12, 20) ] max_overlapping_range = search_ranges[0] for permutated_ranges in itertools.permutations(search_ranges): self.assertEqual( permutated_ranges.index(max_overlapping_range), ranges.find_max_overlapping(query_range, permutated_ranges))
def assign_reads_to_assembled_regions(assembled_regions, reads): """Assign each read to the maximally overlapped window. Args: assembled_regions: list[AssemblyRegion], list of AssemblyRegion to assign reads to. Does not assume AssemblyRegion are sorted. reads: iterable[learning.genomics.genomics.Read], to be processed. Does not assume the reads are sorted. Returns: [AssemblyRegion], information on assigned reads for each assembled region. list[learning.genomics.genomics.Read], the list of unassigned reads. """ regions = [ar.region for ar in assembled_regions] unassigned_reads = [] for read in reads: read_range = utils.read_range(read) window_i = ranges.find_max_overlapping(read_range, regions) if window_i is not None: assembled_regions[window_i].add_read(read) else: unassigned_reads.append(read) return unassigned_reads
def test_find_max_overlapping(self, query_range, search_ranges, expected): actual = ranges.find_max_overlapping(query_range, search_ranges) self.assertEqual(expected, actual)