<commit_before>"""
Using gap score to determine optimal cluster number
"""

import unittest
from unittest import TestCase
from flaky import flaky

import numpy as np
import scipy

from uncurl import gap_score

class GapScoreTest(TestCase):

    def setUp(self):
        pass

    def test_gap_score(self):
        data_mat = scipy.io.loadmat('data/10x_pooled_400.mat')
        data = data_mat['data']
        data_tsvd = gap_score.preproc_data(data)
        max_k, gap_vals, sk_vals = gap_score.run_gap_k_selection(data_tsvd,
                k_min=1, k_max=50, skip=5, B=5)
        # just test that the score is in a very broad range
        self.assertTrue(max_k > 3)
        self.assertTrue(max_k < 20)

    def test_gap_score_2(self):
        data_mat = scipy.io.loadmat('data/GSE60361_dat.mat')
        data = data_mat['Dat']
        data_tsvd = gap_score.preproc_data(data)
        max_k, gap_vals, sk_vals = gap_score.run_gap_k_selection(data_tsvd,
                k_min=1, k_max=50, skip=5, B=5)
        self.assertTrue(max_k > 3)
        self.assertTrue(max_k < 30)

    @flaky(max_runs=3)
    def test_gap_score_3(self):
        data_mat = scipy.io.loadmat('data/SCDE_test.mat')
        data = data_mat['dat']
        data_tsvd = gap_score.preproc_data(data)
        max_k, gap_vals, sk_vals = gap_score.run_gap_k_selection(data_tsvd,
                k_min=1, k_max=50, skip=5, B=5)
        self.assertTrue(max_k < 10)

<commit_msg>test gap score<commit_after>"""
Using gap score to determine optimal cluster number
"""

import unittest
from unittest import TestCase
from flaky import flaky

import numpy as np
import scipy

from uncurl import gap_score

class GapScoreTest(TestCase):

    def setUp(self):
        pass

    def test_gap_score(self):
        data_mat = scipy.io.loadmat('data/10x_pooled_400.mat')
        data = data_mat['data']
        data_tsvd = gap_score.preproc_data(data)
        max_k, gap_vals, sk_vals = gap_score.run_gap_k_selection(data_tsvd,
                k_min=1, k_max=50, skip=5, B=5)
        # just test that the score is in a very broad range
        self.assertTrue(max_k > 3)
        self.assertTrue(max_k < 20)

    def test_gap_score_2(self):
        data_mat = scipy.io.loadmat('data/GSE60361_dat.mat')
        data = data_mat['Dat']
        data_tsvd = gap_score.preproc_data(data)
        max_k, gap_vals, sk_vals = gap_score.run_gap_k_selection(data_tsvd,
                k_min=1, k_max=50, skip=5, B=5)
        self.assertTrue(max_k > 3)
        self.assertTrue(max_k < 30)

    @flaky(max_runs=3)
    def test_gap_score_3(self):
        data_mat = scipy.io.loadmat('data/SCDE_test.mat')
        data = data_mat['dat']
        data_tsvd = gap_score.preproc_data(data, gene_subset=True)
        max_k, gap_vals, sk_vals = gap_score.run_gap_k_selection(data_tsvd,
                k_min=1, k_max=50, skip=5, B=5)
        self.assertTrue(max_k < 10)


{'fraction_non_alphanumeric': 0.10065494657014823, 'fraction_numerical': 0.02481902792140641, 'mean_word_length': 2.848806366047745, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7186055', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1067, 'n_words': 211}