Package: sciencebeam-alignment
ScienceBeam AlignmentScienceBeam Alignment provides generic low-level sequence alignment utility functions, similar to Python'sSequenceMatcher.This project is currently mainly used for training data generation, related to theScienceBeam project. Although this project itself has no ScienceBeam dependency and can be considered a standalone sequence alignment library. It is however more targeted at document size sequences rather than massive gene sequences.Pre-requisitesPython 2 or 3APISequenceMatcherThe mostly drop-in replacement of Python'sSequenceMatcheris provided byfuzzywuzzy'sStringMatcher.In that respect,sciencebeam-alignmentmerely provides a wrapper with fallback.WordSequenceMatcherA wrapper around the aforementionedSequenceMatcher, but matching on word level tokens only.It currently only implementsget_matching_blocks.The main advantage is that it is much faster for long texts, because it won't have to match individual characters. It isn't recommended for short texts, where character level alignment is probably more desirable.example match results:>>>fromsciencebeam_alignment.word_sequence_matcherimport(...WordSequenceMatcher...)>>>WordSequenceMatcher(a='word1',b='word2').get_matching_blocks()[]>>>WordSequenceMatcher(a='a word1 b',b='x word1 y').get_matching_blocks()[(2,2,5)]GlobalSequenceMatcher and LocalSequenceMatcherTheGlobalSequenceMatcher and LocalSequenceMatcherimplements theNeedleman-Wunschglobal alignmentas well as theSmith-Watermanlocal alignment algorithms. The implementation is somewhat inspired bypython-alignment.It does implementget_matching_blocksto match Python'sSequenceMatcher.By passing in a scoring object, the results can be influenced (e.g. gaps can be penalized more than mismatches).It does also provide an optimized implementation usingCython. The level of optimization depends on the type of passed in sequences and scoring. The fastest being with integer sequences and simple scoring. Especially with longer sequences, the potential speed ups can be significant.>>>fromsciencebeam_alignment.alignimportLocalSequenceMatcher,SimpleScoring>>>DEFAULT_SCORING=SimpleScoring(match_score=3,mismatch_score=-1,gap_score=-2)>>>LocalSequenceMatcher(a='a word1 b',b='x word2 y',scoring=DEFAULT_SCORING).get_matching_blocks()[(1,1,5),(7,7,1),(9,9,0)]In addition, theget_multiple_matching_blockscan be used to retrieve multiple matching blocks with the same score:>>>fromsciencebeam_alignment.alignimportGlobalSequenceMatcher,SimpleScoring>>>DEFAULT_SCORING=SimpleScoring(match_score=3,mismatch_score=-1,gap_score=-2)>>>matcher=GlobalSequenceMatcher(a='xyzabc',b='abcxyz',scoring=DEFAULT_SCORING)>>>list(matcher.get_multiple_matching_blocks(limit=2))[[(3,0,3)],[(0,3,3)]]get_multiple_matching_blocksreturns a generator. The number of variations can be limited using thelimitargument or by simply stopping early.TheGlobalSequenceMatchercan also be used to calculate theLevenshtein distance(oredit distance). An example is provided insciencebeam_alignment.levenshtein:>>>fromsciencebeam_alignment.levenshteinimportget_levenshtein_distance>>>get_levenshtein_distance('kitten','sitting')3>>>fromsciencebeam_alignment.levenshteinimportget_levenshtein_ratio>>>get_levenshtein_ratio('kitten','sitting')0.5714285714285714Calculating the levenshtein distance is mainly provided as an example. You might want to consider usingpython-Levenshtein.To check whether the fast implementation is enabled:>>>fromsciencebeam_alignment.alignimportnative_enabled>>>native_enabledTrueDevelopmentDevelopment can be done either using Docker (default) or a virtual environment.All commands are available viamake.Development using DockerBuild and run tests:makebuildtestOr intended for CI:makeci-build-and-testDevelopment using a virtual environmentmaketargets with thedev-prefix are intended for the use with the virtual environment.This requires that you already have Python installed.Setup (virtual environment)makedev-venvTo update the dependencies:makedev-installCython (virtual environment)Compile code using Cython:makedev-cython-cleandev-cython-compileTests (virtual environment)make dev-testOr:make dev-watch