Skip to content

added smith waterman algorithm #9001

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

Merged
merged 12 commits into from
Sep 30, 2023
Merged

Conversation

BAW2501
Copy link
Contributor

@BAW2501 BAW2501 commented Aug 20, 2023

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper bot added require descriptive names This PR needs descriptive function and/or variable names awaiting reviews This PR is ready to be reviewed labels Aug 20, 2023
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@BAW2501 BAW2501 requested a review from CaedenPH August 22, 2023 20:10
Copy link
Contributor

@tianyizheng02 tianyizheng02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I think the implementation looks good, but I have some general feedback:

  1. Can we make the score constants customizable? For example, we could have function parameters with default values so that the user can choose their score constants.
  2. Can we have more variety in the doctests? The current doctests are mostly variations on the same example input. The Wikipedia page for the Smith–Waterman algorithm has a more complex example, and that'd be good to add as a doctest (though the example uses different score constants).

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Sep 25, 2023
@algorithms-keeper algorithms-keeper bot removed require descriptive names This PR needs descriptive function and/or variable names tests are failing Do not merge until tests pass labels Sep 25, 2023
return match if source_char == target_char else mismatch


def smith_waterman(query: str, subject: str) -> list[list[int]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add optional parameters for the score constants in this function's header as well? Users will call this function specifically to run the algorithm, and currently there's no way for the user to pass in their desired score constants into this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i hate repeating code, but there seems to be no way around it when it comes to default params

def smith_waterman(
    query: str,
    subject: str,
    match: int = 1,
    mismatch: int = -1,
    gap: int = -2,
) -> list[list[int]]:
def score_function(
    source_char: str,
    target_char: str,
    match: int = 1,
    mismatch: int = -1,
    gap: int = -2,
) -> int:

either way i got about it i'll have to unpack the kwargs in score function params or the body of the function and i think the params are a better way for clarity

@tianyizheng02 tianyizheng02 merged commit 467903a into TheAlgorithms:master Sep 30, 2023
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Sep 30, 2023
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* added smith waterman algorithm

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* descriptive names for the parameters a and b

* doctesting lowercase upcase empty string cases

* updated block quot,fixed traceback and doctests

* shorter block quote

Co-authored-by: Tianyi Zheng <[email protected]>

* global vars to func params,more doctests

* updated doctests

* user access to SW params

* formating

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tianyi Zheng <[email protected]>
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants