Ejemplo n.º 1
0
    def test_divide_table(self):
        obs = prep_table({
            'S1': {
                'G1': 20,
                'G2': 36,
                'G3': 4
            },
            'S2': {
                'G1': 15,
                'G2': 24,
                'G3': 8
            },
            'S3': {
                'G1': 10,
                'G2': 18,
                'G3': 0
            }
        })
        ob2 = Table(*map(np.array, obs))
        sizes = {'G1': 5, 'G2': 6, 'G3': 2}
        exp = prep_table({
            'S1': {
                'G1': 4,
                'G2': 6,
                'G3': 2
            },
            'S2': {
                'G1': 3,
                'G2': 4,
                'G3': 4
            },
            'S3': {
                'G1': 2,
                'G2': 3,
                'G3': 0
            }
        })
        ex2 = Table(*map(np.array, obs))

        # regular
        divide_table(obs, sizes)
        for i in range(4):
            self.assertListEqual(obs[i], exp[i])

        # BIOM
        divide_table(ob2, sizes)
        ex2 = Table(*map(np.array, exp))
        self.assertEqual(ob2.descriptive_equality(ex2), 'Tables appear equal')

        # missing size
        del (sizes['G3'])
        with self.assertRaises(KeyError):
            divide_table(obs, sizes)
Ejemplo n.º 2
0
    def test_round_table(self):
        obs = prep_table({
            'S1': {
                'G1': 0.5,
                'G2': 0.0,
                'G3': 2.3,
                'G4': 0.50000000001
            },
            'S2': {
                'G1': 1.5,
                'G2': 0.2,
                'G3': 1.49999999999,
                'G4': 0.2
            },
            'S3': {
                'G1': 2.5,
                'G2': 0.3,
                'G3': 3.8,
                'G4': 0.1
            }
        })
        exp = prep_table({
            'S1': {
                'G1': 0,
                'G3': 2
            },
            'S2': {
                'G1': 2,
                'G3': 2
            },
            'S3': {
                'G1': 2,
                'G3': 4
            }
        })
        ob2 = Table(*map(np.array, obs))

        # regular
        round_table(obs)
        for i in range(4):
            self.assertListEqual(obs[i], exp[i])

        # BIOM
        round_table(ob2)
        ex2 = Table(*map(np.array, exp))
        self.assertEqual(ob2.descriptive_equality(ex2), 'Tables appear equal')
Ejemplo n.º 3
0
 def test_round_biom(self):
     obs = Table(*map(
         np.array,
         prep_table({
             'S1': {
                 'G1': 0.5,
                 'G2': 0.0,
                 'G3': 2.3,
                 'G4': 0.50000000001
             },
             'S2': {
                 'G1': 1.5,
                 'G2': 0.2,
                 'G3': 1.49999999999,
                 'G4': 0.2
             },
             'S3': {
                 'G1': 2.5,
                 'G2': 0.3,
                 'G3': 3.8,
                 'G4': 0.1
             }
         })))
     round_biom(obs)
     exp = Table(*map(
         np.array,
         prep_table({
             'S1': {
                 'G1': 0,
                 'G3': 2
             },
             'S2': {
                 'G1': 2,
                 'G3': 2
             },
             'S3': {
                 'G1': 2,
                 'G3': 4
             }
         })))
     self.assertEqual(obs.descriptive_equality(exp), 'Tables appear equal')
Ejemplo n.º 4
0
    def test_scale_table(self):
        obs = prep_table({
            'S1': {
                'G1': 4,
                'G2': 7,
                'G3': 0
            },
            'S2': {
                'G1': 2,
                'G2': 3,
                'G3': 1
            }
        })
        ob2 = Table(*map(np.array, obs))
        exp = prep_table({
            'S1': {
                'G1': 12,
                'G2': 21,
                'G3': 0
            },
            'S2': {
                'G1': 6,
                'G2': 9,
                'G3': 3
            }
        })
        ex2 = Table(*map(np.array, exp))

        # regular
        scale_table(obs, 3)
        for i in range(4):
            self.assertListEqual(obs[i], exp[i])

        # BIOM
        scale_table(ob2, 3)
        self.assertEqual(ob2.descriptive_equality(ex2), 'Tables appear equal')