def get_rows_to_keep(mode, df, grp, samp_grps, qthreshold, min_child_non_leaf, min_child_nsamp, min_peptides,
                     min_pep_nsamp):
    """
    Use checking to find the rows (taxonomic or functional terms) that satisfy all of the filtering conditions for
    the specified group
    :param mode: either 'f', 't', or 'ft'
    :param df: data frame of functional and taxonomic terms. missing values are represented as 0.
    :param grp: grp to check conditions for
    :param samp_grps: SampleGroups() object
    :param qthreshold: minimum number of quantitations per grp
    :param min_child_non_leaf: minimum number of children for terms that are not leaves
    :param min_child_nsamp: minimum number of samples with sample children greater than min_child_non_leaf
    :param min_peptides: minimum number of peptides for each term
    :param min_pep_nsamp: minimum number of samples where the number of peptides has to be larger than
    min_peptides
    :return: boolean Series with rows to keep as True
    """
    # intensity
    intcols = samp_grps.sample_names[grp]
    keep_int = (df[intcols] > 0).apply(sum, axis=1) >= qthreshold

    # peptides
    peptide_cols = samp_grps.n_peptide_names_dict[grp]
    peptide_keep_series = (df[peptide_cols] > min_peptides)
    if min_pep_nsamp == "all":
        keep_peptide = peptide_keep_series.all(axis=1)
    else:
        keep_peptide = peptide_keep_series.apply(sum, axis=1) >= int(min_pep_nsamp)

    if mode != 'ft':
        # child non leaf
        child_cols = samp_grps.samp_children_names_dict[grp]
        child_keep_series = (df[child_cols] >= min_child_non_leaf) | (df[child_cols] == 0)
        if min_child_nsamp == "all":
            keep_child = child_keep_series.all(axis=1)
        else:
            keep_child = child_keep_series.apply(sum, axis=1) >= int(min_child_nsamp)
        all_keep = keep_int & keep_child & keep_peptide
    else:
        all_keep = keep_int & keep_peptide
    return all_keep