import csv


def indexGroups(samplefile, groupvar):
    """
    Build dictionary with sample ID as key, group ID as value

    """

    sg_dict = {}

    f = open(samplefile, 'r', encoding="utf-8")
    reader = csv.DictReader(f, delimiter='\t')

    for row in reader:
        sg_dict[row['ID']] = row[groupvar]

    return sg_dict