def integrationBorderShortestPath(selected_pg, target_run, transformation_collection_, tree):
    """Determine the optimal integration border by using the shortest path in the MST

    Args:
        selected_pg(list(GeneralPeakGroup)): list of selected peakgroups (e.g. those passing the quality threshold)
        target_run(String): run id of the target run (where value is missing)
        transformation_collection_(:class:`.LightTransformationData`): structure to hold binary transformations between two different retention time spaces
        tree(list(tuple)): a minimum spanning tree (MST) represented as list of edges (for example [('0', '1'), ('1', '2')] ). Node names need to correspond to run ids.

    Returns:
        A tuple of (left_integration_border, right_integration_border)
    """

    # Get the shortest path through the MST
    available_runs = [pg.peptide.run.get_id() for pg in selected_pg if pg.get_fdr_score() < 1.0]
    final_path = graphs.findShortestMSTPath(tree, target_run, available_runs)

    # Extract the starting point and the starting borders (left/right)
    source_run = final_path[-1]
    best_pg = [pg for pg in selected_pg if pg.peptide.run.get_id() == source_run][0]
    rwidth = float(best_pg.get_value("rightWidth"))
    lwidth = float(best_pg.get_value("leftWidth"))
    # if verb: print "Compare from", source_run, "directly to", target_run,\
    #     transformation_collection_.getTrafo(source_run, target_run).predict([lwidth])[0], \
    #     transformation_collection_.getTrafo(source_run, target_run).predict([rwidth])[0]

    # Traverse path in reverse order
    for target_run_ in reversed(final_path[:-1]):

        # Transform, go to next step
        lwidth = transformation_collection_.getTrafo(source_run, target_run_).predict([lwidth])[0]
        rwidth = transformation_collection_.getTrafo(source_run, target_run_).predict([rwidth])[0]
        source_run = target_run_

    return lwidth, rwidth
    def test_findShortestMSTPath(self):
        """Test the findShortestMSTPath algorithm"""

        # Test path with one possibility
        res = graphs.findShortestMSTPath(self.mst3, "0_2", ["0_0"])
        expected = ['0_2', '0_1', '0_0']
        self.assertEqual(expected, res)

        # Test path with one possibility
        res = graphs.findShortestMSTPath(self.mst3, "0_2", ["0_1"])
        expected = ['0_2', '0_1']
        self.assertEqual(expected, res)

        # Test path with one possibility
        res = graphs.findShortestMSTPath(self.mst3, "0_2", ["0_5"])
        expected = ['0_2', '0_1', '0_4', '0_5']
        self.assertEqual(expected, res)

        # Test path with two possibilities, the shorter one is 0_0 and should
        # be chosen
        res = graphs.findShortestMSTPath(self.mst3, "0_2", ["0_5", "0_0"])
        expected = ['0_2', '0_1', '0_0']
        self.assertEqual(expected, res)
Exemple #3
0
    def test_findShortestMSTPath(self):
        """Test the findShortestMSTPath algorithm"""

        # Test path with one possibility
        res = graphs.findShortestMSTPath(self.mst3, "0_2", ["0_0"])
        expected = ['0_2', '0_1', '0_0']
        self.assertEqual(expected, res)

        # Test path with one possibility
        res = graphs.findShortestMSTPath(self.mst3, "0_2", ["0_1"])
        expected = ['0_2', '0_1']
        self.assertEqual(expected, res)

        # Test path with one possibility
        res = graphs.findShortestMSTPath(self.mst3, "0_2", ["0_5"])
        expected = ['0_2', '0_1', '0_4', '0_5']
        self.assertEqual(expected, res)

        # Test path with two possibilities, the shorter one is 0_0 and should
        # be chosen
        res = graphs.findShortestMSTPath(self.mst3, "0_2", ["0_5", "0_0"])
        expected = ['0_2', '0_1', '0_0']
        self.assertEqual(expected, res)
Exemple #4
0
def integrationBorderShortestPath(selected_pg, target_run,
                                  transformation_collection_, tree):
    """Determine the optimal integration border by using the shortest path in the MST

    Args:
        selected_pg(list(GeneralPeakGroup)): list of selected peakgroups (e.g. those passing the quality threshold)
        target_run(String): run id of the target run (where value is missing)
        transformation_collection_(:class:`.LightTransformationData`): structure to hold binary transformations between two different retention time spaces
        tree(list(tuple)): a minimum spanning tree (MST) represented as list of edges (for example [('0', '1'), ('1', '2')] ). Node names need to correspond to run ids.

    Returns:
        A tuple of (left_integration_border, right_integration_border)
    """

    # Get the shortest path through the MST
    available_runs = [
        pg.peptide.run.get_id() for pg in selected_pg
        if pg.get_fdr_score() < 1.0
    ]
    final_path = graphs.findShortestMSTPath(tree, target_run, available_runs)

    # Extract the starting point and the starting borders (left/right)
    source_run = final_path[-1]
    best_pg = [
        pg for pg in selected_pg if pg.peptide.run.get_id() == source_run
    ][0]
    rwidth = float(best_pg.get_value("rightWidth"))
    lwidth = float(best_pg.get_value("leftWidth"))
    # if verb: print "Compare from", source_run, "directly to", target_run,\
    #     transformation_collection_.getTrafo(source_run, target_run).predict([lwidth])[0], \
    #     transformation_collection_.getTrafo(source_run, target_run).predict([rwidth])[0]

    # Traverse path in reverse order
    for target_run_ in reversed(final_path[:-1]):

        # Transform, go to next step
        lwidth = transformation_collection_.getTrafo(
            source_run, target_run_).predict([lwidth])[0]
        rwidth = transformation_collection_.getTrafo(
            source_run, target_run_).predict([rwidth])[0]
        source_run = target_run_

    return lwidth, rwidth