import csv


def _parseinfo(path, header):
    """
    Parse subject info

    path:
        path to the subject info TSV file containing subject number and session info
        one session per row
    header:
        header name for subject id and session number in dict
        {"participant_id": "<headername>", "ses": <headername> or None}
    """
    subject_info = {}

    with open(path, "r") as f:
        reader = csv.DictReader(f, delimiter="\t")
        for row in reader:
            sub = row[header["participant_id"]]
            if sub not in subject_info:
                subject_info[sub] = []  # add new subject

            if "ses" in header:
                ses = row[header["ses"]]
                subject_info[sub].append(ses)
    return subject_info