napistu.modify.cofactors

Module to detect and remove cofactors from a pathway model

Public Functions

drop_cofactors

Remove reaction species when they are acting as cofactors

identify_cofactors

Identify reaction species that are acting as cofactors

Functions

drop_cofactors(sbml_dfs[, ...])

Drop Cofactors

identify_cofactors(sbml_dfs[, ...])

Identify Cofactors

Classes

CofactorChebiIDs(*, cofactor_mapping)

Validator for COFACTOR_CHEBI_IDS dictionary structure.

CofactorFilterRule(*, if_all, except_any, ...)

Validator for a single cofactor filter rule.

CofactorSchema(*, schema_mapping)

Validator for COFACTOR_SCHEMA dictionary structure.

class napistu.modify.cofactors.CofactorChebiIDs(*, cofactor_mapping: Dict[str, List[int]])

Bases: BaseModel

Validator for COFACTOR_CHEBI_IDS dictionary structure.

classmethod validate_cofactor_chebi_structure(v: Dict[str, List[int]]) Dict[str, List[int]]

Validate the cofactor ChEBI ID mapping structure.

Checks: 1. All keys are non-empty strings 2. All values are non-empty lists of integers 3. All ChEBI IDs are positive integers 4. No ChEBI ID appears in multiple cofactor sets

get_all_chebi_ids() List[int]

Get a flat list of all ChEBI IDs.

Returns:

All ChEBI IDs across all cofactors

Return type:

List[int]

get_chebi_to_cofactor_map() Dict[int, str]

Create a mapping from ChEBI IDs to cofactor names.

Returns:

Dictionary mapping ChEBI ID to cofactor name

Return type:

Dict[int, str]

_abc_impl = <_abc._abc_data object>
cofactor_mapping: Dict[str, List[int]]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class napistu.modify.cofactors.CofactorFilterRule(*, if_all: ~typing.List[str], except_any: ~typing.List[str] = <factory>, as_substrate: ~typing.List[str] = <factory>)

Bases: BaseModel

Validator for a single cofactor filter rule.

classmethod validate_cofactor_names(v: List[str]) List[str]

Validate that all cofactor names are non-empty strings.

classmethod validate_if_all_not_empty(v: List[str]) List[str]

Validate that if_all is not empty.

_abc_impl = <_abc._abc_data object>
as_substrate: List[str]
except_any: List[str]
if_all: List[str]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class napistu.modify.cofactors.CofactorSchema(*, schema_mapping: Dict[str, CofactorFilterRule])

Bases: BaseModel

Validator for COFACTOR_SCHEMA dictionary structure.

classmethod validate_schema_not_empty(v: Dict[str, CofactorFilterRule]) Dict[str, CofactorFilterRule]

Validate that schema is not empty.

_abc_impl = <_abc._abc_data object>
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

schema_mapping: Dict[str, CofactorFilterRule]
napistu.modify.cofactors._apply_cofactor_filters(cofactor_rscspecies: DataFrame, cofactor_schema: dict = {'ATP PO4 donation': {'except_any': ['AMP'], 'if_all': ['ATP', 'ADP']}, 'ATP PPi donation': {'except_any': ['ADP'], 'if_all': ['ATP', 'AMP']}, 'CO2': {'if_all': ['CO2']}, 'Cl-': {'if_all': ['Cl-']}, 'CoA': {'if_all': ['CoA']}, 'GTP PO4 donation': {'if_all': ['GTP', 'GDP']}, 'Glutathione oxidation': {'except_any': ['NADPH'], 'if_all': ['GSSG', 'GSH']}, 'H+': {'if_all': ['H+']}, 'HCO3-': {'if_all': ['HCO3']}, 'NADH H- donation': {'as_substrate': ['NADH'], 'if_all': ['NADH', 'NAD+']}, 'NADPH H- donation': {'as_substrate': ['NADPH'], 'if_all': ['NADPH', 'NADP+']}, 'Na+': {'if_all': ['Na+']}, 'O2': {'if_all': ['O2']}, 'PO4': {'if_all': ['PO4']}, 'PPi': {'if_all': ['PPi']}, 'SAH methyltransferase': {'if_all': ['SAH', 'SAM']}, 'Water': {'if_all': ['water']}}) Series

Apply Cofactor Filters to Reactions

Apply cofactor filtering rules to identify reaction species that should be removed as cofactors based on the defined schema.

Parameters:
  • cofactor_rscspecies (pd.DataFrame) – Reaction species DataFrame with cofactor annotations

  • cofactor_schema (dict, optional) – Dictionary mapping filter names to cofactor filter rules. Defaults to COFACTOR_SCHEMA.

Returns:

Series with index of rsc_ids and values containing the reason why a reaction species is a cofactor

Return type:

pd.Series

napistu.modify.cofactors._apply_filters_to_reaction(one_rxns_species: DataFrame, cofactor_schema: dict = {'ATP PO4 donation': {'except_any': ['AMP'], 'if_all': ['ATP', 'ADP']}, 'ATP PPi donation': {'except_any': ['ADP'], 'if_all': ['ATP', 'AMP']}, 'CO2': {'if_all': ['CO2']}, 'Cl-': {'if_all': ['Cl-']}, 'CoA': {'if_all': ['CoA']}, 'GTP PO4 donation': {'if_all': ['GTP', 'GDP']}, 'Glutathione oxidation': {'except_any': ['NADPH'], 'if_all': ['GSSG', 'GSH']}, 'H+': {'if_all': ['H+']}, 'HCO3-': {'if_all': ['HCO3']}, 'NADH H- donation': {'as_substrate': ['NADH'], 'if_all': ['NADH', 'NAD+']}, 'NADPH H- donation': {'as_substrate': ['NADPH'], 'if_all': ['NADPH', 'NADP+']}, 'Na+': {'if_all': ['Na+']}, 'O2': {'if_all': ['O2']}, 'PO4': {'if_all': ['PO4']}, 'PPi': {'if_all': ['PPi']}, 'SAH methyltransferase': {'if_all': ['SAH', 'SAM']}, 'Water': {'if_all': ['water']}}) Series

Apply All Filters to Single Reaction

Apply all cofactor filtering rules to a single reaction’s species and return the combined results.

Parameters:
  • one_rxns_species (pd.DataFrame) – Reaction species DataFrame for a single reaction with cofactor annotations

  • cofactor_schema (dict, optional) – Dictionary mapping filter names to cofactor filter rules. Defaults to COFACTOR_SCHEMA.

Returns:

Series with index of rsc_ids and values containing the reason why a reaction species is a cofactor. Empty series if no filters apply.

Return type:

pd.Series

napistu.modify.cofactors._filter_one_reactions_cofactors(one_rxns_species: DataFrame, filter_type: str, cofactor_filter: dict) Series

Filter One Reaction’s Cofactors

Apply a cofactor filter to one reaction’s species

Parameters:

one_rxns_species (pd.DataFrame):

Rows of reactions species containing cofactors

filter_type: str

Reason to filter species with this filter

cofactor_filter: dict

Species included in filter

Returns:

pd.Series with index of rsc_ids and values containing the reason why a reaction species is a cofactor, or None if filter was not triggered.

napistu.modify.cofactors._find_cofactor_species(sbml_dfs: SBML_dfs, cofactor_chebi_ids: dict = {'ADP': [456216, 16761], 'AMP': [16027], 'ATP': [30616, 15422], 'CO2': [16526], 'Cl-': [29311], 'CoA': [1146900, 57287], 'FAD': [16238], 'FADH2': [17877], 'GDP': [17552], 'GSH': [16856], 'GSSG': [17858], 'GTP': [15996], 'Gln': [58359], 'Glu': [29985], 'H+': [15378, 24636], 'H2CO3': [28976], 'HCO3': [17544], 'NAD+': [57540, 15846], 'NADH': [57945, 16908], 'NADP+': [18009, 58349], 'NADPH': [16474], 'Na+': [29101], 'O2': [15379], 'PO4': [18367], 'PPi': [29888, 18361], 'SAH': [16680], 'SAM': [15414], 'UDP': [17659], 'acetyl-CoA': [15351], 'water': [15377, 16234]}) DataFrame

Find Cofactor Species

Identify species in the SBML_dfs that match known cofactor ChEBI IDs.

Parameters:
  • sbml_dfs (SBML_dfs) – A pathway model

  • cofactor_chebi_ids (dict, optional) – Dictionary mapping cofactor names to lists of ChEBI IDs. Defaults to COFACTOR_CHEBI_IDS.

Returns:

DataFrame with species information and their corresponding cofactor names, with one row per species (deduplicated by s_id)

Return type:

pd.DataFrame

napistu.modify.cofactors._map_cofactors_to_reaction_species(sbml_dfs: SBML_dfs, cofactor_species: DataFrame) DataFrame

Map Cofactors to Reaction Species

Take species with cofactor annotations and map them through compartmentalized species to reaction species, filtering to only those with non-zero stoichiometry.

Parameters:
  • sbml_dfs (SBML_dfs) – A pathway model

  • cofactor_species (pd.DataFrame) – DataFrame with species information and cofactor annotations, must contain ‘cofactor’ column and be indexed by s_id

Returns:

Reaction species DataFrame with cofactor annotations, filtered to non-zero stoichiometry entries

Return type:

pd.DataFrame

napistu.modify.cofactors.drop_cofactors(sbml_dfs: SBML_dfs, cofactor_chebi_ids: dict = {'ADP': [456216, 16761], 'AMP': [16027], 'ATP': [30616, 15422], 'CO2': [16526], 'Cl-': [29311], 'CoA': [1146900, 57287], 'FAD': [16238], 'FADH2': [17877], 'GDP': [17552], 'GSH': [16856], 'GSSG': [17858], 'GTP': [15996], 'Gln': [58359], 'Glu': [29985], 'H+': [15378, 24636], 'H2CO3': [28976], 'HCO3': [17544], 'NAD+': [57540, 15846], 'NADH': [57945, 16908], 'NADP+': [18009, 58349], 'NADPH': [16474], 'Na+': [29101], 'O2': [15379], 'PO4': [18367], 'PPi': [29888, 18361], 'SAH': [16680], 'SAM': [15414], 'UDP': [17659], 'acetyl-CoA': [15351], 'water': [15377, 16234]}, cofactor_schema: dict = {'ATP PO4 donation': {'except_any': ['AMP'], 'if_all': ['ATP', 'ADP']}, 'ATP PPi donation': {'except_any': ['ADP'], 'if_all': ['ATP', 'AMP']}, 'CO2': {'if_all': ['CO2']}, 'Cl-': {'if_all': ['Cl-']}, 'CoA': {'if_all': ['CoA']}, 'GTP PO4 donation': {'if_all': ['GTP', 'GDP']}, 'Glutathione oxidation': {'except_any': ['NADPH'], 'if_all': ['GSSG', 'GSH']}, 'H+': {'if_all': ['H+']}, 'HCO3-': {'if_all': ['HCO3']}, 'NADH H- donation': {'as_substrate': ['NADH'], 'if_all': ['NADH', 'NAD+']}, 'NADPH H- donation': {'as_substrate': ['NADPH'], 'if_all': ['NADPH', 'NADP+']}, 'Na+': {'if_all': ['Na+']}, 'O2': {'if_all': ['O2']}, 'PO4': {'if_all': ['PO4']}, 'PPi': {'if_all': ['PPi']}, 'SAH methyltransferase': {'if_all': ['SAH', 'SAM']}, 'Water': {'if_all': ['water']}}, verbose: bool = True) SBML_dfs

Drop Cofactors

Remove reaction species when they are acting as cofactors

Parameters:

sbml_dfs: SBML_dfs

A pathway model

cofactor_chebi_ids: dict

Dictionary mapping cofactor names to lists of ChEBI IDs

cofactor_schema: dict

Dictionary mapping filter names to cofactor filter rules

verbose: bool

Whether to print verbose output

Returns:

sbml_dfs (SBML_dfs):

A pathway model with some reaction species filtered

napistu.modify.cofactors.identify_cofactors(sbml_dfs: SBML_dfs, cofactor_chebi_ids: dict = {'ADP': [456216, 16761], 'AMP': [16027], 'ATP': [30616, 15422], 'CO2': [16526], 'Cl-': [29311], 'CoA': [1146900, 57287], 'FAD': [16238], 'FADH2': [17877], 'GDP': [17552], 'GSH': [16856], 'GSSG': [17858], 'GTP': [15996], 'Gln': [58359], 'Glu': [29985], 'H+': [15378, 24636], 'H2CO3': [28976], 'HCO3': [17544], 'NAD+': [57540, 15846], 'NADH': [57945, 16908], 'NADP+': [18009, 58349], 'NADPH': [16474], 'Na+': [29101], 'O2': [15379], 'PO4': [18367], 'PPi': [29888, 18361], 'SAH': [16680], 'SAM': [15414], 'UDP': [17659], 'acetyl-CoA': [15351], 'water': [15377, 16234]}, cofactor_schema: dict = {'ATP PO4 donation': {'except_any': ['AMP'], 'if_all': ['ATP', 'ADP']}, 'ATP PPi donation': {'except_any': ['ADP'], 'if_all': ['ATP', 'AMP']}, 'CO2': {'if_all': ['CO2']}, 'Cl-': {'if_all': ['Cl-']}, 'CoA': {'if_all': ['CoA']}, 'GTP PO4 donation': {'if_all': ['GTP', 'GDP']}, 'Glutathione oxidation': {'except_any': ['NADPH'], 'if_all': ['GSSG', 'GSH']}, 'H+': {'if_all': ['H+']}, 'HCO3-': {'if_all': ['HCO3']}, 'NADH H- donation': {'as_substrate': ['NADH'], 'if_all': ['NADH', 'NAD+']}, 'NADPH H- donation': {'as_substrate': ['NADPH'], 'if_all': ['NADPH', 'NADP+']}, 'Na+': {'if_all': ['Na+']}, 'O2': {'if_all': ['O2']}, 'PO4': {'if_all': ['PO4']}, 'PPi': {'if_all': ['PPi']}, 'SAH methyltransferase': {'if_all': ['SAH', 'SAM']}, 'Water': {'if_all': ['water']}}) Series

Identify Cofactors

Find cofactors which are playing a supporting role in a reaction (e.g., ATP -> ADP or water).

Parameters:

sbml_dfs: SBML_dfs

A pathway model

Returns:

pd.Series with index of rsc_ids and values containing the reason why a reaction species is a cofactor