Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wherrera10/suffixtrees.jl
Julia implementation of the Ukkonen suffix tree algorithm
https://github.com/wherrera10/suffixtrees.jl
julia-package suffix-tree
Last synced: about 1 month ago
JSON representation
Julia implementation of the Ukkonen suffix tree algorithm
- Host: GitHub
- URL: https://github.com/wherrera10/suffixtrees.jl
- Owner: wherrera10
- License: bsd-2-clause
- Created: 2020-09-27T08:10:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-20T19:59:21.000Z (almost 2 years ago)
- Last Synced: 2024-11-11T08:46:36.570Z (about 2 months ago)
- Topics: julia-package, suffix-tree
- Language: Julia
- Homepage:
- Size: 114 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SuffixTrees.jl
Julia implementation of the Ukkonen suffix tree algorithm
## Functions
mutable struct Node
children::Dict{Char,Int}
start::Int
ending::Int
suffixlink::Int
suffixindex::Int
Node(strt = 0, endng = oo) = new(Dict{Char,Int}(), strt, endng, 0, -1)
endThe suffix-tree's node and default constructor.
Note that these are referenced not by pointer but by an index into an array of nodes.
mutable struct SuffixTree
nodes::Vector{Node}
text::Vector{Char}
root::Int
position::Int
currentnode::Int
needsuffixlink::Int
remainder::Int
activenode::Int
activelength::Int
activeedge::Int
endThe SuffixTree struct.
function SuffixTree(str::String, addterminator = true, terminatorchar = Char(65129))
SuffixTree constructor from string. Note that the string should have a terminator character at its end, usually '$' or '#'.
If addterminator is true (default) and the last character is not a unique terminator, will add one from a Unicode page (default is '﹩').edgelength(st, n::Node)
Return length of edge of a node (the portion of the sequence it covers) """function newnode(st, start, ending)
Make a node for the treefunction addsuffixlink(st, nodenum::Int)
Add a link to treeactiveedge(st)
Return active edge of treefunction walkdown!(st, currnode::Int)
Walk down the tree to its active length
function extendsuffixtree(st, pos)Extend tree at pos
function setsuffixindexbyDFS(st, node, labelheight, verbose=false)
Set the index of the leaves of the tree within the sequence
function dotraversal(st)
Traverse the suffix tree
function getlongestrepeatedsubstring(st::SuffixTree, label="", printresult=true)
Find the longest repeated suffix of the tree
## Example
using SuffixTrees
examples = [
("CAAAABAAAABD\$", "AAAAB"),
("GEEKSFORGEEKS\$", "GEEKS"),
("AAAAAAAAAA\$", "AAAAAAAAA"),
("ABCDEFG\$", ""),
("ABABABA\$", "ABABA"),
("ATCGATCGA\$", "ATCGA"),
("banana\$", "ana"),
("abcpqrabpqpq\$", "ab (or) pq"),
("pqrpqpqabab\$", "ab (or) pq"),
("CAAAABDAAAABD\$", "AAAABD"),
("CAAAABDAAAABD", "AAAABD"), # this one gets an added terminator ﹩ by default
]
println("Test Longest Repeated Substring in:\n")
for (ex, ans) in examples
st = SuffixTree(ex)
println("Check: ", getlongestrepeatedsubstring(st), " == $ans")
end