def filterTagDataPandas(counts_table,
                        design_table,
                        filter_min_counts_per_row=1,
                        filter_min_counts_per_sample=10,
                        filter_percentile_rowsums=0):
    '''filter tag data.

    * remove rows with at least x number of counts

    * remove samples with a maximum of *min_sample_counts*

    * remove the lowest percentile of rows in the table, sorted
       by total tags per row
    '''

    # 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()

    empty_samples = filter_min_counts_per_sample < max_counts_per_sample
    sample_names = counts_table.columns
    nempty_samples = sum(empty_samples)

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

                          enumerate(empty_samples) if y])))
        raise NotImplementedError("removing empty samples needs to be done")
        # R('''countsTable <- countsTable[, max_counts >= %i]''' % filter_min_counts_per_sample)
        # R('''groups <- groups[max_counts >= %i]''' % filter_min_counts_per_sample)
        # R('''pairs <- pairs[max_counts >= %i]''' % filter_min_counts_per_sample)
        # observations, samples = tuple( R('''dim(countsTable)'''))

    # 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]

    return counts_table
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Expression.py/filterTagDataPandas/swapped operands of `<`