def get_match_score()

in files/lambda_code/call_cm_other_models_lambda.py [0:0]


def get_match_score(string_1=None,string_2=None,normalize_max=True):
    '''
    Get the score of the match between 2 strings. This uses the Smith-Waterman (SW) algorithm.
    SW computes local alighments between the two strings, and returns the match percentage between the two.
    If normalize_max=True, the score is normalized based on the maximum string length. If not, the score is normalized that by length of string_1.
    Note: The normalized SW score may be not symmetric.
    '''
    match = 1
    mismatch = -1
    #set lower gap penalty to encourage longer matches.
    gap_penalty = -.5
    scoring = swalign.NucleotideScoringMatrix(match, mismatch)
    sw = swalign.LocalAlignment(scoring,gap_penalty)
    z=sw.align(string_1,string_2)
    total_score=z.score

    len_to_divide=len(string_1)

    if normalize_max==True:
        len_to_divide=max(len(string_1),len(string_2))
    score=total_score/len_to_divide
    return(score)