17.1.1.4.1.3. cobra.manipulation.modify

17.1.1.4.1.3.1. Module Contents

17.1.1.4.1.3.1.1. Classes

_GeneEscaper

A NodeVisitor subclass that walks the abstract syntax tree and

17.1.1.4.1.3.1.2. Functions

_escape_str_id(id_str)

make a single string id SBML compliant

escape_ID(cobra_model)

makes all ids SBML compliant

rename_genes(cobra_model, rename_dict)

renames genes in a model from the rename_dict

cobra.manipulation.modify._renames = [['.', '_DOT_'], ['(', '_LPAREN_'], [')', '_RPAREN_'], ['-', '__'], ['[', '_LSQBKT'], [']', '_RSQBKT'], [',', '_COMMA_'], [':', '_COLON_'], ['>', '_GT_'], ['<', '_LT'], ['/', '_FLASH'], ['\\', '_BSLASH'], ['+', '_PLUS_'], ['=', '_EQ_'], [' ', '_SPACE_'], ["'", '_SQUOT_'], ['"', '_DQUOT_']][source]
cobra.manipulation.modify._escape_str_id(id_str)[source]

make a single string id SBML compliant

class cobra.manipulation.modify._GeneEscaper[source]

Bases: ast.NodeTransformer

A NodeVisitor subclass that walks the abstract syntax tree and allows modification of nodes.

The NodeTransformer will walk the AST and use the return value of the visitor methods to replace or remove the old node. If the return value of the visitor method is None, the node will be removed from its location, otherwise it is replaced with the return value. The return value may be the original node in which case no replacement takes place.

Here is an example transformer that rewrites all occurrences of name lookups (foo) to data['foo']:

class RewriteName(NodeTransformer):

    def visit_Name(self, node):
        return Subscript(
            value=Name(id='data', ctx=Load()),
            slice=Index(value=Str(s=node.id)),
            ctx=node.ctx
        )

Keep in mind that if the node you’re operating on has child nodes you must either transform the child nodes yourself or call the generic_visit() method for the node first.

For nodes that were part of a collection of statements (that applies to all statement nodes), the visitor may also return a list of nodes rather than just a single node.

Usually you use the transformer like this:

node = YourTransformer().visit(node)
visit_Name(self, node)[source]
cobra.manipulation.modify.escape_ID(cobra_model)[source]

makes all ids SBML compliant

cobra.manipulation.modify.rename_genes(cobra_model, rename_dict)[source]

renames genes in a model from the rename_dict