def MatchScorerAmbigs(match, mismatch, matches=None):
 matches = (matches or {'A': {'A': None}, 'G': {'G': None}, 'C': {'C': None}, 'T': {'T': None}, '-': {'-': None}})
 for (ambig, chars) in DNASequence.iupac_degeneracies().iteritems():
  try:
   matches[ambig].update({}.fromkeys(chars))
  except KeyError:
   matches[ambig] = {}.fromkeys(chars)
  for char in chars:
   try:
    matches[char].update({ambig: None})
   except KeyError:
    matches[char] = {ambig: None}
 def scorer(x, y):
  if ((x not in matches) or (y not in matches)):
   raise ValueError(('Unknown character: %s or %s' % (x, y)))
  if (y in matches[x]):
   return match
  else:
   return mismatch
 return scorer

def MatchScorerAmbigs ( match , mismatch , matches = None ) : matches = ( matches or { 'A' : { 'A' : None } , 'G' : { 'G' : None } , 'C' : { 'C' : None } , 'T' : { 'T' : None } , '-' : { '-' : None } } ) for ( ambig , chars ) in DNASequence . iupac_degeneracies ( ) . iteritems ( ) : try : matches [ ambig ] . update ( { } . fromkeys ( chars ) ) except KeyError : matches [ ambig ] = { } . fromkeys ( chars ) for char in chars : try : matches [ char ] . update ( { ambig : None } ) except KeyError : matches [ char ] = { ambig : None } def scorer ( x , y ) : if ( ( x not in matches ) or ( y not in matches ) ) : raise ValueError ( ( 'Unknown character: %s or %s' % ( x , y ) ) ) if ( y in matches [ x ] ) : return match else : return mismatch return scorer
alternative scorer factory for sw_align which allows match to ambiguous chars it allows for matching to ambiguous characters which is useful for primer/sequence matching .