Exemplo n.º 1
0
    def test_compute_structured_pathway_abundance_or_coverage_test_coverage_missing_optional_reaction(
            self):
        """
        Test the compute_structured_pathway_abundance_or_coverage function for a simple structure with coverage
        Test the PathwaysDatabase add and get pathway structure along with key reactions
        Test with an optional reaction missing
        """

        # Create the database structure
        pathways_database_store = store.PathwaysDatabase()
        structure_string = " A -B C "
        pathways_database_store.add_pathway_structure("pathway1",
                                                      structure_string)

        reaction_scores = {"A": 1, "B": 0, "C": 3}
        structure = pathways_database_store.get_structure_for_pathway(
            "pathway1")
        key_reactions = pathways_database_store.get_key_reactions_for_pathway(
            "pathway1")
        median = 1

        # Compute the coverage
        coverage = modules.compute_structured_pathway_abundance_or_coverage(
            structure, key_reactions, reaction_scores, True, median)

        # Compute the expected coverage which is the harmonic mean of the chi2cdf for the required reactions
        del reaction_scores["B"]
        expected_coverage = modules.harmonic_mean(
            [chi2cdf.chi2cdf(v, median) for v in reaction_scores.values()])

        self.assertEqual(coverage, expected_coverage)
Exemplo n.º 2
0
    def test_harmonic_mean_one_zero(self):
        """
        Test the harmonmic mean function with a set of values with on zero
        """

        result = modules.harmonic_mean([1, 2, 3, 0, 4])
        expect_result = 0

        self.assertEqual(result, expect_result)
Exemplo n.º 3
0
    def test_harmonic_mean_empty_list(self):
        """
        Test the harmonmic mean function with an empty list
        """

        result = modules.harmonic_mean([])
        expect_result = 0

        self.assertEqual(result, expect_result)
Exemplo n.º 4
0
    def test_harmonic_mean(self):
        """
        Test the harmonmic mean function
        """

        values = [1, 2, 3, 4]
        result = modules.harmonic_mean(values)
        expect_result = len(values) / sum(1.0 / v for v in values)

        self.assertEqual(result, expect_result)