def parse_sample_id_map(sample_id_map_f):
 result = {}
 new_samp_id_counts = defaultdict(int)
 for line in sample_id_map_f:
  line = line.strip()
  if line:
   (samp_id, mapped_id) = line.split(' DCTB ')
   if (samp_id in result):
    raise ValueError(("The first column of the sample ID map must contain unique sample IDs ('%s' is repeated). The second column, however, may contain repeats." % samp_id))
   elif (new_samp_id_counts[mapped_id] >= 2):
    raise ValueError(("Only two original sample IDs may map to the same new sample ID. The new sample ID '%s' has more than two sample IDs mapping to it." % mapped_id))
   else:
    result[samp_id] = mapped_id
    new_samp_id_counts[mapped_id] += 1
 return result

def parse_sample_id_map ( sample_id_map_f ) : result = { } new_samp_id_counts = defaultdict ( int ) for line in sample_id_map_f : line = line . strip ( ) if line : ( samp_id , mapped_id ) = line . split ( ' DCTB ' ) if ( samp_id in result ) : raise ValueError ( ( "The first column of the sample ID map must contain unique sample IDs ('%s' is repeated). The second column, however, may contain repeats." % samp_id ) ) elif ( new_samp_id_counts [ mapped_id ] >= 2 ) : raise ValueError ( ( "Only two original sample IDs may map to the same new sample ID. The new sample ID '%s' has more than two sample IDs mapping to it." % mapped_id ) ) else : result [ samp_id ] = mapped_id new_samp_id_counts [ mapped_id ] += 1 return result
parses the lines of a sample id map file into a dictionary .