-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Edit_Distance algorithm for genetic string matching #10336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
f574ce1
caeda9f
f3303b0
a6ef5bd
00da496
4d1fd42
1455e30
c97c94a
a5d5316
4d64c3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def edit_distance(source, target): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: As there is no test file in this pull request nor any test function or class in the file Please provide type hint for the parameter: Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: Please provide type hint for the parameter: Please provide type hint for the parameter: |
||
""" | ||
Edit distance algorithm is a string metric, i.e., it is a way of quantifying | ||
how dissimilar two strings are to one another, that is measured by | ||
counting the minimum number of operations required to transform one string | ||
into another. | ||
In genetic algorithms consisting of A,T, G, and C ncleotides, this matching | ||
becomes essential in understanding the mutation in succesive genes. | ||
Hence, this algorithm comes in handy when we are trying to quantify the | ||
mutations in successive generations. | ||
Args: | ||
source (string): This is the source string, the initial string with | ||
respect to which we are calculating the edit_distance for the target | ||
target (string): This is the target string, which is formed after n | ||
number of operations performed on the source string. | ||
Assumptions: | ||
The cost of operations (insertion, deletion and subtraction) is all 1 | ||
""" | ||
delta = {True: 0, False: 1} # Substitution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An error occurred while parsing the file: Traceback (most recent call last):
File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
reports = lint_file(
^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 19:4.
parser error: error at 18:3: expected INDENT
delta = {True: 0, False: 1} # Substitution
^ |
||
|
||
if len(source) == 0: | ||
return len(target) | ||
elif len(target) == 0: | ||
return len(source) | ||
|
||
return min( | ||
edit_distance(source[:-1], target[:-1]) + delta[source[-1] == target[-1]], | ||
edit_distance(source, target[:-1]) + 1, | ||
edit_distance(source[:-1], target) + 1, | ||
) | ||
|
||
|
||
print(edit_distance("ATCGCTG", "TAGCTAA")) | ||
# Answer is 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
edit_distance
. If the function does not return a value, please provide the type hint as:def function() -> None:
As there is no test file in this pull request nor any test function or class in the file
genetic_algorithm/edit_distance.py
, please provide doctest for the functionedit_distance
Please provide type hint for the parameter:
source
Please provide type hint for the parameter:
target