code: def vcf(args):
      
      from jcvi.apps.grid import Jobs
  
      valid_callers = ("mpileup", "freebayes")
      p = OptionParser(vcf.__doc__)
      p.set_outfile(outfile="out.vcf.gz")
      p.add_option("--nosort", default=False, action="store_true",
                   help="Do not sort the BAM files")
      p.add_option("--caller", default="mpileup", choices=valid_callers,
                   help="Use variant caller [default: %default]")
      opts, args = p.parse_args(args)
  
      if len(args) < 2:
          sys.exit(not p.print_help())
  
      fastafile = args[0]
      bamfiles = args[1:]
      caller = opts.caller
  
      unsorted = [x for x in bamfiles if ".sorted." not in x]
      if opts.nosort:
          bamfiles = unsorted
      else:
          jargs = [[[x, "--unique"]] for x in unsorted]
          jobs = Jobs(index, args=jargs)
          jobs.run()
          bamfiles = [x.replace(".sorted.bam", ".bam") for x in bamfiles]
          bamfiles = [x.replace(".bam", ".sorted.bam") for x in bamfiles]
  
      if caller == "mpileup":
          cmd = "samtools mpileup -E -uf"
          cmd += " {0} {1}".format(fastafile, " ".join(bamfiles))
          cmd += " | bcftools call -vmO v"
      elif caller == "freebayes":
          cmd = "freebayes -f"
          cmd += " {0} {1}".format(fastafile, " ".join(bamfiles))
      sh(cmd, outfile=opts.outfile)
docs: %prog vcf fastafile bamfiles > out.vcf.gz
  
      Call SNPs on bam files.