code: def _write_newick_leaf_label(out, node_id, node, otu_group, label_key, leaf_labels, unlabeled_counter, needs_quotes_pattern):
      
      otu_id = node['@otu']
      otu = otu_group[otu_id]
      if is_str_type(label_key):
          label = otu.get(label_key)
          if label is None:
              unlabeled_counter += 1
              o = otu.get('^ot:originalLabel', '<unknown>')
              label = "'*tip #{n:d} not mapped to OTT. Original label - {o}'"
              label = label.format(n=unlabeled_counter, o=o)
          else:
              label = quote_newick_name(label, needs_quotes_pattern)
      else:
          label = quote_newick_name(label_key(node_id, node, otu), needs_quotes_pattern)
      if leaf_labels is not None:
          if label not in leaf_labels[1]:
              leaf_labels[1][label] = len(leaf_labels[0])
              leaf_labels[0].append(label)
      out.write(label)
      return unlabeled_counter
docs: `label_key` is a string (a key in the otu object) or a callable that takes two arguments: the node, and the otu
      If `leaf_labels` is not None, it shoulr be a (list, dict) pair which will be filled. The list will
          hold the order encountered,
          and the dict will map name to index in the list