Package: sequence-align
sequence_alignEfficient implementations ofNeedleman-Wunschand other sequence alignment algorithms written in Rust with Python bindings viaPyO3.Installationsequence_alignis distributed viaPyPifor Python 3.7+, making installation as simple as the following --
no special setup required for cross-platform compatibility, Rust installation, etc.!pipinstallsequence_alignAlternatively, if one wishes to develop forsequence_align, first ensure that bothPythonandRustare installed on your system. Then, installMaturinand runmaturin develop(optionally with the-rflag to compile a release build, instead of an unoptimized debug build)
from the root of your cloned repo to build and installsequence_alignin your active Python environment.Quick StartPairwise sequence algorithms are available insequence_align.pairwise.
Currently, two algorithms are implemented: theNeedleman-Wunsch algorithmandHirschberg’s algorithm. Needleman-Wunsch is
commonly used for global sequence alignment, but suffers from the fact that it usesO(M*N)space,
whereMandNare the lengths of the two sequences being aligned. Hirschberg’s algorithm modifies Needleman-Wunsch
to have the same time complexity (O(M*N)), but only useO(min{M, N})space, making it an appealing option
for memory-limited applications or extremely large sequences.Using these algorithms is straightforward:fromsequence_align.pairwiseimporthirschberg,needleman_wunsch# See https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm#/media/File:Needleman-Wunsch_pairwise_sequence_alignment.png# Use Needleman-Wunsch default scores (match=1, mismatch=-1, indel=-1)seq_a=["G","A","T","T","A","C","A"]seq_b=["G","C","A","T","G","C","G"]aligned_seq_a,aligned_seq_b=needleman_wunsch(seq_a,seq_b,match_score=1.0,mismatch_score=-1.0,indel_score=-1.0,gap="_",)# Expects ["G", "_", "A", "T", "T", "A", "C", "A"]print(aligned_seq_a)# Expects ["G", "C", "A", "_", "T", "G", "C", "G"]print(aligned_seq_b)# See https://en.wikipedia.org/wiki/Hirschberg%27s_algorithm#Exampleseq_a=["A","G","T","A","C","G","C","A"]seq_b=["T","A","T","G","C"]aligned_seq_a,aligned_seq_b=hirschberg(seq_a,seq_b,match_score=2.0,mismatch_score=-1.0,indel_score=-2.0,gap="_",)# Expects ["A", "G", "T", "A", "C", "G", "C", "A"]print(aligned_seq_a)# Expects ["_", "_", "T", "A", "T", "G", "C", "_"]print(aligned_seq_b)Performance BenchmarksAll tests below were conducted sequentially on aAWS R5.4 instancewith 16 cores and 128 GB of memory. The pair of sequences for alignment consist of a character sequence of randomly
selected A/C/G/T nucleotide bases along with another that is identical, except with 10% of the characters randomly
perturbed by deletion, insertion of another randomly-selected character after the entry, or replacement with a
different randomly-selected character.As one can see, whilesequence_alignis comparable to some other toolkits in terms of speed, its memory performance
isbest-in-class, even when compared to toolkits using the same algorithm, such as Needleman-Wunsch being used inpyseq-align.(Please note that some lines terminate early, as some toolkits took prohibitively long and/or ran out of memory at higher scales.)LicenseLicensed under the Apache 2.0 License. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.Copyright 2023-present Kensho Technologies, LLC. The present date is determined by the timestamp of the most recent commit in the repository.