def build_sample_map(flowcell):
    """Build sample map ``dict`` for the given flowcell."""
    result = {}
    rows = [(lane, lib["name"]) for lib in flowcell["libraries"] for lane in lib["lanes"]]
    i = 1
    for _, name in sorted(set(rows)):
        if name not in result:
            result[name] = "S{}".format(i)
            i += 1
    return result