def canonical_chrom_sorted(in_chroms):
    """
    Sort a list of chromosomes in the order 1..22, X, Y, M/MT

    :param list in_chroms: Input chromosomes
    :return: Sorted chromosomes
    :rtype: list[str]
    """
    if len(in_chroms) == 0:
        return []
    chr_prefix = False
    mt = False
    if in_chroms[0].startswith('chr'):
        in_chroms = [x.lstrip('chr') for x in in_chroms]
        chr_prefix = True
    if 'MT' in in_chroms:
        in_chroms[in_chroms.index('MT')] = 'M'
        mt = True
    in_chroms = sorted(in_chroms, key=lambda c: int(c) if c not in ('X', 'Y', 'M') else c)
    try:
        m_index = in_chroms.index('M')
    except ValueError:
        pass
    else:
        in_chroms.pop(m_index)
        in_chroms.append('M')
    # At this point it should be nicely sorted
    if mt:
        in_chroms[in_chroms.index('M')] = 'MT'
    if chr_prefix:
        in_chroms = [''.join(['chr', x]) for x in in_chroms]
    return in_chroms
Sort a list of chromosomes in the order 1..22, X, Y, M/MT

    :param list in_chroms: Input chromosomes
    :return: Sorted chromosomes
    :rtype: list[str]