code: def split(args):
      
      p = OptionParser(split.__doc__)
      mode_choices = ("batch", "cycle", "optimal")
      p.add_option("--all", default=False, action="store_true",
              help="split all records [default: %default]")
      p.add_option("--mode", default="optimal", choices=mode_choices,
              help="Mode when splitting records [default: %default]")
      p.add_option("--format", choices=("fasta", "fastq", "txt", "clust"),
              help="input file format [default: %default]")
  
      opts, args = p.parse_args(args)
  
      if len(args) != 3:
          sys.exit(not p.print_help())
  
      filename, outdir, N = args
      fs = FileSplitter(filename, outputdir=outdir,
                        format=opts.format, mode=opts.mode)
  
      if opts.all:
          logging.debug("option -all override N")
          N = fs.num_records
      else:
          N = min(fs.num_records, int(N))
          assert N > 0, "N must be > 0"
  
      logging.debug("split file into %d chunks" % N)
      fs.split(N)
  
      return fs
docs: %prog split file outdir N
  
      Split file into N records. This allows splitting FASTA/FASTQ/TXT file
      properly at boundary of records. Split is useful for parallelization
      on input chunks.
  
      Option --mode is useful on how to break into chunks.
      1. chunk - chunk records sequentially, 1-100 in file 1, 101-200 in file 2, etc.
      2. cycle - chunk records in Round Robin fashion
      3. optimal - try to make split file of roughly similar sizes, using LPT
      algorithm. This is the default.