def filterTagDataPandas(counts_table,
                        design_table,
                        filter_min_counts_per_row=1,
                        filter_min_counts_per_sample=10,
                        filter_percentile_rowsums=0):

    # Remove windows with no data
    max_counts_per_row = counts_table.max(1)
    counts_table = counts_table[
        max_counts_per_row >= filter_min_counts_per_row]
    observations, samples = counts_table.shape
    E.info("trimmed data: %i observations for %i samples" %
           (observations, samples))

    # remove samples without data
    max_counts_per_sample = counts_table.max()

    low_samples = max_counts_per_sample < filter_min_counts_per_sample
    high_samples = [not x for x in low_samples.tolist()]
    sample_names = counts_table.columns
    nlow_samples = sum(low_samples)

    if nlow_samples:
        E.warn("%i empty samples are being removed: %s" %
               (nlow_samples,
                ",".join([sample_names[x] for x, y in

                          enumerate(low_samples) if y])))
        counts_table = counts_table.iloc[:, high_samples]

    # percentile filtering
    if filter_percentile_rowsums > 0:
        percentile = float(filter_percentile_rowsums) / 100.0
        sum_counts = counts_table.sum(1)
        take = sum_counts > sum_counts.quantile(percentile)
        E.info("percentile filtering at level %f: keep=%i, discard=%i" %
               (filter_percentile_rowsums,
                sum(take),
                len(take) - sum(take)))
        counts_table = counts_table[take]

    # need to return altered design table based on filtering
    # in case samples are removed!

    design_table = design_table.ix[high_samples]

    nobservations, nsamples = counts_table.shape

    return nobservations, nsamples, counts_table, design_table
filter tag data.
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Counts.py/filterTagDataPandas