code: def truncate_name(name, rule=None):
      
      import re
  
      if rule is None:
          return name
  
      k = re.search("(?<=^head)[0-9]{1,2}$", rule)
      if k:
          k = k.group(0)
          tname = name[int(k):]
      else:
          k = re.search("(?<=^ohead)[0-9]{1,2}$", rule)
          if k:
              k = k.group(0)
              tname = name[:int(k)]
          else:
              k = re.search("(?<=^tail)[0-9]{1,2}$", rule)
              if k:
                  k = k.group(0)
                  tname = name[:-int(k)]
              else:
                  k = re.search("(?<=^otail)[0-9]{1,2}$", rule)
                  if k:
                      k = k.group(0)
                      tname = name[-int(k):]
                  else:
                      print(truncate_name.__doc__, file=sys.stderr)
                      raise ValueError('Wrong rule for truncation!')
      return tname
docs: shorten taxa names for tree display
  
      Options of rule. This only affects tree display.
      - headn (eg. head3 truncates first 3 chars)
      - oheadn (eg. ohead3 retains only the first 3 chars)
      - tailn (eg. tail3 truncates last 3 chars)
      - otailn (eg. otail3 retains only the last 3 chars)
      n = 1 ~ 99