Skip to content

Commit

Permalink
example commit for #176
Browse files Browse the repository at this point in the history
  • Loading branch information
manulera committed Aug 12, 2024
1 parent f156549 commit 787d00c
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 128 deletions.
35 changes: 29 additions & 6 deletions src/pydna/common_sub_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
# from array import array as _array
# import itertools as _itertools
from operator import itemgetter as _itemgetter
from typing import List as _List, Tuple as _Tuple

Match = _Tuple[int, int, int]

# def _kark_sort(s, SA, n, K):
# def radixpass(a, b, r, s, n, k):
Expand Down Expand Up @@ -312,16 +314,37 @@
# return match


def common_sub_strings(stringx: str, stringy: str, limit=25):
def common_sub_strings(stringx: str, stringy: str, limit=25) -> _List[Match]:
"""
Finds all common substrings between stringx and stringy, and returns
them sorted by length.
This function is case sensitive.
Parameters
----------
stringx : str
stringy : str
limit : int, optional
Returns
-------
list of tuple
[(startx1, starty1, length1),(startx2, starty2, length2), ...]
startx1 = startposition in x, where substring 1 starts
starty1 = position in y where substring 1 starts
length1 = lenght of substring
"""
from pydivsufsort import common_substrings

match = common_substrings(stringx, stringy, limit=limit)
match.sort()
match.sort(key=_itemgetter(2), reverse=True)
return match
matches = common_substrings(stringx, stringy, limit=limit)
matches.sort()
matches.sort(key=_itemgetter(2), reverse=True)
return matches


def terminal_overlap(stringx: str, stringy: str, limit=15):
def terminal_overlap(stringx: str, stringy: str, limit=15) -> _List[Match]:
"""Finds the the flanking common substrings between stringx and stringy
longer than limit. This means that the results only contains substrings
that starts or ends at the the ends of stringx and stringy.
Expand Down
Loading

0 comments on commit 787d00c

Please sign in to comment.