def HBVGenotypeKey(genotype):
    """
    Make a key for sorting HBV genotypes (including non-human genotypes that
    are the species name) for the plot legend.

    @param genotype: A C{str} genotype.
    @return: A 2-C{tuple} with an C{int} index and the passed C{str} genotype.
        This will ensure that sorting will be first on the index, then on the
        genotype name.
    """
    # The index is 0 for single-character genotypes (apart from ?, which
    # comes last), followed by 1 for genotypes with longer names
    # (Chimpanzee, Gibbon, etc), followed by 2 for unknown (?) genotypes.
    return (
        2 if genotype == '?' else (0 if len(genotype) == 1 else 1),
        genotype)