def test_compute_pathways_coverage_structured(self): """ Test the compute_pathways_coverage function Test PathwaysDatabase add Test PathwaysAndReactions store Test Pathways store Test with structured pathways """ # Set xipe to off config.xipe_toggle = "off" # Create the database structure pathways_database_store = store.PathwaysDatabase() pathways_database_store.add_pathway_structure("pathway1", " A B C D ") pathways_database_store.add_pathway_structure("pathway2", " A B C D E F ") # Have all test data be from the same bug bug = "bug" pathways_and_reactions_store = store.PathwaysAndReactions() # Just a note that a value of 1 has a chi2cdf value of 0 # Also values ~10 or less have small chi2cdf values pathways_and_reactions_store.add(bug, "A", "pathway1", 11) pathways_and_reactions_store.add(bug, "B", "pathway1", 12) pathways_and_reactions_store.add(bug, "C", "pathway1", 13) pathways_and_reactions_store.add(bug, "D", "pathway1", 14) pathways_and_reactions_store.add(bug, "A", "pathway2", 19) pathways_and_reactions_store.add(bug, "B", "pathway2", 20) pathways_and_reactions_store.add(bug, "C", "pathway2", 30) pathways_and_reactions_store.add(bug, "D", "pathway2", 40) pathways_and_reactions_store.add(bug, "E", "pathway2", 50) pathways_and_reactions_store.add(bug, "F", "pathway2", 60) # Get the coverage result # The median is the median of all of the reactions of all of the pathways for this bug median_score_value = 19.5 # boost the pathway values pathway1_values_boosted = [12, 12, 13, 14] coverage_pathway1 = len(pathway1_values_boosted) / sum( 1.0 / chi2cdf.chi2cdf(v, median_score_value) for v in pathway1_values_boosted) pathway2_values_boosted = [20, 20, 30, 40, 50, 60] coverage_pathway2 = len(pathway2_values_boosted) / sum( 1.0 / chi2cdf.chi2cdf(v, median_score_value) for v in pathway2_values_boosted) # Find the actual result pathways_abundance_store_result = modules.compute_pathways_coverage( pathways_and_reactions_store, pathways_database_store) # Test the pathways abundance match those expected self.assertEqual( pathways_abundance_store_result.get_score_for_bug(bug, "pathway1"), coverage_pathway1) self.assertEqual( pathways_abundance_store_result.get_score_for_bug(bug, "pathway2"), coverage_pathway2)
def test_compute_pathways_coverage_unstructured(self): """ Test the compute_pathways_coaverage function Test PathwaysDatabase add Test PathwaysAndReactions store Test Pathways store Test with unstructured pathways """ # Set xipe to off config.xipe_toggle = "off" # Create the database structure pathways_database_store = store.PathwaysDatabase() pathways_database_store.add_pathway("pathway1", ["A", "B", "C", "D"]) pathways_database_store.add_pathway("pathway2", ["A", "B", "C", "D", "E", "F"]) # Have all test data be from the same bug bug = "bug" pathways_and_reactions_store = store.PathwaysAndReactions() pathways_and_reactions_store.add(bug, "A", "pathway1", 1) # Note B is not recored for pathway1 which will result in a zero value pathways_and_reactions_store.add(bug, "C", "pathway1", 3) pathways_and_reactions_store.add(bug, "D", "pathway1", 40) pathways_and_reactions_store.add(bug, "A", "pathway2", 10) pathways_and_reactions_store.add(bug, "B", "pathway2", 20) # Note C is not recored for pathway2 which will result in a zero value pathways_and_reactions_store.add(bug, "D", "pathway2", 40) pathways_and_reactions_store.add(bug, "E", "pathway2", 50) # Note F is not recored for pathway2 which will result in a zero value # The coverage for each pathway if the number of reactions greater than the median # divided by the total reactions in the pathway # The median for this set is 20 pathway1_values = [0, 1, 3, 40] count_greater_than_median = 1 pathway1_coverage = count_greater_than_median / float( len(pathway1_values)) pathway2_values = [0, 0, 10, 20, 40, 50] count_greater_than_median = 2 pathway2_coverage = count_greater_than_median / float( len(pathway2_values)) pathways_coverage_store_result = modules.compute_pathways_coverage( pathways_and_reactions_store, pathways_database_store) # Test the pathways abundance match those expected self.assertEqual( pathways_coverage_store_result.get_score_for_bug(bug, "pathway1"), pathway1_coverage) self.assertEqual( pathways_coverage_store_result.get_score_for_bug(bug, "pathway2"), pathway2_coverage)
def test_compute_pathways_abundance_unstructured(self): """ Test the compute_pathways_abundance function Test PathwaysDatabase add Test PathwaysAndReactions store Test Pathways store Test with unstructured pathways """ # Create the database structure pathways_database_store = store.PathwaysDatabase() pathways_database_store.add_pathway("pathway1", ["A", "B", "C", "D"]) pathways_database_store.add_pathway("pathway2", ["A", "B", "C", "D", "E", "F"]) # Have all test data be from the same bug bug = "bug" pathways_and_reactions_store = store.PathwaysAndReactions() pathways_and_reactions_store.add(bug, "A", "pathway1", 1) # Note B is not recored for pathway1 which will result in a zero value pathways_and_reactions_store.add(bug, "C", "pathway1", 3) pathways_and_reactions_store.add(bug, "D", "pathway1", 4) pathways_and_reactions_store.add(bug, "A", "pathway2", 10) pathways_and_reactions_store.add(bug, "B", "pathway2", 20) # Note C is not recored for pathway2 which will result in a zero value pathways_and_reactions_store.add(bug, "D", "pathway2", 40) pathways_and_reactions_store.add(bug, "E", "pathway2", 50) # Note F is not recored for pathway2 which will result in a zero value # The abundance for each pathway is the average of the largest half of the reaction values # For unstructured pathways, if the reaction is not included it does not result in a zero abundance pathway1_values = [0, 1, 3, 4] pathway1_abundance_set = pathway1_values[int(len(pathway1_values) / 2):] pathway1_abundance = sum(pathway1_abundance_set) / len( pathway1_abundance_set) pathway2_values = [0, 0, 10, 20, 40, 50] pathway2_abundance_set = pathway2_values[int(len(pathway2_values) / 2):] pathway2_abundance = sum(pathway2_abundance_set) / len( pathway2_abundance_set) pathways_abundance_store_result, reactions_in_pathways_present = modules.compute_pathways_abundance( pathways_and_reactions_store, pathways_database_store) # Test the pathways abundance match those expected self.assertEqual( pathways_abundance_store_result.get_score_for_bug(bug, "pathway1"), pathway1_abundance) self.assertEqual( pathways_abundance_store_result.get_score_for_bug(bug, "pathway2"), pathway2_abundance)
def test_compute_pathways_abundance_structured(self): """ Test the compute_pathways_abundance function Test PathwaysDatabase add Test PathwaysAndReactions store Test Pathways store Test with structured pathways """ # Create the database structure pathways_database_store = store.PathwaysDatabase() pathways_database_store.add_pathway_structure("pathway1", " A B C D ") pathways_database_store.add_pathway_structure("pathway2", " A B C D E F ") # Have all test data be from the same bug bug = "bug" pathways_and_reactions_store = store.PathwaysAndReactions() # Just a note that a value of 1 has a chi2cdf value of 0 # Also values ~10 or less have small chi2cdf values pathways_and_reactions_store.add(bug, "A", "pathway1", 11) pathways_and_reactions_store.add(bug, "B", "pathway1", 12) pathways_and_reactions_store.add(bug, "C", "pathway1", 13) pathways_and_reactions_store.add(bug, "D", "pathway1", 14) pathways_and_reactions_store.add(bug, "A", "pathway2", 19) pathways_and_reactions_store.add(bug, "B", "pathway2", 20) pathways_and_reactions_store.add(bug, "C", "pathway2", 30) pathways_and_reactions_store.add(bug, "D", "pathway2", 40) pathways_and_reactions_store.add(bug, "E", "pathway2", 50) pathways_and_reactions_store.add(bug, "F", "pathway2", 60) # The abundance for each pathway is the harmonic mean of the values # boost the lowest value in the pathway pathway1_values_boosted = [12, 12, 13, 14] pathway1_abundance = len(pathway1_values_boosted) / sum( 1.0 / v for v in pathway1_values_boosted) pathway2_values_boosted = [20, 20, 30, 40, 50, 60] pathway2_abundance = len(pathway2_values_boosted) / sum( 1.0 / v for v in pathway2_values_boosted) # Find the actual result pathways_abundance_store_result, reactions_in_pathways_present = modules.compute_pathways_abundance( pathways_and_reactions_store, pathways_database_store) # Test the pathways abundance match those expected self.assertEqual( pathways_abundance_store_result.get_score_for_bug(bug, "pathway1"), pathway1_abundance) self.assertEqual( pathways_abundance_store_result.get_score_for_bug(bug, "pathway2"), pathway2_abundance)
def test_compute_pathways_abundance_unstructured_reactions_list(self): """ Test the compute_pathways_abundance function Test PathwaysDatabase add Test PathwaysAndReactions store Test Pathways store Test with unstructured pathways Test the resulting list of reactions included in pathways """ # Create the database structure pathways_database_store = store.PathwaysDatabase() pathways_database_store.add_pathway("pathway1", ["A", "B", "C", "D"]) pathways_database_store.add_pathway("pathway2", ["A", "B", "C", "D", "E", "F"]) pathways_database_store.add_pathway("pathway3", ["A", "B", "G"]) # Have all test data be from two bugs bug = "bug1" pathways_and_reactions_store = store.PathwaysAndReactions() pathways_and_reactions_store.add(bug, "A", "pathway1", 1) pathways_and_reactions_store.add(bug, "B", "pathway1", 2) pathways_and_reactions_store.add(bug, "B", "pathway2", 2) pathways_and_reactions_store.add(bug, "C", "pathway2", 3) expected_reactions_in_pathways_present = {} expected_reactions_in_pathways_present[bug] = ["A", "B", "C"] bug = "bug2" pathways_and_reactions_store.add(bug, "A", "pathway1", 1) pathways_and_reactions_store.add(bug, "D", "pathway1", 3) pathways_and_reactions_store.add(bug, "B", "pathway1", 2) pathways_and_reactions_store.add(bug, "B", "pathway2", 2) expected_reactions_in_pathways_present[bug] = ["A", "B", "D"] pathways_abundance_store_result, reactions_in_pathways_present = modules.compute_pathways_abundance( pathways_and_reactions_store, pathways_database_store) # Test the reactions match those expected self.assertEqual( sorted(expected_reactions_in_pathways_present["bug1"]), sorted(list(reactions_in_pathways_present["bug1"]))) self.assertEqual( sorted(expected_reactions_in_pathways_present["bug2"]), sorted(list(reactions_in_pathways_present["bug2"])))
def test_compute_pathways_abundance_structured_reactions_list(self): """ Test the compute_pathways_abundance function Test PathwaysDatabase add Test PathwaysAndReactions store Test Pathways store Test with structured pathways Test gap fill Test the resulting list of reactions included in pathways """ # Create the database structure pathways_database_store = store.PathwaysDatabase() pathways_database_store.add_pathway_structure("pathway1", " A B C D ") pathways_database_store.add_pathway_structure("pathway2", " A B C D E F ") pathways_database_store.add_pathway_structure("pathway3", " A B G") # Have all test data be from three bugs bug = "bug1" pathways_and_reactions_store = store.PathwaysAndReactions() pathways_and_reactions_store.add(bug, "A", "pathway1", 1) pathways_and_reactions_store.add(bug, "B", "pathway1", 2) pathways_and_reactions_store.add(bug, "C", "pathway1", 3) expected_reactions_in_pathways_present = {} # This pathway is present because D is filled in # Though D does not have abundance so it is not included in the list expected_reactions_in_pathways_present[bug] = ["A", "B", "C"] bug = "bug2" pathways_and_reactions_store.add(bug, "A", "pathway1", 1) pathways_and_reactions_store.add(bug, "B", "pathway1", 3) pathways_and_reactions_store.add(bug, "D", "pathway2", 2) pathways_and_reactions_store.add(bug, "B", "pathway2", 2) # The pathways for this bug are missing too many reactions to have abundance expected_reactions_in_pathways_present[bug] = [] bug = "bug3" pathways_and_reactions_store.add(bug, "A", "pathway3", 1) pathways_and_reactions_store.add(bug, "B", "pathway3", 3) pathways_and_reactions_store.add(bug, "G", "pathway3", 2) pathways_and_reactions_store.add(bug, "B", "pathway2", 2) # One pathway for this bug includes all reactions expected_reactions_in_pathways_present[bug] = ["A", "B", "G"] pathways_abundance_store_result, reactions_in_pathways_present = modules.compute_pathways_abundance( pathways_and_reactions_store, pathways_database_store) # Test the reactions match those expected self.assertEqual( sorted(expected_reactions_in_pathways_present["bug1"]), sorted(list(reactions_in_pathways_present["bug1"]))) self.assertEqual( sorted(expected_reactions_in_pathways_present["bug2"]), sorted(list(reactions_in_pathways_present["bug2"]))) self.assertEqual( sorted(expected_reactions_in_pathways_present["bug3"]), sorted(list(reactions_in_pathways_present["bug3"])))