nuskell.dsdcompiler.interpreter

The nuskell programming language interpreter.

Nuskell code is interpreted using public functions of the Environment class. All other classes and functions are needed internally to set up the interpreter environment. Built-in functions and expressions are encapuslated in the respective namespace.

class nuskell.dsdcompiler.interpreter.ComplexFragment(sequence, structure, attr=None)[source]

A nucleic acid complex, i.e. a (sequence, structure) pair.

This is an extension of dsdobjects.core.DSD_Complex(), which stores an additional dictionary of attributes. This dictionary maps domain names as specified in the translation-scheme to the unique Domain() object.

Parameters:
  • attr (Dict[name]=Domain) – A mapping between names in the translation scheme and Domain objects

  • sequence (List[str]) – Domain Objects

  • structure (List[str]) – A list of dot-parens characters “.(.+).”

property flatten_cplx

Resolves nested complexes and their corresponding ‘~’ structure wildcard.

This function is very specific to Nuskell translation using macros, but it might be generalized to handle ‘Complex of Complexes’ behavior of some sort.

class nuskell.dsdcompiler.interpreter.NusFunction(args, body)[source]

A function of the nuskell programming language.

Parameters:
  • () (body) – The arguments of a function.

  • () – The function body.

exception nuskell.dsdcompiler.interpreter.NuskellEnvError[source]
class nuskell.dsdcompiler.interpreter.NuskellEnvironment[source]

The Nuskell language environment.

NuskellEnvironment() interprets the Nuskell language using low-level instructions, and executes the formal and main functions of translation schemes. Inherits from NuskellExpressions() and initializes built-in functions provided by NuskellFunctions().

Raises:

NuskellEnvError

create_binding(name, value)[source]

Create binding of a Nuskell function in the last level. :param name: Name of the function. :type name: str :param value: anything, really. :type value: …

interpret(code)[source]

Setup the environment (the final namespace).

Creates bindings for variables and functions defined in the body of the translation scheme. All keywords (class, function, macro, module) are treated the same, only the global keyword is special, as global expressions are interpreted first and then bound.

ref_binding(fname)[source]

Search levels (reversed) for function bindings given the reference.

Parameters:

fname (str) – Name of a function

Returns:

Function binding (self._env[?][fname])

translate_formal_species(fs_list)[source]

Apply the formal() function to the formal species in the input CRN.

First, the bindings for formal species are created, then the formal() function is applied to every formal species in the input CRN.

Returns:

[dict()] A dictionary of key=name, value=:obj:ComplexFragment()

translate_reactions(crn_parsed, modular=False)[source]

Execute the main() function of the translation scheme.

The input CRN is replaced with previously initialized formal species objects.

Parameters:

crn_paresed (List[Lists]) – A crn in crn_parser format.

Raises:

NuskellEnvError – If the compiled formal species cannot be found

Returns:

fuel species

Return type:

list

exception nuskell.dsdcompiler.interpreter.NuskellExit[source]
class nuskell.dsdcompiler.interpreter.NuskellExpressions[source]

Builtin expressions for Nuskell translation schemes.

interpret_expr(expr)[source]

Recursive interpretation the body of a global variable.

class nuskell.dsdcompiler.interpreter.NuskellFunctions(env)[source]

Builtin functions of Nuskell translation schemes.

This object is initialized within the NuskellEnvironment() after the respective functions have been bound. Most methods do not require any class variables and are therefore declared as staticmethods. As a consequence, the functions can be accessed without prior initialization of the Object.

static asgn_pattern_match(id, value)[source]

Pattern matching for list assignments.

For example: [a, b, c] = [1, 2, 3]

static complement(args)[source]

Returns the complement of a given input.

It can interpret Complex, Domains and dot-bracket lists, as well as lists of lists.

Parameters:

args – An expression in form of an array, where the first element in the array contains the data of interest.

eval_builtin_functions(f, args)[source]

Evaluate built-in functions.

Parameters:
  • f (str) – The built-in function name.

  • args (list) – The arguments for the function call.

Raises:

NuskellEnvError – “Function not found.”

Returns:

The results form f(args)

static flip(args)[source]

A matrix transpose function for lists of lists.

Parameters:

args (list) – Contains both the lol and and integer to specify the dimenstion.

Example

input: [[[x,y,z],[a,b,c],[n,l,k],[u,v,w]],3] returns: [[x,a,n,u],[y,b,l,v],[z,c,k,w]]

static infty(args)[source]

Return a fuel complex.

This function assigns infinite concentration to the complex, which is a placeholder until we have come to a more reasonable solution.

static irrev_reactions(args)[source]

Split reversible rxns into a pair of irreversible rxns.

long(args)[source]

Returns a long domain.

static remove_id_tags(l)[source]

Helper function to remove all tags from the given id_list.

short(args)[source]

Returns a short domain.

static tail(args)[source]

Returns the list minus the first element.

unique(args)[source]

A function that returns branch-migration domains.

class nuskell.dsdcompiler.interpreter.Reaction(reactants, products, reversible)[source]

A reversible or irreversible reaction.

Parameters:
  • reactands (List[str]) – a list of educts, eg. [‘A’, ‘B’]

  • products (List[str]) – a list of products, eg. [‘C’]

  • reversible (bool) – True or False

class nuskell.dsdcompiler.interpreter.Species(name)[source]

A species of a CRN.

Parameters:

name (str) – The name of a species.

class nuskell.dsdcompiler.interpreter.void[source]

An empty object returned by the print function.