
[](https://pypi.org/project/minineedle/)
[](https://pypi.org/project/minineedle/)

[](LICENSE)
<img width="250" src="https://github.com/scastlara/minineedle/blob/master/assets/logo.png"/>
Needleman-Wunsch and Smith-Waterman algorithms in python for any iterable objects.
## Algorithms
### Needleman-Wunsch
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3f/Needleman-Wunsch_pairwise_sequence_alignment.png" width="300px">
> The Needleman–Wunsch algorithm is an algorithm used in bioinformatics to align protein or nucleotide sequences. It was one of the first applications of dynamic programming to compare biological sequences. The algorithm was developed by Saul B. Needleman and Christian D. Wunsch and published in 1970. The algorithm essentially divides a large problem (e.g. the full sequence) into a series of smaller problems and uses the solutions to the smaller problems to reconstruct a solution to the larger problem. It is also sometimes referred to as the optimal matching algorithm and the global alignment technique. The Needleman–Wunsch algorithm is still widely used for optimal global alignment, particularly when the quality of the global alignment is of the utmost importance.
>
> -- From the <cite>[Wikipedia article](https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm)</cite>
### Smith-Waterman
<img src="https://upload.wikimedia.org/wikipedia/commons/9/92/Smith-Waterman-Algorithm-Example-En.gif" width="300px">
> The Smith–Waterman algorithm performs local sequence alignment; that is, for determining similar regions between two strings of nucleic acid sequences or protein sequences. Instead of looking at the entire sequence, the Smith–Waterman algorithm compares segments of all possible lengths and optimizes the similarity measure.
>
> -- From the <cite>[Wikipedia article](https://en.wikipedia.org/wiki/Smith–Waterman_algorithm)</cite>
## Usage
```python
from minineedle import needle, smith, core
# Use miniseq objects
# Load sequences as miniseq FASTA object
import miniseq
fasta = miniseq.FASTA(filename="myfasta.fa")
seq1, seq2 = fasta[0], fasta[1]
# Or use strings, lists, etc
# seq1, seq2 = "ACTG", "ATCTG"
# seq1, seq2 = ["A","C","T","G"], ["A","T","C","T","G"]
# Create the instance
alignment: needle.NeedlemanWunsch[str] = needle.NeedlemanWunsch(seq1, seq2)
# or
# alignment smith.SmithWaterman[str] = smith.SmithWaterman(seq1, seq2)
# Make the alignment
alignment.align()
# Get the score
alignment.get_score()
# Get the sequences aligned as lists
al1, al2 = alignment.get_aligned_sequences(core.AlignmentFormat.list) # or "list"
# Get the sequences as strings
al1, al2 = alignment.get_aligned_sequences(core.AlignmentFormat.str) # or "str
# Change the matrix and run again
alignment.change_matrix(core.ScoreMatrix(match=4, miss=-4, gap=-2))
alignment.align()
# Print the sequences aligned
print(alignment)
# Change gap character
alignment.gap_character = "-gap-"
print(alignment)
# Sort a list of alignments by score
first_al = needle.NeedlemanWunsch(seq1, seq2)
second_al = needle.NeedlemanWunsch(seq3, seq4)
for align in sorted([first_al, second_al], reverse=True):
print(align)
```
## Install
```bash
pip install minineedle
```
## Classes
### NeedlemanWunsch
Needleman-Wunsch alignment class. It has the following attributes:
- seq1
- seq2
- alseq1
- alseq2
- nmatrix
- pmatrix
- smatrix
- score
- identity
- gap_character
To create the instance you have to provide two iterable objects with elements that can be compared with "==".
### SmithWaterman
Smith-Waterman alignment class. It has the following attributes:
- seq1
- seq2
- alseq1
- alseq2
- nmatrix
- pmatrix
- smatrix
- score
- identity
To create the instance you have to provide two iterable objects with elements that can be compared with "==".
### ScoreMatrix
With this class you can define your own score matrices. It has three attributes:
- match
- miss
- gap
## Methods
### align()
Performs the alignment.
### get_score()
Returns the score of the alignment. It runs align() if it has not been done yet.
### change_matrix(newmatrix)
Takes a ScoreMatrix object and updates the matrix for the alignment. You still have to run it calling `align()`.
### get identity()
Returns the % of identity (rounded with 2 decimal points).
### get_almatrix()
Return the alignment matrix as a list of lists.
Raw data
{
"_id": null,
"home_page": "https://github.com/scastlara/minineedle",
"name": "minineedle",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "",
"author": "S. Castillo-Lara",
"author_email": "sergiocastillo@ub.edu",
"download_url": "https://files.pythonhosted.org/packages/8e/d2/212a5a18f3bb9f85198b397d5ff914a577f2238f9d8fad66615d68de769f/minineedle-3.1.5.tar.gz",
"platform": null,
"description": "\n[](https://pypi.org/project/minineedle/)\n[](https://pypi.org/project/minineedle/)\n\n[](LICENSE)\n\n\n<img width=\"250\" src=\"https://github.com/scastlara/minineedle/blob/master/assets/logo.png\"/>\n\nNeedleman-Wunsch and Smith-Waterman algorithms in python for any iterable objects.\n\n## Algorithms\n\n### Needleman-Wunsch\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/3/3f/Needleman-Wunsch_pairwise_sequence_alignment.png\" width=\"300px\">\n\n> The Needleman\u2013Wunsch algorithm is an algorithm used in bioinformatics to align protein or nucleotide sequences. It was one of the first applications of dynamic programming to compare biological sequences. The algorithm was developed by Saul B. Needleman and Christian D. Wunsch and published in 1970. The algorithm essentially divides a large problem (e.g. the full sequence) into a series of smaller problems and uses the solutions to the smaller problems to reconstruct a solution to the larger problem. It is also sometimes referred to as the optimal matching algorithm and the global alignment technique. The Needleman\u2013Wunsch algorithm is still widely used for optimal global alignment, particularly when the quality of the global alignment is of the utmost importance. \n>\n> -- From the <cite>[Wikipedia article](https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm)</cite>\n\n### Smith-Waterman\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/9/92/Smith-Waterman-Algorithm-Example-En.gif\" width=\"300px\">\n\n> The Smith\u2013Waterman algorithm performs local sequence alignment; that is, for determining similar regions between two strings of nucleic acid sequences or protein sequences. Instead of looking at the entire sequence, the Smith\u2013Waterman algorithm compares segments of all possible lengths and optimizes the similarity measure. \n>\n> -- From the <cite>[Wikipedia article](https://en.wikipedia.org/wiki/Smith\u2013Waterman_algorithm)</cite>\n\n\n## Usage\n\n```python\nfrom minineedle import needle, smith, core\n\n# Use miniseq objects\n# Load sequences as miniseq FASTA object\nimport miniseq\nfasta = miniseq.FASTA(filename=\"myfasta.fa\")\nseq1, seq2 = fasta[0], fasta[1]\n\n# Or use strings, lists, etc\n# seq1, seq2 = \"ACTG\", \"ATCTG\"\n# seq1, seq2 = [\"A\",\"C\",\"T\",\"G\"], [\"A\",\"T\",\"C\",\"T\",\"G\"]\n\n# Create the instance\nalignment: needle.NeedlemanWunsch[str] = needle.NeedlemanWunsch(seq1, seq2)\n# or\n# alignment smith.SmithWaterman[str] = smith.SmithWaterman(seq1, seq2)\n\n# Make the alignment\nalignment.align()\n\n# Get the score\nalignment.get_score()\n\n# Get the sequences aligned as lists\nal1, al2 = alignment.get_aligned_sequences(core.AlignmentFormat.list) # or \"list\"\n\n# Get the sequences as strings\nal1, al2 = alignment.get_aligned_sequences(core.AlignmentFormat.str) # or \"str\n\n# Change the matrix and run again\nalignment.change_matrix(core.ScoreMatrix(match=4, miss=-4, gap=-2))\nalignment.align()\n\n# Print the sequences aligned\nprint(alignment)\n\n# Change gap character\nalignment.gap_character = \"-gap-\"\nprint(alignment)\n\n# Sort a list of alignments by score\nfirst_al = needle.NeedlemanWunsch(seq1, seq2)\nsecond_al = needle.NeedlemanWunsch(seq3, seq4)\n\nfor align in sorted([first_al, second_al], reverse=True):\n print(align)\n\n```\n\n\n## Install\n```bash\npip install minineedle\n```\n\n\n## Classes\n\n### NeedlemanWunsch\nNeedleman-Wunsch alignment class. It has the following attributes:\n- seq1\n- seq2 \n- alseq1 \n- alseq2\n- nmatrix \n- pmatrix \n- smatrix \n- score \n- identity\n- gap_character\n\nTo create the instance you have to provide two iterable objects with elements that can be compared with \"==\".\n\n### SmithWaterman\nSmith-Waterman alignment class. It has the following attributes:\n- seq1\n- seq2 \n- alseq1 \n- alseq2\n- nmatrix \n- pmatrix \n- smatrix \n- score \n- identity\n\nTo create the instance you have to provide two iterable objects with elements that can be compared with \"==\".\n\n### ScoreMatrix\nWith this class you can define your own score matrices. It has three attributes:\n- match\n- miss\n- gap\n\n\n## Methods\n### align()\nPerforms the alignment.\n\n### get_score()\nReturns the score of the alignment. It runs align() if it has not been done yet.\n\n### change_matrix(newmatrix)\nTakes a ScoreMatrix object and updates the matrix for the alignment. You still have to run it calling `align()`.\n\n### get identity()\nReturns the % of identity (rounded with 2 decimal points).\n\n### get_almatrix()\nReturn the alignment matrix as a list of lists.\n",
"bugtrack_url": null,
"license": "GPL3",
"summary": "Needleman-Wunsch and Smith-Waterman algorithms in python for any iterable objects.",
"version": "3.1.5",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "33d65cf14cc4543658d4b6328422412a551b01eacbeb32c223d33a47b4986aad",
"md5": "300278b1e05c787c23bed4cac9d7c79e",
"sha256": "5bf5643368fcd2c7cb3c22d61e9bd610301ebd63cd7cd668430a5c1af29ffd6e"
},
"downloads": -1,
"filename": "minineedle-3.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "300278b1e05c787c23bed4cac9d7c79e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 19651,
"upload_time": "2023-04-01T17:50:57",
"upload_time_iso_8601": "2023-04-01T17:50:57.568647Z",
"url": "https://files.pythonhosted.org/packages/33/d6/5cf14cc4543658d4b6328422412a551b01eacbeb32c223d33a47b4986aad/minineedle-3.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8ed2212a5a18f3bb9f85198b397d5ff914a577f2238f9d8fad66615d68de769f",
"md5": "7b9ab25606f224c7e0bfb2509b5aba83",
"sha256": "89d6a913daea13dff365063031b59f6f622084490ecb3cf0cbcf27d1a2ba4e41"
},
"downloads": -1,
"filename": "minineedle-3.1.5.tar.gz",
"has_sig": false,
"md5_digest": "7b9ab25606f224c7e0bfb2509b5aba83",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 17933,
"upload_time": "2023-04-01T17:50:58",
"upload_time_iso_8601": "2023-04-01T17:50:58.956401Z",
"url": "https://files.pythonhosted.org/packages/8e/d2/212a5a18f3bb9f85198b397d5ff914a577f2238f9d8fad66615d68de769f/minineedle-3.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-01 17:50:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "scastlara",
"github_project": "minineedle",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "minineedle"
}