booldog.io.circuit ================== .. py:module:: booldog.io.circuit .. autoapi-nested-parse:: Function to transform booldog:Network to DiGraph Attributes ---------- .. autoapisummary:: booldog.io.circuit.logger booldog.io.circuit.PAREN_RE Classes ------- .. autoapisummary:: booldog.io.circuit.BooleanOperators booldog.io.circuit.BooleanDiGraph Functions --------- .. autoapisummary:: booldog.io.circuit.clean_line booldog.io.circuit.booldog2circuit booldog.io.circuit.resolve_rule booldog.io.circuit.resolve_factor Module Contents --------------- .. py:data:: logger .. py:data:: PAREN_RE .. py:function:: clean_line(line) Makes sure line is a Boolean rule, and not a header or comment .. py:class:: BooleanOperators A simple class to define the Boolean operators as class attributes. This is used to make the code more readable and maintainable. .. py:attribute:: AND :value: '&' .. py:attribute:: OR :value: '|' .. py:attribute:: NOT :value: '!' .. py:class:: BooleanDiGraph Bases: :py:obj:`networkx.DiGraph` Simple helper class to track logic nodes .. py:attribute:: and_count :value: 0 .. py:attribute:: or_count :value: 0 .. py:attribute:: not_count :value: 0 .. py:method:: add_and() Add a AND node to the graph. .. py:method:: add_or() Add a OR node to the graph. .. py:method:: add_not() Add a NOT node to the graph. .. py:function:: booldog2circuit(model) Export a BoolDog Boolean model to Networkx DiGraph :param model: A BoolDog object representing a Boolean network. :type model: booldog:BoolDogModel :returns: **graph** -- A networkx.DiGraph with the same nodes as the input network. Boolean rules are represented as additional "logical" nodes (and, or, not) and edges. :rtype: BooleanDiGraph .. py:function:: resolve_rule(rule, processor) Parse a Boolean rule and replace it with "logical" nodes and edges in the graph. The rule can be nested with brackets, which are resolved first. :param rule: A Boolean rule (e.g. "A & B | C") :type rule: str :param processor: A function that takes a list of nodes and an operator, processes them as needed. The operator can be "AND", "OR", or "NOT". The function should return the new node representing the result of applying the operator to the nodes. :type processor: function :returns: **new_s** -- Replacement string (the final node) :rtype: str .. py:function:: resolve_factor(factor, processor) Parse a single factor of a Boolean rule. The factor can be a list of nodes connected by '&', '|', and '!' operators. The factor does not contain brackets. :param factor: A Boolean factor e.g. "A & B | C" :type factor: str :param processor: A function that takes a list of nodes and an operator, processes them as needed. The operator can be "AND", "OR", or "NOT". The function should return the new node representing the result of applying the operator to the nodes. :type processor: function :returns: **s** -- Replacement string (the final node representing this factor) :rtype: str