code: def concatenate(
      b: Batch,
      files: List[ResourceFile],
      image: Optional[str] = None,
      branching_factor: int = 100,
  ) -> ResourceFile:
      """
      Concatenate files using tree aggregation.
  
      Examples
      --------
      Create and execute a batch that concatenates output files:
  
      >>> b = Batch()
      >>> j1 = b.new_job()
      >>> j1.command(f'touch {j1.ofile}')
      >>> j2 = b.new_job()
      >>> j2.command(f'touch {j2.ofile}')
      >>> j3 = b.new_job()
      >>> j3.command(f'touch {j3.ofile}')
      >>> files = [j1.ofile, j2.ofile, j3.ofile]
      >>> ofile = concatenate(b, files, branching_factor=2)
      >>> b.run()
  
      Parameters
      ----------
      b:
          Batch to add concatenation jobs to.
      files:
          List of files to concatenate.
      branching_factor:
          Grouping factor when concatenating files.
      image:
          Image to use. Must have the cat command.
  
      Returns
      -------
      Concatenated output file.
      """
  
      def _concatenate(b, name, xs):
          j = b.new_job(name=name)
          if image:
              j.image(image)
          j.command(f'cat {" ".join(xs)} > {j.ofile}')
          return j.ofile
  
      if len(files) == 0:
          raise BatchException(
              "Must have at least one file to concatenate."
          )
  
      if not all(isinstance(f, ResourceFile) for f in files):
          raise BatchException(
              "Invalid input file(s) - all inputs must be resource files."
          )
  
      return _combine(
          _concatenate,
          b,
          "concatenate",
          files,
          branching_factor=branching_factor,
      )
  
file_path: hail/hail/python/hailtop/batch/utils.py
imports: import math
  from typing import List, Optional
  from ..utils.utils import grouped, digits_needed
  from .batch import Batch
  from .exceptions import BatchException
  from .resource import ResourceGroup, ResourceFile
label_desc: Use image node_id 1 for calling a global function with example usage: concatenate(b, files, image, branching_factor) and returns: _combine, j