6.1.1.3. pytfa.io

6.1.1.3.1. Submodules

6.1.1.3.2. Package Contents

6.1.1.3.2.1. Classes

MyEncoder

We define an encoder that takes care of the serialization of numpy types,

6.1.1.3.2.2. Functions

import_matlab_model(path, variable_name=None)

Convert at matlab cobra_model to a pyTFA cobra_model, with Thermodynamic values

recover_compartments(model, compartments_list)

write_matlab_model(tmodel, path, varname='tmodel')

Writes the Thermo Model to a Matlab-compatible structure

create_thermo_dict(tmodel)

Dumps the thermodynamic information in a mat-compatible dictionary

varnames2matlab(name, tmodel)

Transforms reaction variable pairs from ('ACALD','ACALD_reverse_xxxxx') to

create_problem_dict(tmodel)

Dumps the the MILP formulation for TFA in a mat-compatible dictionary

create_generalized_matrix(tmodel, array_type='dense')

Returns the generalized stoichiomatric matrix used for TFA

load_thermoDB(path)

Load a thermodynamic database

printLP(model)

Print the LP file corresponding to the cobra_model

writeLP(model, path=None)

Write the LP file of the specified cobra_model to the file indicated by path.

write_lexicon(tmodel, filepath)

Writes a csv file in the format :

annotate_from_lexicon(model, lexicon)

Converts a lexicon into annotation for the metabolites

read_lexicon(filepath)

write_compartment_data(tmodel, filepath)

param filepath

read_compartment_data(filepath)

apply_compartment_data(tmodel, compartment_data)

6.1.1.3.2.3. Attributes

BIGM_DG

pytfa.io.BIGM_DG = 1000.0
pytfa.io.import_matlab_model(path, variable_name=None)[source]

Convert at matlab cobra_model to a pyTFA cobra_model, with Thermodynamic values

Parameters
  • variable_name

  • path (string) – The path of the file to import

Returns

The converted cobra_model

Return type

cobra.thermo.model.Model

pytfa.io.recover_compartments(model, compartments_list)[source]
pytfa.io.write_matlab_model(tmodel, path, varname='tmodel')[source]

Writes the Thermo Model to a Matlab-compatible structure

Parameters
  • varname

  • tmodel

  • path

Returns

None

pytfa.io.create_thermo_dict(tmodel)[source]

Dumps the thermodynamic information in a mat-compatible dictionary (similar to the output of cobra.io.mat.create_mat_dict)

Parameters

tmodel – pytfa.thermo.tmodel.ThermoModel

Returns

dict object

pytfa.io.varnames2matlab(name, tmodel)[source]

Transforms reaction variable pairs from (‘ACALD’,’ACALD_reverse_xxxxx’) to (‘F_ACALD’,’B_ACALD’) if it is a reaction, else leaves is as is

Returns

pytfa.io.create_problem_dict(tmodel)[source]

Dumps the the MILP formulation for TFA in a mat-compatible dictionary (similar to the output of cobra.io.mat.create_mat_dict)

Parameters

tmodel – pytfa.thermo.tmodel.ThermoModel

:ret

pytfa.io.create_generalized_matrix(tmodel, array_type='dense')[source]

Returns the generalized stoichiomatric matrix used for TFA

Parameters
  • array_type

  • tmodel – pytfa.ThermoModel

Returns

matrix.

pytfa.io.load_thermoDB(path)[source]

Load a thermodynamic database

Parameters

path (string) – The path of the file to load

Returns

The thermodynamic database

Return type

dict

pytfa.io.printLP(model)[source]

Print the LP file corresponding to the cobra_model

Parameters

model (cobra.thermo.model.Model) – The cobra_model to output the LP file for

Returns

The content of the LP file

Return type

str

Usually, you pass the result of this function to file.write() to write it on disk. If you prefer, you can use pytfa.io.writeLP() to write the result directly to a file.

pytfa.io.writeLP(model, path=None)[source]

Write the LP file of the specified cobra_model to the file indicated by path.

Parameters
  • model (cobra.thermo.model.Model) – The COBRApy cobra_model to write the LP file for

  • path (string) – Optional The path of the file to be written. If not specified, the name of the COBRApy cobra_model will be used.

class pytfa.io.MyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: json.JSONEncoder

We define an encoder that takes care of the serialization of numpy types, which are not handled by json by default

default(self, obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
pytfa.io.write_lexicon(tmodel, filepath)[source]
Writes a csv file in the format :

seed_id

13BDglcn_c cpd11791 13dpg_c cpd00203 2pg_c cpd00482 3pg_c cpd00169 4abut_c cpd00281

Useful for exporting an annotation

Parameters
  • tmodel (pytfa.core.ThermoModel) –

  • filepath

Returns

pytfa.io.annotate_from_lexicon(model, lexicon)[source]

Converts a lexicon into annotation for the metabolites

Parameters
  • model (cobra.Model) –

  • lexicon

Returns

pytfa.io.read_lexicon(filepath)[source]
pytfa.io.write_compartment_data(tmodel, filepath)[source]
Parameters
  • filepath

  • tmodel (pytfa.core.ThermoModel) –

Returns

pytfa.io.read_compartment_data(filepath)[source]
pytfa.io.apply_compartment_data(tmodel, compartment_data)[source]