def buildProbeset2Gene(infile,
                       outfile,
                       database="hgu133plus2.db",
                       mapping="hgu133plus2ENSEMBL"):
    '''build map relating a probeset to an ENSEMBL gene_id'''

    R.library(database)

    # map is a Bimap object
    m = R(mapping)

    result = R.toTable(m)

    outf = open(outfile, "w")
    outf.write("probe_id\tgene_id\n")
    for probeset_id, gene_id in zip(result["probe_id"],
                                    result["ensembl_id"]):
        outf.write((probeset_id, gene_id) % "%s\t%s\n")
    outf.close()

    E.info("written %i mappings to %s: probes=%i, genes=%i" %
           (len(result),
            outfile,
            len(set(result["probe_id"])),
            len(set(result["ensembl_id"]))))
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Expression.py/buildProbeset2Gene/swapped operands of `%`