<commit_before>-- lua-npge, Nucleotide PanGenome explorer (Lua module)
-- Copyright (C) 2014-2015 <NAME>
-- See the LICENSE file for terms of use.

describe("npge.alignment.goodSlices", function()
    it("finds good slices", function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices({100, 0, 100, 100, 100,
            0, 0, 0, 0, 100, 100, 100},
            3, 1, 0.6, 3), {
                {0, 4},
                {9, 11},
            })
        assert.same(goodSlices({100, 0, 100, 100, 100,
            0, 0, 0, 0, 100, 100, 100, 100},
            3, 2, 0.6, 3), {
                {9, 12},
                {2, 4},
            })
        assert.same(goodSlices({100, 0, 100, 100, 100,
            0, 0, 0, 0, 100, 100, 100, 100},
            3, 3, 0.6, 3), {
                {0, 4},
                {9, 12},
            })
    end)

    local function bools(row)
        row = row:gsub('%s', '')
        local array = {}
        for i = 1, #row do
            local score = (row:sub(i, i) ~= '-') and 100 or 0
            table.insert(array, score)
        end
        return array
    end

    it("finds good slices (rows)", function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+-+++----++++"),
            3, 1, 0.6, 3), {
                {0, 4},
                {9, 12},
            })
        assert.same(goodSlices(bools("+-+++----++++"),
            3, 2, 0.6, 3), {
                {9, 12},
                {2, 4},
            })
    end)

    it("finds good slices (local is good, #global is bad)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("++-+++++++++-+"),
            10, 1, 0.9, 10), {
                {0, 13}
            })
    end)

    it("finds good slices (min_length=length)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            3, 1, 0.9, 3), {
                {0, 2}
            })
    end)

    it("finds good slices (min_length=length=min_end)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            3, 3, 0.9, 3), {
                {0, 2}
            })
    end)

    it("finds good slices (min_end = 0)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            2, 0, 0.9, 2), {
                {0, 2}
            })
    end)

    it("finds good slices (min_end > min_length)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            2, 3, 0.9, 2), {
            })
    end)

    it("finds good slices (min_identity > 100%)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            2, 1, 1.46, 2), {
            })
    end)

    it("finds good slices (min_identity = 100%)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            2, 1, 1.0, 2), {
                {0, 2}
            })
    end)

    it("finds good slices (min_identity = 0%)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+-+"),
            2, 1, 0.0, 2), {
                {0, 2}
            })
    end)

    it("finds good slices (empty input)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools(""),
            2, 1, 0.9, 2), {})
    end)

    it("finds good slices (short input)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+"),
            2, 1, 0.9, 2), {})
    end)

    it("finds good slices (long rows)", function()
        local goodSlices = require 'npge.alignment.goodSlices'
        local row = [[
++++++++++++++++++++-+++++++++++++++++++++++++++-++-++++--+-
+++++++++++-++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++-+-+++++++++-++--+++++-++++++-+--+++++++
+++++-++++++++-++++++++++++++-++++++++-++++++++++++++++-++++
+++++++-+++++++++++++++++-+++-+++++++++++-++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++-+++++-++++++++++++
+++++++++++++-++++++-++++++--+++++--++++++++++++++++++++--++
+++++++++-+++++++++++++++++++++-+++++++++++++-+++++++++++--+
++++--++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++-+++++++-++++++++-+++++++--++++++++++++++++++++++++++++
++++++++++++++++++++++-+++-+-+++++++++++++++++++++++++++++++
+++-+++++++-++++++++-+++++-++++++++-+++++++++++-+++++-++-+++
+++++++++++++-++++++++++++++++-+++++++++-+++++++++---++++++-
+++--+++-++++++-++++-++++++-+++++-++++++++++-+++++++++++++-+
++++++-+++-+++++--+++++++++++++++++-+++++++++++++-++++++++++
+++++++++++++++++++++++++-+++++-+++++++++++++++++++-++++++++
++++++++++++-++++++-++++++++++++++++++++]]
        assert.same(goodSlices(bools(row), 100, 3, 0.9, 100), {
            {396, 712},
            {157, 393},
            {801, 999},
            {0, 151},
        })
    end)

    it("finds good slices (MIN_LENGTH<FRAME_LENGTH, end gaps)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        local row = [[
+---+++---+----------+---+---+-------+++++++-+-+++++++++++
        ]]
        row = bools(row)
        row[2] = 99 -- gap
        row[3] = 99 -- gap
        row[4] = 99 -- gap
        -- error: find all, then cut begin, so identity < 50%
        assert.same(goodSlices(row, 99, 3, 0.5, 50), {})
    end)

    it("finds good slices (bad end)", function()
        local goodSlices = require 'npge.alignment.goodSlices'
        local scores = {}
        for i = 1, 100 do
            scores[i] = 99 -- gaps
        end
        scores[1] = 100
        scores[100] = 100
        -- control
        assert.same(
            goodSlices(scores, 100, 1, 0.6, 100),
            {{0, 99}})
        assert.same(
            goodSlices(scores, 100, 10, 0.6, 100),
            {})
    end)

    it("finds good slices (bad end, min_length=min_end)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(
            {100, 100, 99, 99, 99, 99, 99, 99, 100, 100},
            10, 10, 0.6, 10), {})
    end)
end)<commit_msg>test for goodSlices with bad frame_length<commit_after>-- lua-npge, Nucleotide PanGenome explorer (Lua module)
-- Copyright (C) 2014-2015 <NAME>
-- See the LICENSE file for terms of use.

describe("npge.alignment.goodSlices", function()
    it("finds good slices", function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices({100, 0, 100, 100, 100,
            0, 0, 0, 0, 100, 100, 100},
            3, 1, 0.6, 3), {
                {0, 4},
                {9, 11},
            })
        assert.same(goodSlices({100, 0, 100, 100, 100,
            0, 0, 0, 0, 100, 100, 100, 100},
            3, 2, 0.6, 3), {
                {9, 12},
                {2, 4},
            })
        assert.same(goodSlices({100, 0, 100, 100, 100,
            0, 0, 0, 0, 100, 100, 100, 100},
            3, 3, 0.6, 3), {
                {0, 4},
                {9, 12},
            })
    end)

    local function bools(row)
        row = row:gsub('%s', '')
        local array = {}
        for i = 1, #row do
            local score = (row:sub(i, i) ~= '-') and 100 or 0
            table.insert(array, score)
        end
        return array
    end

    it("finds good slices (rows)", function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+-+++----++++"),
            3, 1, 0.6, 3), {
                {0, 4},
                {9, 12},
            })
        assert.same(goodSlices(bools("+-+++----++++"),
            3, 2, 0.6, 3), {
                {9, 12},
                {2, 4},
            })
    end)

    it("finds good slices (local is good, #global is bad)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("++-+++++++++-+"),
            10, 1, 0.9, 10), {
                {0, 13}
            })
    end)

    it("finds good slices (min_length=length)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            3, 1, 0.9, 3), {
                {0, 2}
            })
    end)

    it("finds good slices (min_length=length=min_end)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            3, 3, 0.9, 3), {
                {0, 2}
            })
    end)

    it("finds good slices (min_end = 0)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            2, 0, 0.9, 2), {
                {0, 2}
            })
    end)

    it("finds good slices (min_end > min_length)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            2, 3, 0.9, 2), {
            })
    end)

    it("finds good slices (min_identity > 100%)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            2, 1, 1.46, 2), {
            })
    end)

    it("finds good slices (min_identity = 100%)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+++"),
            2, 1, 1.0, 2), {
                {0, 2}
            })
    end)

    it("finds good slices (min_identity = 0%)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+-+"),
            2, 1, 0.0, 2), {
                {0, 2}
            })
    end)

    it("finds good slices (empty input)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools(""),
            2, 1, 0.9, 2), {})
    end)

    it("finds good slices (short input)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(bools("+"),
            2, 1, 0.9, 2), {})
    end)

    it("finds good slices (long rows)", function()
        local goodSlices = require 'npge.alignment.goodSlices'
        local row = [[
++++++++++++++++++++-+++++++++++++++++++++++++++-++-++++--+-
+++++++++++-++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++-+-+++++++++-++--+++++-++++++-+--+++++++
+++++-++++++++-++++++++++++++-++++++++-++++++++++++++++-++++
+++++++-+++++++++++++++++-+++-+++++++++++-++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++-+++++-++++++++++++
+++++++++++++-++++++-++++++--+++++--++++++++++++++++++++--++
+++++++++-+++++++++++++++++++++-+++++++++++++-+++++++++++--+
++++--++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++-+++++++-++++++++-+++++++--++++++++++++++++++++++++++++
++++++++++++++++++++++-+++-+-+++++++++++++++++++++++++++++++
+++-+++++++-++++++++-+++++-++++++++-+++++++++++-+++++-++-+++
+++++++++++++-++++++++++++++++-+++++++++-+++++++++---++++++-
+++--+++-++++++-++++-++++++-+++++-++++++++++-+++++++++++++-+
++++++-+++-+++++--+++++++++++++++++-+++++++++++++-++++++++++
+++++++++++++++++++++++++-+++++-+++++++++++++++++++-++++++++
++++++++++++-++++++-++++++++++++++++++++]]
        assert.same(goodSlices(bools(row), 100, 3, 0.9, 100), {
            {396, 712},
            {157, 393},
            {801, 999},
            {0, 151},
        })
    end)

    it("finds good slices (MIN_LENGTH<FRAME_LENGTH, end gaps)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        local row = [[
+---+++---+----------+---+---+-------+++++++-+-+++++++++++
        ]]
        row = bools(row)
        row[2] = 99 -- gap
        row[3] = 99 -- gap
        row[4] = 99 -- gap
        -- error: find all, then cut begin, so identity < 50%
        assert.same(goodSlices(row, 99, 3, 0.5, 50), {})
    end)

    it("finds good slices (bad end)", function()
        local goodSlices = require 'npge.alignment.goodSlices'
        local scores = {}
        for i = 1, 100 do
            scores[i] = 99 -- gaps
        end
        scores[1] = 100
        scores[100] = 100
        -- control
        assert.same(
            goodSlices(scores, 100, 1, 0.6, 100),
            {{0, 99}})
        assert.same(
            goodSlices(scores, 100, 10, 0.6, 100),
            {})
    end)

    it("finds good slices (bad end, min_length=min_end)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices(
            {100, 100, 99, 99, 99, 99, 99, 99, 100, 100},
            10, 10, 0.6, 10), {})
    end)

    it("finds good slices (bad frame_length negative)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices({100, 0, 100, 100, 100,
            0, 0, 0, 0, 100, 100, 100},
            -1, 1, 0.6, 3), {})
    end)

    it("finds good slices (bad frame_length > block_length)",
    function()
        local goodSlices = require 'npge.alignment.goodSlices'
        assert.same(goodSlices({100, 0, 100, 100, 100,
            0, 0, 0, 0, 100, 100, 100},
            100, 1, 0.6, 3), {})
    end)
end)
{'fraction_non_alphanumeric': 0.2878821362799263, 'fraction_numerical': 0.05480662983425414, 'mean_word_length': 1.9423493714781102, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2628903', 'n_tokens_mistral': 5279, 'n_tokens_neox': 4379, 'n_words': 968}