import unittest

from Src.BioAnalyzer.GenePrioritization.Steps.DifferentialAnalysis.Measurers.GlobaBetaValueMeasurer import \
    GlobalBetaValueMeasurer
from Src.BioDataManagement.CrossCutting.DTOs.DnaMethylationLevelStatusDto import DnaMethylationLevelStatusDto


class GlobalBetaValueMeasurerTest(unittest.TestCase):
    def test_calculate(self):
        measurer = GlobalBetaValueMeasurer()
        case_levels = [0.1813, 0.7961, 0.2214, 0.3894, 0.6967, 0.0668, 0.0713, 0.7414, 0.9488, 0.6871, 0.0496,
                          0.8851, 0.4431, 0.3422, 0.0697, 0.3021, 0.8536, 0.6261, 0.7965, 0.3122, 0.7092, 0.4338,
                          0.2711, 0.8316, 0.0879, 0.2212, 0.0391]

        control_levels = [0.1813, 0.1, 0.2214, 0.3, 0.6967, 0.8, 0.0713, 0.7414, 0.9488, 0.6871, 0.06,
                       0.1, 0.1, 0.32, 0.0697, 0.3021, 0.8536, 0.6261, 0.7965, 0.3122, 0.7092, 0.38,
                       0.1, 0.86, 0.0879, 0.22, 0.01]

        resp = measurer.calculate(1, case_levels, control_levels)
        self.assertEqual(resp.element_id, 1)
        self.assertFalse(resp.is_highly_significant)
        self.assertEqual(resp.status, DnaMethylationLevelStatusDto.Hypomethylation)
        self.assertEqual(resp.value, 0.05255925925925925)
        self.assertEqual(resp.ratio, 0.53631758198391777)

        control_levels = [0.1813, 0.7961, 0.2214, 0.3894, 0.6967, 0.0668, 0.0713, 0.7414, 0.9488, 0.6871, 0.0496,
                       0.8851, 0.4431, 0.3422, 0.0697, 0.3021, 0.8536, 0.6261, 0.7965, 0.3122, 0.7092, 0.4338,
                       0.2711, 0.8316, 0.0879, 0.2212, 0.0391]

        case_levels = [0.13, 0.1, 0.24, 0.3, 0.69, 0.8, 0.0713, 0.741, 0.988, 0.671, 0.06,
                          0.1, 0.1, 0.32, 0.06, 0.31, 0.85, 0.62, 0.7965, 0.322, 0.70, 0.38,
                          0.1, 0.8, 0.09, 0.22, 0.01]

        resp = measurer.calculate(1, case_levels, control_levels)
        self.assertEqual(resp.element_id, 1)
        self.assertFalse(resp.is_highly_significant)
        self.assertEqual(resp.status, DnaMethylationLevelStatusDto.Hypomethylation)
        self.assertEqual(resp.value, -0.0557259259259259)
        self.assertEqual(resp.ratio, 0.51163671802224087)

        control_levels = [0.1813, 0.7961, 0.2214, 0.3894, 0.6967, 0.0668, 0.0713, 0.7414, 0.9488, 0.6871, 0.0496,
                       0.8851, 0.4431, 0.3422, 0.0697, 0.3021, 0.8536, 0.6261, 0.7965, 0.3122, 0.7092, 0.4338,
                       0.2711, 0.8316, 0.0879, 0.2212, 0.0391]

        case_levels = [0.1813, 0.7961, 0.2214, 0.3894, 0.6967, 0.0668, 0.0713, 0.7414, 0.9488, 0.6871, 0.0496,
                       0.8851, 0.4431, 0.3422, 0.0697, 0.3021, 0.8536, 0.6261, 0.7965, 0.3122, 0.7092, 0.4338,
                       0.2711, 0.8316, 0.0879, 0.2212, 0.0391]

        resp = measurer.calculate(1, case_levels, control_levels)
        self.assertEqual(resp.element_id, 1)
        self.assertFalse(resp.is_highly_significant)
        self.assertEqual(resp.status, DnaMethylationLevelStatusDto.Hypomethylation)
        self.assertEqual(resp.value, 0)
        self.assertEqual(resp.ratio, 1)

        control_levels = [0.1813, 0.7961, 0.2214, 0.3894, 0.6967, 0.0668, 0.0713, 0.7414, 0.9488, 0.6871, 0.0496,
                          0.8851, 0.4431, 0.3422, 0.0697, 0.3021, 0.8536, 0.6261, 0.7965, 0.3122, 0.7092, 0.4338,
                          0.2711, 0.8316, 0.0879, 0.2212, 0.0391]

        case_levels = [0.63, 0.1, 0.54, 0.4, 0.89, 0.8, 0.6713, 0.841, 0.988, 0.871, 0.36,
                       0.9, 0.1, 0.62, 0.66, 0.81, 0.95, 0.82, 0.8965, 0.622, 0.90, 0.68,
                       0.8, 0.8, 0.79, 0.62, 0.51]

        resp = measurer.calculate(1, case_levels, control_levels)
        self.assertEqual(resp.element_id, 1)
        self.assertTrue(resp.is_highly_significant)
        self.assertEqual(resp.status, DnaMethylationLevelStatusDto.Hypermethylated)
        self.assertEqual(resp.value, 0.24057037037037038)
        self.assertEqual(resp.ratio, 0.0020875781181989004)


if __name__ == '__main__':
    unittest.main()
