def local_align_primer_seq(primer, sequence, sw_scorer=equality_scorer_ambigs):
 query_primer = primer
 query_sequence = str(sequence)
 alignment = pair_hmm_align_unaligned_seqs([query_primer, query_sequence])
 primer_hit = str(alignment.Seqs[0])
 target_hit = str(alignment.Seqs[1])
 insertions = primer_hit.count('-')
 deletions = target_hit.count('-')
 mismatches = 0
 for i in range(len(target_hit)):
  if ((sw_scorer(target_hit[i], primer_hit[i]) == (-1)) and (target_hit[i] != '-') and (primer_hit[i] != '-')):
   mismatches += 1
 try:
  hit_start = query_sequence.index(target_hit.replace('-', ''))
 except ValueError:
  raise ValueError(('substring not found, query string %s, target_hit %s' % (query_sequence, target_hit)))
 mismatch_count = ((insertions + deletions) + mismatches)
 return (mismatch_count, hit_start)

def local_align_primer_seq ( primer , sequence , sw_scorer = equality_scorer_ambigs ) : query_primer = primer query_sequence = str ( sequence ) alignment = pair_hmm_align_unaligned_seqs ( [ query_primer , query_sequence ] ) primer_hit = str ( alignment . Seqs [ 0 ] ) target_hit = str ( alignment . Seqs [ 1 ] ) insertions = primer_hit . count ( '-' ) deletions = target_hit . count ( '-' ) mismatches = 0 for i in range ( len ( target_hit ) ) : if ( ( sw_scorer ( target_hit [ i ] , primer_hit [ i ] ) == ( - 1 ) ) and ( target_hit [ i ] != '-' ) and ( primer_hit [ i ] != '-' ) ) : mismatches += 1 try : hit_start = query_sequence . index ( target_hit . replace ( '-' , '' ) ) except ValueError : raise ValueError ( ( 'substring not found, query string %s, target_hit %s' % ( query_sequence , target_hit ) ) ) mismatch_count = ( ( insertions + deletions ) + mismatches ) return ( mismatch_count , hit_start )
perform local alignment of primer and sequence primer: input primer sequence sequence: target sequence to test primer against returns the number of mismatches .