code: def validate(args):
      
      p = OptionParser(validate.__doc__)
      opts, args = p.parse_args(args)
  
      if len(args) != 2:
          sys.exit(not p.print_help())
  
      imputed, withheld = args
      register = {}
      fp = open(withheld)
      for row in fp:
          if row[0] == "#":
              continue
          v = VcfLine(row)
          register[(v.seqid, v.pos)] = v.genotype
  
      logging.debug("Imported {0} records from `{1}`".\
                      format(len(register), withheld))
  
      fp = must_open(imputed)
      hit = concordant = 0
      seen = set()
      for row in fp:
          if row[0] == "#":
              continue
          v = VcfLine(row)
          chr, pos, genotype = v.seqid, v.pos, v.genotype
          if (chr, pos) in seen:
              continue
          seen.add((chr, pos))
          if (chr, pos) not in register:
              continue
          truth = register[(chr, pos)]
          imputed = genotype.split(":")[0]
          if "|" in imputed:
              imputed = "/".join(sorted(genotype.split(":")[0].split("|")))
              #probs = [float(x) for x in genotype.split(":")[-1].split(",")]
              #imputed = max(zip(probs, ["0/0", "0/1", "1/1"]))[-1]
          hit += 1
          if truth == imputed:
              concordant += 1
          else:
              print(row.strip(), "truth={0}".format(truth), file=sys.stderr)
  
      logging.debug("Total concordant: {0}".\
              format(percentage(concordant, hit)))
docs: %prog validate imputed.vcf withheld.vcf
  
      Validate imputation against withheld variants.