psamm.bayesian – Bayesian Matching Functions

Calculate model mapping likelihood with bayesian.

class psamm.bayesian.CompoundEntry(id, name, formula, charge, kegg, cas)
cas

Alias for field number 5

charge

Alias for field number 3

formula

Alias for field number 2

id

Alias for field number 0

kegg

Alias for field number 4

name

Alias for field number 1

class psamm.bayesian.ReactionEntry(id, name, genes, equation, subsystem, ec)
ec

Alias for field number 5

equation

Alias for field number 3

genes

Alias for field number 2

id

Alias for field number 0

name

Alias for field number 1

subsystem

Alias for field number 4

class psamm.bayesian.MappingModel(model)

Generate the internal structure for model mapping.

Parameters:modelpsamm.datasource.native.NativeModel
print_summary()

Print model summary

check_reaction_compounds()

Check that reaction compounds are defined in the model

class psamm.bayesian.BayesianCompoundPredictor(model1, model2, nproc=1, outpath='.', log=False, kegg=False)

Predict model compound mappings based on a Bayesian model.

Parameters:
  • model1psamm.bayesian.MappingModel.
  • model2psamm.bayesian.MappingModel.
  • nproc – number of processes used for mapping.
  • outpath – the path to output the detailed log file.
  • log – whether to output log file of the p_match and p_no_match.
  • kegg – whether to compare the KEGG id.
get_raw_map()

Return pandas.DataFrame style of raw mapping table.

get_best_map(threshold_compound=0)

Return pandas.DataFrame style of best mapping for each query.

get_cpd_pred(threshold_compound=0)

Return the cpd_pred used for reaction mapping.

class psamm.bayesian.BayesianReactionPredictor(model1, model2, cpd_pred, nproc=1, outpath='.', log=False, gene=False, compartment_map={}, gene_map={})

Predict model reaction mappings based on a Bayesian model.

Parameters:
  • model1psamm.bayesian.MappingModel.
  • model2psamm.bayesian.MappingModel.
  • cpd_predpandas.Series with compound pairs as index, compound mapping score as value.
  • nproc – number of processes used for mapping.
  • outpath – the path to output the detailed log file.
  • log – whether to output log file of the p_match and p_no_match.
  • gene – whether to compare the gene association.
  • compartment_map – dictionary mapping compartment id in the query model to the id in the target model.
  • gene_map – dictionary mapping gene id in the query model to the id in the target model.
get_raw_map()

Return pandas.DataFrame style of raw mapping table.

get_best_map(threshold_reaction=0)

Return pandas.DataFrame style of best mapping for each query.

psamm.bayesian.reaction_equation_mapping_approx_max_likelihood(cpd_set1, cpd_set2, cpd_map, cpd_score, compartment_map={})

Calculate equation likelihood based on compound mapping.

psamm.bayesian.reaction_equation_compound_mapping_likelihood(r1, r2, *args, **kwargs)

Get the likelihood of reaction equations

Parameters:r2 (r1,) – two RactionEntry objects to be compared
args, kwargs:
cpd_map: dictionary mapping compound id in the query model to a set
of best-mapping compound ids in the target model.
cpd_score: dictionary mapping compound id in the query model to
its best mapping score during compound mapping.
compartment_map: dictionary mapping compartment id in the query model
to the id in the target model.
psamm.bayesian.get_best_p_value_set(r1, r2, *args, **kwargs)

Assume equations may have reversed direction, report best mapping p.

psamm.bayesian.merge_partial_p_set(cpd_set1_left, cpd_set2_left, cpd_set1_right, cpd_set2_right, *args, **kwargs)

Merge the left hand side and right hand side p values together.

The compound mapping is done separately on left hand side and right hand side. Then the corresponding p_match and p_no_match are merged together.

psamm.bayesian.fake_likelihood(e1, e2)

Generate fake likelihood if corresponding mapping is not required.

psamm.bayesian.pairwise_likelihood(pool, chunksize, model1, model2, likelihood, *args, **kwargs)

Compute likelihood of all pairwise comparisons.

Returns likelihoods as a dataframe with a column for each hypothesis.

psamm.bayesian.likelihood_products(likelihood_dfs)

Combine likelihood dataframes.

psamm.bayesian.bayes_posterior(prior, likelihood_df)

Calculate posterior given likelihoods and prior.

psamm.bayesian.map_model_compounds(model1, model2, nproc=1, outpath='.', log=False, kegg=False)

Map compounds of two models.

psamm.bayesian.map_model_reactions(model1, model2, cpd_map, cpd_score, nproc=1, outpath='.', log=False, gene=False, compartment_map={}, gene_map={})

Map reactions of two models.