def get_sample_type(sample, sample_mapping):
    """Return the key in sample_mapping that has a match to the start of sample

    If two sample types include a sample name base in their sample name list that match
    the start of sample, then return the one matching sample more specificically, i.e.
    that with the longest match.
    """
    possibilities = {
        s: s_type
        for (s_type, s_list) in sample_mapping.items()
        for s in s_list
        if sample.startswith(s)
    }
    return possibilities[max(possibilities.keys(), key=len)]