code: 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("\t".join(["o"] + bseqids), file=fw)
      for aseqid in aseqids:
          print("\t".join([aseqid] + \
                      [str(m[(aseqid, x)]) for x in bseqids]), file=fw)
docs: %prog matrix all.bed anchorfile matrixfile
  
      Make oxford grid based on anchors file.