def matrix(args):

    p = OptionParser(matrix.__doc__)
    p.add_option("--seqids", help="File with seqids [default: %default]")
    opts, args = p.parse_args(args)

    if len(args) != 3:
        sys.exit(not p.print_help())

    bedfile, anchorfile, matrixfile = args
    ac = AnchorFile(anchorfile)
    seqidsfile = opts.seqids
    if seqidsfile:
        seqids = SetFile(seqidsfile, delimiter=',')

    order = Bed(bedfile).order
    blocks = ac.blocks
    m = defaultdict(int)
    fw = open(matrixfile, "w")
    aseqids = set()
    bseqids = set()
    for block in blocks:
        a, b, scores = zip(*block)
        ai, af = order[a[0]]
        bi, bf = order[b[0]]
        aseqid = af.seqid
        bseqid = bf.seqid
        if seqidsfile:
            if (aseqid not in seqids) or (bseqid not in seqids):
                continue
        m[(aseqid, bseqid)] += len(block)
        aseqids.add(aseqid)
        bseqids.add(bseqid)

    aseqids = list(aseqids)
    bseqids = list(bseqids)
    print >> fw, "\t".join(["o"] + bseqids)
    for aseqid in aseqids:
        print >> fw, "\t".join([aseqid] + \
                    [str(m[(aseqid, x)]) for x in bseqids])
Assign nodes to a new group.
dataset/ETHPy150Open tanghaibao/jcvi/compara/synteny.py/matrix--crossover with--dataset/ETHPy150Open ganeti/ganeti/lib/cmdlib/group.py/LUGroupAssignNodes.Exec