def _align(sequenceA, sequenceB, match_fn, gap_A_fn, gap_B_fn, penalize_extend_when_opening, penalize_end_gaps, align_globally, gap_char, force_generic, score_only, one_alignment_only):
 if ((not sequenceA) or (not sequenceB)):
  return []
 try:
  (sequenceA + gap_char)
  (sequenceB + gap_char)
 except TypeError:
  raise TypeError((('both sequences must be of the same type, either ' + 'string/sequence object or list. Gap character must ') + 'fit the sequence type (string or list)'))
 if (not isinstance(sequenceA, list)):
  sequenceA = str(sequenceA)
 if (not isinstance(sequenceB, list)):
  sequenceB = str(sequenceB)
 if ((not force_generic) and isinstance(gap_A_fn, affine_penalty) and isinstance(gap_B_fn, affine_penalty)):
  (open_A, extend_A) = (gap_A_fn.open, gap_A_fn.extend)
  (open_B, extend_B) = (gap_B_fn.open, gap_B_fn.extend)
  x = _make_score_matrix_fast(sequenceA, sequenceB, match_fn, open_A, extend_A, open_B, extend_B, penalize_extend_when_opening, penalize_end_gaps, align_globally, score_only)
 else:
  x = _make_score_matrix_generic(sequenceA, sequenceB, match_fn, gap_A_fn, gap_B_fn, penalize_end_gaps, align_globally, score_only)
 (score_matrix, trace_matrix) = x
 starts = _find_start(score_matrix, align_globally)
 best_score = max([x[0] for x in starts])
 if score_only:
  return best_score
 tolerance = 0
 starts = [(score, pos) for (score, pos) in starts if (rint(abs((score - best_score))) <= rint(tolerance))]
 return _recover_alignments(sequenceA, sequenceB, starts, score_matrix, trace_matrix, align_globally, gap_char, one_alignment_only, gap_A_fn, gap_B_fn)

def _align ( sequenceA , sequenceB , match_fn , gap_A_fn , gap_B_fn , penalize_extend_when_opening , penalize_end_gaps , align_globally , gap_char , force_generic , score_only , one_alignment_only ) : if ( ( not sequenceA ) or ( not sequenceB ) ) : return [ ] try : ( sequenceA + gap_char ) ( sequenceB + gap_char ) except TypeError : raise TypeError ( ( ( 'both sequences must be of the same type, either ' + 'string/sequence object or list. Gap character must ' ) + 'fit the sequence type (string or list)' ) ) if ( not isinstance ( sequenceA , list ) ) : sequenceA = str ( sequenceA ) if ( not isinstance ( sequenceB , list ) ) : sequenceB = str ( sequenceB ) if ( ( not force_generic ) and isinstance ( gap_A_fn , affine_penalty ) and isinstance ( gap_B_fn , affine_penalty ) ) : ( open_A , extend_A ) = ( gap_A_fn . open , gap_A_fn . extend ) ( open_B , extend_B ) = ( gap_B_fn . open , gap_B_fn . extend ) x = _make_score_matrix_fast ( sequenceA , sequenceB , match_fn , open_A , extend_A , open_B , extend_B , penalize_extend_when_opening , penalize_end_gaps , align_globally , score_only ) else : x = _make_score_matrix_generic ( sequenceA , sequenceB , match_fn , gap_A_fn , gap_B_fn , penalize_end_gaps , align_globally , score_only ) ( score_matrix , trace_matrix ) = x starts = _find_start ( score_matrix , align_globally ) best_score = max ( [ x [ 0 ] for x in starts ] ) if score_only : return best_score tolerance = 0 starts = [ ( score , pos ) for ( score , pos ) in starts if ( rint ( abs ( ( score - best_score ) ) ) <= rint ( tolerance ) ) ] return _recover_alignments ( sequenceA , sequenceB , starts , score_matrix , trace_matrix , align_globally , gap_char , one_alignment_only , gap_A_fn , gap_B_fn )
align a set of terms .