def can_write_read(read_and_alignment, current_position):
    """Returns true if the first read in the cache can safely be written. This
    will be the case if the read was not the first in a set of reads with the
    same alignment, or if the current position has gone beyond the last base
    covered in that alignment.
    """
    _, alignment = read_and_alignment
    if alignment is None:
        return True

    current_ref_id, current_ref_start = current_position
    alignment_ref_id, _, _, alignment_ref_end = alignment

    return alignment_ref_id != current_ref_id or alignment_ref_end < current_ref_start