docs: def demultiplex_cells(fastq, out_dir, readnumber, prefix, cb_histogram, 
                        cb_cutoff):
      ''' Demultiplex a fastqtransformed FASTQ file into a FASTQ file for
      each cell.
      '''
      annotations = detect_fastq_annotations(fastq)
      re_string = construct_transformed_regex(annotations)
      parser_re = re.compile(re_string)
      readstring = "" if not readnumber else "_R{}".format(readnumber)
      filestring = "{prefix}{sample}{readstring}.fq"
      cb_set = set()
      if cb_histogram:
          cb_set = get_cb_depth_set(cb_histogram, cb_cutoff)
      sample_set = set()
      batch = collections.defaultdict(list)
      parsed = 0
      safe_makedir(out_dir)
      for read in read_fastq(fastq):
          parsed += 1
          match = parser_re.search(read).groupdict()
          sample = match['CB']
          if cb_set and sample not in cb_set:
              continue
          sample_set.add(sample)
          batch[sample].append(read)
          # write in batches to avoid opening up file handles repeatedly
          if not parsed % 10000000:
              for sample, reads in batch.items():
                  out_file = os.path.join(out_dir, filestring.format(**locals()))
                  with open(out_file, "a") as out_handle:
                      for read in reads:
                          out_handle.write(read)
              batch = collections.defaultdict(list)
  
      for sample, reads in batch.items():
          out_file = os.path.join(out_dir, filestring.format(**locals()))
          with open(out_file, "a") as out_handle:
              for read in reads:
                  out_handle.write(read)