import pathlib


def read_score_file(filepath):
    """ Read in a score file

    :param filepath:
        The path to the score file
    :returns:
        A tuple of (sequence, score) or (sequence, score, subsequence)
    """
    filepath = pathlib.Path(filepath)

    records = []
    with filepath.open('rt') as fp:
        for line in fp:
            line = line.strip()
            if line == '':
                continue
            rec = line.split('\t')
            if len(rec) == 2:
                records.append((rec[0], float(rec[1])))
            elif len(rec) == 3:
                records.append((rec[0], float(rec[1]), rec[2]))
            else:
                raise ValueError('Malformed line: {}'.format(line))
    return records