def _replace_parenthesized_ambigs(seq, rev_ambig_values):
 opening = seq.find('(')
 while (opening > (-1)):
  closing = seq.find(')')
  if (closing < 0):
   raise NexusError(('Missing closing parenthesis in: ' + seq))
  elif (closing < opening):
   raise NexusError(('Missing opening parenthesis in: ' + seq))
  ambig = ''.join(sorted(seq[(opening + 1):closing]))
  ambig_code = rev_ambig_values[ambig.upper()]
  if (ambig != ambig.upper()):
   ambig_code = ambig_code.lower()
  seq = ((seq[:opening] + ambig_code) + seq[(closing + 1):])
  opening = seq.find('(')
 return seq

def _replace_parenthesized_ambigs ( seq , rev_ambig_values ) : opening = seq . find ( '(' ) while ( opening > ( - 1 ) ) : closing = seq . find ( ')' ) if ( closing < 0 ) : raise NexusError ( ( 'Missing closing parenthesis in: ' + seq ) ) elif ( closing < opening ) : raise NexusError ( ( 'Missing opening parenthesis in: ' + seq ) ) ambig = '' . join ( sorted ( seq [ ( opening + 1 ) : closing ] ) ) ambig_code = rev_ambig_values [ ambig . upper ( ) ] if ( ambig != ambig . upper ( ) ) : ambig_code = ambig_code . lower ( ) seq = ( ( seq [ : opening ] + ambig_code ) + seq [ ( closing + 1 ) : ] ) opening = seq . find ( '(' ) return seq
replaces ambigs in xxxxxx format by iupac ambiguity code .