Ejemplo n.º 1
0
def test_name_standardize():
    n = pa._n('.*/- ^&#@$')
    assert isinstance(n, str)
    assert n == '__________'
    n = pa._n('14-3-3')
    assert isinstance(n, str)
    assert n == 'p14_3_3'
    n = pa._n('\U0001F4A9bar')
    assert isinstance(n, str)
    assert n == 'bar'
def test_name_standardize():
    n = pa._n('.*/- ^&#@$')
    assert isinstance(n, str)
    assert n == '__________'
    n = pa._n('14-3-3')
    assert isinstance(n, str)
    assert n == 'p14_3_3'
    n = pa._n('\U0001F4A9bar')
    assert isinstance(n, str)
    assert n == 'bar'
Ejemplo n.º 3
0
def apply_condition(model, condition):
    agent = condition.quantity.entity
    try:
        monomer = model.monomers[pa._n(agent.name)]
    except KeyError:
        raise MissingMonomerError('%s is not in the model ' % agent.name,
                                  agent)
    site_pattern = pa.get_site_pattern(agent)
    # TODO: handle modified patterns
    if site_pattern:
        logger.warning('Cannot handle initial conditions on' +
                       ' modified monomers.')
    if condition.condition_type == 'exact':
        ic_name = monomer.name + '_0'
        if condition.value.quant_type == 'number':
            pa.set_base_initial_condition(model, monomer,
                                          condition.value.value)
        else:
            logger.warning('Cannot handle non-number initial conditions')
    elif condition.condition_type == 'multiple':
        # TODO: refer to annotations for the IC name
        ic_name = monomer.name + '_0'
        model.parameters[ic_name].value *= condition.value
    elif condition.condition_type == 'decrease':
        ic_name = monomer.name + '_0'
        model.parameters[ic_name].value *= 0.9
    elif condition.condition_type == 'increase':
        ic_name = monomer.name + '_0'
        model.parameters[ic_name].value *= 1.1
    logger.info('New initial condition: %s' % model.parameters[ic_name])
Ejemplo n.º 4
0
def apply_condition(model, condition):
    agent = condition.quantity.entity
    try:
        monomer = model.monomers[pa._n(agent.name)]
    except KeyError:
        raise MissingMonomerError('%s is not in the model ' % agent.name)
    site_pattern = pa.get_site_pattern(agent)
    # TODO: handle modified patterns
    if site_pattern:
        logger.warning('Cannot handle initial conditions on' +
                       ' modified monomers.')
    if condition.condition_type == 'exact':
        ic_name = monomer.name + '_0'
        if condition.value.quant_type == 'number':
            pa.set_base_initial_condition(model, monomer,
                                          condition.value.value)
        else:
            logger.warning('Cannot handle non-number initial conditions')
    elif condition.condition_type == 'multiple':
        # TODO: refer to annotations for the IC name
        ic_name = monomer.name + '_0'
        model.parameters[ic_name].value *= condition.value
    elif condition.condition_type == 'decrease':
        ic_name = monomer.name + '_0'
        model.parameters[ic_name].value *= 0.9
    elif condition.condition_type == 'increase':
        ic_name = monomer.name + '_0'
        model.parameters[ic_name].value *= 1.1
    logger.info('New initial condition: %s' % model.parameters[ic_name])
Ejemplo n.º 5
0
def get_chemical_agents(stmts):
    chemicals = set()
    for stmt in stmts:
        for agent in stmt.agent_list():
            if agent is not None and ('CHEBI' in agent.db_refs or
                                      'PUBCHEM' in agent.db_refs):
                chemicals.add(pysb_assembler._n(agent.name))
    return list(chemicals)
Ejemplo n.º 6
0
def get_chemical_agents(stmts):
    chemicals = set()
    for stmt in stmts:
        for agent in stmt.agent_list():
            if agent is not None and ('CHEBI' in agent.db_refs or
                                      'PC' in agent.db_refs):
                chemicals.add(pysb_assembler._n(agent.name))
    return list(chemicals)
Ejemplo n.º 7
0
def get_create_observable(model, agent):
    site_pattern = pa.get_site_pattern(agent)
    obs_name = pa.get_agent_rule_str(agent) + '_obs'
    try:
        monomer = model.monomers[pa._n(agent.name)]
    except KeyError:
        raise MissingMonomerError('%s is not in the model ' % agent.name)
    try:
        monomer_state = monomer(site_pattern)
    except Exception as e:
        msg = 'Site pattern %s invalid for monomer %s' % \
            (site_pattern, monomer.name)
        raise MissingMonomerSiteError(msg)
    obs = Observable(obs_name, monomer(site_pattern))
    model.add_component(obs)
    return obs
Ejemplo n.º 8
0
    def set_style(self, label, border_color, fill_color):
        """Colorizes all nodes with the specified label with the specified
        border and fill color.

        Parameters
        ----------
        label : str
            Add a style to nodes with this label
        border_color : str
            The border color, starting with # and followed by six hex digits
        fill_color : str
            The fill color, starting with # and followed by six hex digits
        """
        label = _n(label)
        assert(border_color.startswith('#'))
        assert(fill_color.startswith('#'))
        labels = self.label_to_glyph_ids.keys()
        if label in labels:
            self.label_to_style[label] = Style(border_color, fill_color)
Ejemplo n.º 9
0
def get_create_observable(model, agent):
    site_pattern = pa.get_site_pattern(agent)
    obs_name = pa.get_agent_rule_str(agent) + '_obs'
    try:
        monomer = model.monomers[pa._n(agent.name)]
    except KeyError:
        raise MissingMonomerError('%s is not in the model ' % agent.name,
                                  agent)
    try:
        monomer_state = monomer(site_pattern)
    except Exception as e:
        msg = 'Site pattern %s invalid for monomer %s' % \
            (site_pattern, monomer.name)
        raise MissingMonomerSiteError(msg)
    obs = Observable(obs_name, monomer(site_pattern))
    try:
        model.add_component(obs)
    except ComponentDuplicateNameError as e:
        pass
    return obs
Ejemplo n.º 10
0
    def set_style_expression_mutation(self, model, cell_line='A375_SKIN'):
        """Sets the fill color of each node based on its expression level
        on the given cell line, and the stroke color based on whether it is
        a mutation.

        Parameters
        ----------
        model: list<indra.statements.Statement>
            A list of INDRA statements
        cell_line: str
            A cell line for which we're interested in protein expression level
        """
        labels = self.label_to_glyph_ids.keys()

        label_to_agent = {}
        for label in labels:
            for statement in model:
                for agent in statement.agent_list():
                    if agent is not None and _n(agent.name) == label:
                        label_to_agent[label] = agent

        agent_to_expression_level = {}
        for agent in label_to_agent.values():
            if 'HGNC' not in agent.db_refs and 'FPLX' not in agent.db_refs:
                # This is not a gene
                agent_to_expression_level[agent] = 0
                continue

            if 'FPLX' not in agent.db_refs:
                gene_names = [agent.name]
            else:
                children = bio_ontology.get_children('FPLX',
                                                     agent.db_refs['FPLX'])
                gene_names = [bio_ontology.get_name(*child) for child
                              in children]

            # Compute mean expression level
            expression_levels = []
            logger.info('Getting expression status of proteins: %s' %
                        str(gene_names))
            l = self.get_expression(gene_names, cell_line)
            for line in l:
                for element in l[line]:
                    level = l[line][element]
                    if level is not None:
                        expression_levels.append(l[line][element])
            if len(expression_levels) == 0:
                mean_level = None
            else:
                mean_level = sum(expression_levels) / len(expression_levels)

            agent_to_expression_level[agent] = mean_level

        # Create a normalized expression score between 0 and 1
        # Compute min and maximum levels
        min_level = None
        max_level = None
        for agent, level in agent_to_expression_level.items():
            if level is None:
                continue
            if min_level is None:
                min_level = level
            if max_level is None:
                max_level = level
            if level < min_level:
                min_level = level
            if level > max_level:
                max_level = level
        # Compute scores
        agent_to_score = {}
        if max_level is not None:
            level_span = max_level - min_level
        for agent, level in agent_to_expression_level.items():
            if level is None or level_span == 0:
                agent_to_score[agent] = 0
            else:
                agent_to_score[agent] = (level - min_level) / level_span

        # Map scores to colors and assign colors to labels
        agent_to_color = {}
        for agent, score in agent_to_score.items():
            if 'HGNC' not in agent.db_refs and 'FPLX' not in agent.db_refs:
                color = cm.Blues(0.3)
                color_str = colors.to_hex(color[:3])
            else:
                # color = cm.plasma(score)
                color = cm.Greens(0.6*score + 0.2)
                color_str = colors.to_hex(color[:3])
            assert(len(color_str) == 7)
            stroke_color = \
                    self._choose_stroke_color_from_mutation_status(agent.name,
                                                                   cell_line)
            self.set_style(agent.name, stroke_color, color_str)