def extract_pairs(abed, bbed, groups):
    """
    Called by fromgroups(), extract pairs specific to a pair of species.
    """
    agenome = op.basename(abed.filename).split(".")[0]
    bgenome = op.basename(bbed.filename).split(".")[0]
    aorder = abed.order
    border = bbed.order
    pairsfile = "{0}.{1}.pairs".format(agenome, bgenome)
    fw = open(pairsfile, "w")

    is_self = abed.filename == bbed.filename
    npairs = 0
    for group in groups:
        iter = combinations(group, 2) if is_self \
                    else product(group, repeat=2)

        for a, b in iter:
            if a not in aorder or b not in border:
                continue

            print >> fw, "\t".join((a, b))
            npairs += 1

    logging.debug("File `{0}` written with {1} pairs.".format(pairsfile, npairs))
dataset/ETHPy150Open tanghaibao/jcvi/apps/ks.py/extract_pairs/original