Example #1
0
def test_pysb_preassembler_replace_activities2():
    a_act = Agent('a', activity=ActivityCondition('activity', True))
    st = Activation(a_act, Agent('b'))
    st2 = Activation(Agent('c'), Agent('a'))
    ppa = PysbPreassembler([st, st2])
    ppa.replace_activities()
    assert(len(ppa.statements) == 2)
Example #2
0
def test_pysb_preassembler_replace_activities1():
    st1 = ActiveForm(Agent('a', location='nucleus'), 'activity', True)
    st2 = Phosphorylation(
        Agent('a', activity=ActivityCondition('activity', True)), Agent('b'))
    ppa = PysbPreassembler([st1, st2])
    ppa.replace_activities()
    assert (len(ppa.statements) == 2)
    assert (ppa.statements[1].enz.location == 'nucleus')
Example #3
0
def test_pysb_preassembler_replace_activities3():
    p = Agent('PPP2CA')
    bc = BoundCondition(p, False)
    erk = Agent('ERK')
    mek1 = Agent('MEK', mods=[ModCondition('phosphorylation',
                                           None, None, True)])
    mek2 = Agent('MEK', activity=ActivityCondition('activity', True),
                 bound_conditions=[bc])
    st2 = ActiveForm(mek1, 'activity', True)
    st1 = Phosphorylation(mek2, erk)
    ppa = PysbPreassembler([st1, st2])
    ppa.replace_activities()
    assert(len(ppa.statements) == 2)
    assert(ppa.statements[0].enz.mods)
    assert(ppa.statements[0].enz.bound_conditions)
Example #4
0
    def make_model(self):
        """Assemble the SBGN model from the collected INDRA Statements.

        This method assembles an SBGN model from the set of INDRA Statements.
        The assembled model is set as the assembler's sbgn attribute (it is
        represented as an XML ElementTree internally). The model is returned
        as a serialized XML string.

        Returns
        -------
        sbgn_str : str
            The XML serialized SBGN model.
        """
        ppa = PysbPreassembler(self.statements)
        ppa.replace_activities()
        self.statements = ppa.statements
        self.sbgn = emaker.sbgn()
        self._map = emaker.map()
        self.sbgn.append(self._map)
        for stmt in self.statements:
            if isinstance(stmt, Modification):
                self._assemble_modification(stmt)
            elif isinstance(stmt, RegulateActivity):
                self._assemble_regulateactivity(stmt)
            elif isinstance(stmt, RegulateAmount):
                self._assemble_regulateamount(stmt)
            elif isinstance(stmt, Complex):
                self._assemble_complex(stmt)
            elif isinstance(stmt, ActiveForm):
                #self._assemble_activeform(stmt)
                pass
            else:
                logger.warning("Unhandled Statement type %s" % type(stmt))
                continue
        sbgn_str = self.print_model()
        return sbgn_str
Example #5
0
    def make_model(self,
                   policies=None,
                   initial_conditions=True,
                   reverse_effects=False):
        """Assemble the Kami model from the collected INDRA Statements.

        This method assembles a Kami model from the set of INDRA Statements.
        The assembled model is both returned and set as the assembler's
        model argument.

        Parameters
        ----------
        policies : Optional[Union[str, dict]]
            A string or dictionary of policies, as defined in
            :py:class:`indra.assemblers.KamiAssembler`. This set of policies
            locally supersedes the default setting in the assembler. This
            is useful when this function is called multiple times with
            different policies.
        initial_conditions : Optional[bool]
            If True, default initial conditions are generated for the
            agents in the model.

        Returns
        -------
        model : dict
            The assembled Kami model.
        """
        ppa = PysbPreassembler(self.statements)
        ppa.replace_activities()
        if reverse_effects:
            ppa.add_reverse_effects()
        self.statements = ppa.statements
        # Set local policies for this make_model call that overwrite
        # the global policies of the Kami assembler
        if policies is not None:
            global_policies = self.policies
            if isinstance(policies, basestring):
                local_policies = {'other': policies}
            else:
                local_policies = {'other': 'default'}
                local_policies.update(policies)
            self.policies = local_policies

        self.model = {}
        graphs = []
        self.model['graphs'] = graphs
        self.model['typing'] = []

        # Action graph generated here
        action_graph = {
            'id': 'action_graph',
            'attrs': {
                'name': 'action_graph'
            }
        }
        action_graph['graph'] = {'nodes': [], 'edges': []}
        graphs.append(action_graph)

        # Iterate over the statements to generate rules
        self._assemble()
        # Add initial conditions
        #if initial_conditions:
        #    self.add_default_initial_conditions()

        # If local policies were applied, revert to the global one
        if policies is not None:
            self.policies = global_policies

        return self.model