def chr_sort_key(sequence_name):
    """
    Provides sort key for a chromosome such that chromosome
    names are sorted in order chr1, chr2, ..., chrN, chrX,
    chrY, chrM ('chr' prefixes optional)
    """
    extra_chroms_dict = {"W": 101, "X": 102, "Y": 103, "Z": 104, "M": 105}
    stripped_sequence_name = sequence_name.lstrip("chr")
    if stripped_sequence_name.isdigit():
        return int(stripped_sequence_name)
    elif stripped_sequence_name in extra_chroms_dict:
        return extra_chroms_dict[stripped_sequence_name]
    else:
        return 1000