コード例 #1
0
    def find_essential_reactions_1(self):
        """ Computes the list of essential reactions of the model
			Saves the result in __essential_reactions attribute.
			Returns a list of error during the computation.

		:return: list of error during the computation.
		:rtype: list of str
		"""
        errors = []
        try:
            self.__objective_value = self.get_growth()
            if isnan(self.__objective_value):
                self.__objective_value = None
            self.__essential_reactions = {}
            deletions = single_reaction_deletion(self.__cobra_model,
                                                 method='fba',
                                                 processes=self.__processes)
            essential = deletions.loc[:, :]['growth']
            for r, g in essential.iteritems():
                reaction = self.__cobra_model.reactions.get_by_id(list(r)[0])
                self.__essential_reactions[reaction] = g
        except Exception as error:
            errors.append(str(error))
            self.__essential_reactions = {}
        return errors
コード例 #2
0
def find_essential_reactions(model, threshold=None, processes=None):
    """Return a set of essential reactions.

    A reaction is considered essential if restricting its flux to zero
    causes the objective, e.g., the growth rate, to also be zero, below the
    threshold, or infeasible.


    Parameters
    ----------
    model : cobra.Model
        The model to find the essential reactions for.
    threshold : float, optional
        Minimal objective flux to be considered viable. By default this is
        1% of the maximal objective.
    processes : int, optional
        The number of parallel processes to run. Can speed up the computations
        if the number of knockouts to perform is large. If not passed,
        will be set to the number of CPUs found.

    Returns
    -------
    set
        Set of essential reactions
    """
    if threshold is None:
        threshold = model.slim_optimize(error_value=None) * 1E-02
    deletions = single_reaction_deletion(model,
                                         method='fba',
                                         processes=processes)
    essential = deletions.loc[deletions['growth'].isna() |
                              (deletions['growth'] < threshold), :].index
    return {model.reactions.get_by_id(r) for ids in essential for r in ids}
コード例 #3
0
ファイル: variability.py プロジェクト: cdiener/cobrapy
def find_essential_reactions(model, threshold=None, processes=None):
    """Return a set of essential reactions.

    A reaction is considered essential if restricting its flux to zero
    causes the objective (e.g. the growth rate) to also be zero.

    Parameters
    ----------
    model : cobra.Model
        The model to find the essential reactions for.
    threshold : float, optional
        Minimal objective flux to be considered viable. By default this is
        0.01 times the growth rate.
    processes : int, optional
        The number of parallel processes to run. Can speed up the computations
        if the number of knockouts to perform is large. If not passed,
        will be set to the number of CPUs found.

    Returns
    -------
    set
        Set of essential reactions
    """
    if threshold is None:
        threshold = model.slim_optimize(error_value=None) * 1E-02
    deletions = single_reaction_deletion(model, method='fba',
                                         processes=processes)
    essential = deletions.loc[deletions['growth'].isna() |
                              (deletions['growth'] < threshold), :].index
    return set(model.reactions.get_by_id(r) for ids in essential for r in ids)
コード例 #4
0
ファイル: variability.py プロジェクト: jlerman44/cobrapy_main
def find_essential_reactions(model, threshold=None):
    """Return a set of essential reactions.

    A reaction is considered essential if restricting its flux to zero
    causes the objective (e.g. the growth rate) to also be zero.

    Parameters
    ----------
    model : cobra.Model
        The model to find the essential reactions for.
    threshold : float, optional
        Minimal objective flux to be considered viable. By default this is
        0.01 times the growth rate.

    Returns
    -------
    set
        Set of essential reactions
    """
    if threshold is None:
        threshold = model.slim_optimize(error_value=None) * 1E-02
    deletions = single_reaction_deletion(model, method='fba')
    essential = deletions.loc[deletions['growth'].isna() |
                              (deletions['growth'] < threshold), :].index
    return set(model.reactions.get_by_id(r) for ids in essential for r in ids)
コード例 #5
0
def find_essential_reactions(model, threshold=None):
    """Return a set of essential reactions.

    A reaction is considered essential if restricting its flux to zero
    causes the objective (e.g. the growth rate) to also be zero.

    Parameters
    ----------
    model : cobra.Model
        The model to find the essential reactions for.
    threshold : float, optional
        Minimal objective flux to be considered viable. By default this is
        0.01 times the growth rate.

    Returns
    -------
    set
        Set of essential reactions
    """
    if threshold is None:
        threshold = model.slim_optimize(error_value=None) * 1E-02
    deletions = single_reaction_deletion(model, method='fba')
    essential = deletions.loc[deletions['growth'].isna() |
                              (deletions['growth'] < threshold), :].index
    return set(model.reactions.get_by_id(r) for ids in essential for r in ids)
コード例 #6
0
ファイル: test_deletion.py プロジェクト: opencobra/cobrapy
def test_single_reaction_deletion(model, all_solvers):
    """Test single reaction deletion."""
    model.solver = all_solvers
    expected_results = {'FBA': 0.70404, 'FBP': 0.87392, 'CS': 0,
                        'FUM': 0.81430, 'GAPD': 0, 'GLUDy': 0.85139}
    result = single_reaction_deletion(
        model=model,
        reaction_list=list(expected_results),
        processes=1
    )['growth']
    for reaction, value in iteritems(expected_results):
        assert np.isclose(result[frozenset([reaction])], value,
                          atol=1E-05)
コード例 #7
0
ファイル: test_deletion.py プロジェクト: sumanasri/cobrapy
def test_single_reaction_deletion(model, all_solvers):
    """Test single reaction deletion."""
    model.solver = all_solvers
    expected_results = {
        'FBA': 0.70404,
        'FBP': 0.87392,
        'CS': 0,
        'FUM': 0.81430,
        'GAPD': 0,
        'GLUDy': 0.85139
    }
    result = single_reaction_deletion(model=model,
                                      reaction_list=list(expected_results),
                                      processes=1)['growth']
    for reaction, value in iteritems(expected_results):
        assert np.isclose(result[frozenset([reaction])], value, atol=1E-05)
コード例 #8
0
ファイル: test_deletion.py プロジェクト: cgaray/cobrapy
def test_single_reaction_deletion(model: Model, all_solvers) -> None:
    """Test single reaction deletion."""
    model.solver = all_solvers
    expected_results = {
        "FBA": 0.70404,
        "FBP": 0.87392,
        "CS": 0,
        "FUM": 0.81430,
        "GAPD": 0,
        "GLUDy": 0.85139,
    }
    result = single_reaction_deletion(
        model=model, reaction_list=list(expected_results), processes=1
    )

    for reaction, value in expected_results.items():
        assert np.isclose(result.knockout[reaction].growth, value, atol=1e-05)
コード例 #9
0
ファイル: test_deletion.py プロジェクト: cgaray/cobrapy
def test_deletion_accessor(small_model: Model) -> None:
    """Test the DataFrame accessor."""
    single = single_reaction_deletion(small_model, small_model.reactions[0:10])
    double = double_reaction_deletion(small_model, small_model.reactions[0:10])
    rxn1 = small_model.reactions[0]
    rxn2 = small_model.reactions[1]

    with pytest.raises(ValueError):
        single.knockout[1]

    with pytest.raises(ValueError):
        single.knockout[{"a": 1}]

    assert single.knockout[rxn1].ids.iloc[0] == {rxn1.id}
    assert double.knockout[{rxn1, rxn2}].ids.iloc[0] == {rxn1.id, rxn2.id}
    assert all(single.knockout[rxn1.id] == single.knockout[rxn1])
    assert all(double.knockout[{rxn1.id, rxn2.id}] == double.knockout[{rxn1, rxn2}])
    assert single.knockout[rxn1, rxn2].shape == (2, 3)
    assert double.knockout[rxn1, rxn2].shape == (2, 3)
    assert double.knockout[{rxn1, rxn2}].shape == (1, 3)
    assert double.knockout[{rxn1}, {rxn2}].shape == (2, 3)