MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / score_function

Function score_function

dynamic_programming/smith_waterman.py:12–36  ·  view source on GitHub ↗

Calculate the score for a character pair based on whether they match or mismatch. Returns 1 if the characters match, -1 if they mismatch, and -2 if either of the characters is a gap. >>> score_function('A', 'A') 1 >>> score_function('A', 'C') -1 >>> score_function('-

(
    source_char: str,
    target_char: str,
    match: int = 1,
    mismatch: int = -1,
    gap: int = -2,
)

Source from the content-addressed store, hash-verified

10
11
12def score_function(
13 source_char: str,
14 target_char: str,
15 match: int = 1,
16 mismatch: int = -1,
17 gap: int = -2,
18) -> int:
19 """
20 Calculate the score for a character pair based on whether they match or mismatch.
21 Returns 1 if the characters match, -1 if they mismatch, and -2 if either of the
22 characters is a gap.
23 >>> score_function('A', 'A')
24 1
25 >>> score_function('A', 'C')
26 -1
27 >>> score_function('-', 'A')
28 -2
29 >>> score_function('A', '-')
30 -2
31 >>> score_function('-', '-')
32 -2
33 """
34 if "-" in (source_char, target_char):
35 return gap
36 return match if source_char == target_char else mismatch
37
38
39def smith_waterman(

Callers 2

smith_watermanFunction · 0.85
tracebackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected