code: def sample(args):
      
      from random import random
  
      p = OptionParser(sample.__doc__)
      opts, args = p.parse_args(args)
  
      if len(args) != 2:
          sys.exit(not p.print_help())
  
      vcffile, ratio = args
      ratio = float(ratio)
      fp = open(vcffile)
      pf = vcffile.rsplit(".", 1)[0]
      kept = pf + ".kept.vcf"
      withheld = pf + ".withheld.vcf"
      fwk = open(kept, "w")
      fww = open(withheld, "w")
      nkept = nwithheld = 0
      for row in fp:
          if row[0] == '#':
              print(row.strip(), file=fwk)
              continue
          if random() < ratio:
              nkept += 1
              print(row.strip(), file=fwk)
          else:
              nwithheld += 1
              print(row.strip(), file=fww)
      logging.debug("{0} records kept to `{1}`".format(nkept, kept))
      logging.debug("{0} records withheld to `{1}`".format(nwithheld, withheld))
docs: %prog sample vcffile 0.9
  
      Sample subset of vcf file.