def query_iterator(alignment_iterator):
    reads_found = set()
    last = None
    alignments = []
    for alignment in alignment_iterator:
        this = alignment.qid
        if this != last:
            if last:
                yield alignments
            alignments = []
            reads_found.add(alignment.qid)
        alignments.append(alignment)
        last = this
    if last:
        yield alignments

#######################################################
#######################################################
#######################################################
iterate over alignments by query
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Diamond.py/query_iterator