import gzip


def read_consanguineous_samples(path, cutoff=0.05):
    """
    Read inbreeding coefficients from a TSV file at the specified path.
    Second column is sample id, 6th column is F coefficient. From PLINK:
    FID, IID, O(HOM), E(HOM), N(NM), F
    Additional columns may be present but will be ignored.
    """
    consanguineous_samples = {}
    myopen = gzip.open if path.endswith('.gz') else open
    with myopen(path) as inf:
        _ = inf.readline()
        for line in inf:
            cols = line.strip().split()
            if float(cols[5]) > cutoff:
                consanguineous_samples[cols[1]] = True
    return consanguineous_samples