Giter Club home page Giter Club logo

suffixtrees.jl's Introduction

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)
end

The 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
end

The 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 tree

function addsuffixlink(st, nodenum::Int)

Add a link to tree

activeedge(st)

Return active edge of tree

function 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

suffixtrees.jl's People

Contributors

wherrera10 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

suffixtrees.jl's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.