def test_raw_abundance(self): """ Testing raw_abundance() function of biom_calc.py. :return: Returns OK, if testing goal is achieved, otherwise raises error. """ self.result = bc.raw_abundance(self.biom, sample_abd=False) self.result1 = bc.raw_abundance(self.biom) # Lists containing hand and function calculated values. hand_calc = [7, 3, 4, 6, 3, 4] hand_calc1 = [1, 12, 7, 5, 2] hand_calc2 = ['Sample1', 'Sample2', 'Sample3', 'Sample4', 'Sample5', 'Sample6'] hand_calc3 = ['GG_OTU_1', 'GG_OTU_2', 'GG_OTU_3', 'GG_OTU_4', 'GG_OTU_5'] # Testing validity of raw_abundance() function. self.assertItemsEqual(hand_calc1, self.result.values(), msg='Raw abundances not calculated accurately.') self.assertItemsEqual(hand_calc, self.result1.values(), msg='Raw abundances not calculated accurately.') self.assertItemsEqual(self.result.keys(), hand_calc3, msg='Abundances not calculated for SampleID\'s') self.assertItemsEqual(self.result1.keys(), hand_calc2, msg='Abundances not calculated for OTUID\'s')
def test_raw_abundance(self): """ Testing raw_abundance() function of biom_calc.py. :return: Returns OK, if testing goal is achieved, otherwise raises error. """ self.result = bc.raw_abundance(self.biomf, sample_abd=False) self.result1 = bc.raw_abundance(self.biomf) self.result2 = bc.raw_abundance(self.biomf, sampleIDs=["Sample2", "Sample5"]) self.result3 = bc.raw_abundance(self.biomf, sampleIDs=["Sample1", "Sample4"], sample_abd=False) # Lists containing hand and function calculated values. hand_calc = [15, 51, 87, 123, 159] hand_calc1 = [60, 65, 70, 75, 80, 85] hand_calc2 = ["Sample1", "Sample2", "Sample3", "Sample4", "Sample5", "Sample6"] hand_calc3 = ["GG_OTU_1", "GG_OTU_2", "GG_OTU_3", "GG_OTU_4", "GG_OTU_5"] hand_calc4 = [65, 80] hand_calc5 = ["Sample2", "Sample5"] hand_calc6 = [3, 15, 27, 39, 51] hand_calc7 = ["GG_OTU_1", "GG_OTU_2", "GG_OTU_3", "GG_OTU_4", "GG_OTU_5"] # Testing validity of raw_abundance() function. self.assertItemsEqual(hand_calc1, sorted(self.result1.values()), msg="Raw abundances not calculated accurately.") self.assertItemsEqual(hand_calc, self.result.values(), msg="Raw abundances not calculated accurately.") self.assertItemsEqual(self.result.keys(), hand_calc3, msg="Abundances not calculated for SampleID's") self.assertItemsEqual(sorted(self.result1.keys()), hand_calc2, msg="Abundances not calculated for OTUID's") self.assertItemsEqual(sorted(self.result2.keys()), hand_calc5, msg="Abundances not calculated for SampleID's") self.assertItemsEqual(self.result3.keys(), hand_calc7, msg="Abundances not calculated for OTUID's") self.assertItemsEqual(sorted(self.result2.values()), hand_calc4, msg="Abundances not calculated for SampleID's") self.assertItemsEqual(self.result3.values(), hand_calc6, msg="Abundances not calculated for OTUID's")
def test_transform_raw_abundance(self): """ Testing transform_raw_abundance() function of biom_calc.py. :return: Returns OK if testing goal is achieved, otherwise raises error. """ self.result = bc.transform_raw_abundance( self.biom, sample_abd=False ) self.result1 = bc.raw_abundance(self.biom, sample_abd=False) # Obtaining manual calculations for comparison testing hand_calc = [] for num in self.result1.values(): hand_calc.append(math.log10(float(num))) # Testing the validity of transform function self.assertAlmostEqual( self.result.values(), hand_calc, places=10, msg='Function did not calculate the transformation accurately.' )
def test_transform_raw_abundance(self): """ Testing transform_raw_abundance() function of biom_calc.py. :return: Returns OK if testing goal is achieved, otherwise raises error. """ self.result = bc.transform_raw_abundance( self.biomf, sample_abd=False ) self.result1 = bc.raw_abundance(self.biomf, sample_abd=False) # Obtaining manual calculations for comparison testing hand_calc = [1.17609125906, 1.7075701761, 1.93951925262, 2.08990511144, 2.20139712432] # Testing the validity of transform function for hand, func in zip(hand_calc, self.result.values()): self.assertAlmostEqual( hand, func, msg="Function did not calculate the transformation accurately." )
def test_raw_abundance(self): """ Testing raw_abundance() function of biom_calc.py. :return: Returns OK, if testing goal is achieved, otherwise raises error. """ self.result = bc.raw_abundance(self.biomf, sample_abd=False) self.result1 = bc.raw_abundance(self.biomf) self.result2 = bc.raw_abundance(self.biomf, sampleIDs=["S2", "S5"]) self.result3 = bc.raw_abundance(self.biomf, sampleIDs=["S1", "S4"], sample_abd=False) # Lists containing hand and function calculated values. hand_calc = {"GG_OTU_1": 35., "GG_OTU_2": 38., "GG_OTU_3": 54., "GG_OTU_4": 54., "GG_OTU_5": 42.} hand_calc1 = {"S9": 9.0, "S8": 26.0, "S3": 18.0, "S2": 31.0, "S1": 26.0, "S10": 24.0, "S7": 28.0, "S6": 27.0, "S5": 23.0, "S4": 11.0} hand_calc2 = {"S2": 31.0, "S5": 23.0} hand_calc3 = {"GG_OTU_1": 7., "GG_OTU_2": 2., "GG_OTU_3": 11., "GG_OTU_4": 12., "GG_OTU_5": 5.} # Testing validity of raw_abundance() function. self.assertDictEqual(hand_calc, self.result, msg="Raw abundances not calculated accurately.") self.assertDictEqual(hand_calc1, self.result1, msg="Raw abundances not calculated accurately.") self.assertDictEqual(self.result2, hand_calc2, msg="Abundances not calculated for SampleID's") self.assertDictEqual(self.result3, hand_calc3, msg="Abundances not calculated for OTUID's") # Test for passed sampleID validity with self.assertRaisesRegexp(ValueError, "\nError while calculating raw total " "abundances: The sampleIDs provided do not match " "the sampleIDs in biom file. Please double check " "the sampleIDs provided.\n"): bc.raw_abundance(self.biomf, sampleIDs=["NS01", "NS02", "NS03"])