def filter_by_datasets(data, datasets):
    """ Given a list of datasets, limit the data frame to reads coming from
        only thoes datasets """

    # Validate dataset names first
    permitted_datasets = set(list(data.dataset))
    for d in datasets:
        if d not in permitted_datasets:
            raise ValueError("Invalid dataset name: %s" % (d))

    data = data[data['dataset'].isin(datasets)]
    return data