def addToFragments(fragments, qname, chromosome, rstart, rend, cell_barcode,
    is_reverse, max_dist):
    """Add new fragment information to dictionary
    
    Parameters
    ----------

    fragments : dict
        A dictionary containing all the fragment information
    qname : str
        Read name
    chromosome : str
        Chromosome name
    rstart : int
        Alignment start position
    rend : int
        Alignment end position
    cell_barcode : str
        Cell barcode sequence
    is_reverse : bool
        Read is aligned to reverse strand
    max_dist : int
        Maximum allowed fragment size
    """
    if qname in fragments.keys():
        if is_reverse:
            current_coord = fragments[qname][1]
            if current_coord is None:
                del fragments[qname]
            elif rend - current_coord > max_dist or rend - current_coord < 0:
                del fragments[qname]
            elif cell_barcode is None and fragments[qname][3] is None:
                del fragments[qname]
            else:
                if fragments[qname][3] is None:
                    fragments[qname][3] = cell_barcode
                fragments[qname][2] = rend
                fragments[qname][4] = True
        else:
            current_coord = fragments[qname][2]
            if current_coord is None:
                del fragments[qname]
            elif current_coord - rstart > max_dist or current_coord - rstart < 0:
                del fragments[qname]
            elif cell_barcode is None and fragments[qname][3] is None:
                del fragments[qname]
            else:
                if fragments[qname][3] is None:
                    fragments[qname][3] = cell_barcode
                fragments[qname][1] = rstart
                fragments[qname][4] = True
    else:
        fragments[qname] = [chromosome, None, None, cell_barcode, False]
        if is_reverse:
            fragments[qname][2] = rend
        else:
            fragments[qname][1] = rstart
    return fragments
