from typing import OrderedDict


def readUniqueHashMap(fileName, keyIndex = 1):
  """Read file list file and return key/value hash map. Can be used to sample name/sample file definition, or parameter options definition.
  
  Arguments:
    fileName {str} -- the file containing at least two columns, one is key and another is value, no header. One key corresponds to one value.
    keyIndex {int} -- the column index (0-based) of key.
  
  Result:
    Hash map, key:value
  """

  valueIndex = 1 if keyIndex == 0 else 0
  maxIndex = max(valueIndex, keyIndex)

  result = OrderedDict()
  with open(fileName, "r") as f:
    for line in f:
      parts = line.rstrip().split('\t')
      if(len(parts) > maxIndex):
        result[parts[keyIndex]] = parts[valueIndex]

  return(result)