def ratio_discrete(control_type, df, name2gene):
    eligible = df["name"].notnull()
    up = (df["ratio (A/B)"] > 1.0) & eligible
    down = (df["ratio (A/B)"] < 1.0) & eligible
    up_reg = [name2gene[name] for name in df["name"][up]\
            if name2gene[name] is not None]
    total = up.sum()
    LOGGER.info("  mapped %d/%d up-regulated genes (%.2f%%)", len(up_reg), total,
            len(up_reg) / total * 100.0)
    down_reg = [name2gene[name] for name in df["name"][down]\
            if name2gene[name] is not None]
    total = down.sum()
    LOGGER.info("  mapped %d/%d down-regulated genes (%.2f%%)", len(down_reg),
            total, len(down_reg) / total * 100.0)
    results = dict()
    results["gene"] = dict()
    results["gene"]["up"] = up_reg
    results["gene"]["down"] = down_reg
    results["tu"] = dict()
    results["tu"]["up"] = pyreg.active_tu(up_reg)
    results["tu"]["down"] = pyreg.active_tu(down_reg)
    results["operon"] = dict()
    results["operon"]["up"] = pyreg.active_operons(up_reg)
    results["operon"]["down"] = pyreg.active_operons(down_reg)
    return results
def simple_discrete(control_type, df, name2gene):
    eligible = df["name"].notnull()
    active = [name2gene[name] for name in df["name"][eligible]\
            if name2gene[name] is not None]
    LOGGER.info("  mapped %d/%d active genes (%.2f%%)", len(active), len(df),
            len(active) / len(df) * 100.0)
    results = dict()
    results["gene"] = active
    if control_type == "digital":
        results["gene"] = pyreg.active_genes_and_tf(active)
    results["tu"] = pyreg.active_tu(active)
    results["operon"] = pyreg.active_operons(active)
    return results