code: def to_cigar_unit(source):
      """Creates a cigar_pb2 CigarUnit from source.
  
      This function attempts to convert source into a CigarUnit protobuf. If
      source is a string, it must be a single CIGAR string specification like
      '12M'. If source is a tuple or a list, must have exactly two elements
      (operation_length, opstr). operation_length can be a string or int, and must
      be >= 1. opstr should be a single character CIGAR specification (e.g., 'M').
      If source is already a CigarUnit, it is just passed through unmodified.
  
      Args:
        source: many types allowed. The object we want to convert to a CigarUnit
          proto.
  
      Returns:
        CigarUnit proto with operation_length and operation set to values from
          source.
  
      Raises:
        ValueError: if source cannot be converted or is malformed.
      """
      try:
          if isinstance(source, cigar_pb2.CigarUnit):
              return source
          elif isinstance(source, six.string_types):
              l, op = source[:-1], source[-1]
          elif isinstance(source, (tuple, list)):
              l, op = source
          else:
              raise ValueError("Unexpected source", source)
  
          if isinstance(op, six.string_types):
              op = CHAR_TO_CIGAR_OPS[op]
          l = int(l)
          if l < 1:
              raise ValueError("Length must be >= 1", l)
          return cigar_pb2.CigarUnit(
              operation=op, operation_length=int(l)
          )
      except (KeyError, IndexError):
          raise ValueError(
              "Failed to convert {} into a CigarUnit".format(source)
          )
  
file_path: deepvariant/third_party/nucleus/util/cigar.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import re
  import six
  from third_party.nucleus.protos import cigar_pb2
label_desc: Use image node_id 4 for calling a global function with example usage: to_cigar_unit(source) and returns: cigar_pb2, source