def _match_pairs_from_sorted_reads(sorted_reads): prev_reads = [] prev_reads_name = None prev_reads_directions = [] #{'read': None, 'name': None, 'direction': None} for read in sorted_reads: title = get_title(read) try: name, direction = _parse_pair_direction_and_name_from_title(title) except PairDirectionError: name, direction = None, None if direction is not None and prev_reads_name is None: prev_reads = [read] prev_reads_name = name prev_reads_directions = [direction] continue elif direction is None: if prev_reads: yield prev_reads prev_reads = [] prev_reads_name = None prev_reads_directions = [] yield [read] elif name == prev_reads_name: if direction == REV: prev_reads.append(read) prev_reads_directions.append(direction) else: prev_reads.insert(0, read) prev_reads_directions.insert(0, direction) else: if prev_reads: yield prev_reads prev_reads = [read] prev_reads_name = name prev_reads_directions = [direction] if prev_reads: yield prev_reads
def _key(seq): return get_title(seq)
def _parse_pair_direction_and_name(seq): 'It parses the description field to get the name and the pair direction' return _parse_pair_direction_and_name_from_title(get_title(seq))