How to use indra - 10 common examples

To help you get started, we’ve selected a few indra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gcallah / indras_net / models / el_farol.py View on Github external
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props)

    drinkers = Composite(DRINKERS, {"color": RED},
                         member_creator=create_drinker,
                         num_members=get_prop('population',
                                              DEF_POPULATION) // 2)

    non_drinkers = Composite(NON_DRINKERS, {"color": BLUE},
                             member_creator=create_non_drinker,
                             num_members=get_prop('population',
                                                  DEF_POPULATION) // 2)
    bar = Env(MODEL_NAME,
              height=get_prop('grid_height', DEF_HEIGHT),
              width=get_prop('grid_width', DEF_WIDTH),
              members=[drinkers, non_drinkers],
              pop_hist_setup=setup_attendance)
    population = len(drinkers) + len(non_drinkers)
    bar.set_attr("population", population)
    bar.set_attr(OPT_OCCUPANCY, int(population * DEF_MOTIV))
github gcallah / indras_net / models / el_farol.py View on Github external
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props)

    drinkers = Composite(DRINKERS, {"color": RED},
                         member_creator=create_drinker,
                         num_members=get_prop('population',
                                              DEF_POPULATION) // 2)

    non_drinkers = Composite(NON_DRINKERS, {"color": BLUE},
                             member_creator=create_non_drinker,
                             num_members=get_prop('population',
                                                  DEF_POPULATION) // 2)
    bar = Env(MODEL_NAME,
              height=get_prop('grid_height', DEF_HEIGHT),
              width=get_prop('grid_width', DEF_WIDTH),
              members=[drinkers, non_drinkers],
              pop_hist_setup=setup_attendance)
    population = len(drinkers) + len(non_drinkers)
    bar.set_attr("population", population)
    bar.set_attr(OPT_OCCUPANCY, int(population * DEF_MOTIV))
    bar.set_attr(AGENTS_DECIDED, 0)
    bar.set_attr(ATTENDANCE, 0)
    set_env_attrs()
github gcallah / indras_net / models / el_farol.py View on Github external
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props)

    drinkers = Composite(DRINKERS, {"color": RED},
                         member_creator=create_drinker,
                         num_members=get_prop('population',
                                              DEF_POPULATION) // 2)

    non_drinkers = Composite(NON_DRINKERS, {"color": BLUE},
                             member_creator=create_non_drinker,
                             num_members=get_prop('population',
                                                  DEF_POPULATION) // 2)
    bar = Env(MODEL_NAME,
              height=get_prop('grid_height', DEF_HEIGHT),
              width=get_prop('grid_width', DEF_WIDTH),
              members=[drinkers, non_drinkers],
              pop_hist_setup=setup_attendance)
    population = len(drinkers) + len(non_drinkers)
    bar.set_attr("population", population)
    bar.set_attr(OPT_OCCUPANCY, int(population * DEF_MOTIV))
    bar.set_attr(AGENTS_DECIDED, 0)
    bar.set_attr(ATTENDANCE, 0)
    set_env_attrs()
github gcallah / indras_net / models / el_farol.py View on Github external
def set_up(props=None):
    """
    A func to set up run that can also be used by test code.
    """
    init_props(MODEL_NAME, props)

    drinkers = Composite(DRINKERS, {"color": RED},
                         member_creator=create_drinker,
                         num_members=get_prop('population',
                                              DEF_POPULATION) // 2)

    non_drinkers = Composite(NON_DRINKERS, {"color": BLUE},
                             member_creator=create_non_drinker,
                             num_members=get_prop('population',
                                                  DEF_POPULATION) // 2)
    bar = Env(MODEL_NAME,
              height=get_prop('grid_height', DEF_HEIGHT),
              width=get_prop('grid_width', DEF_WIDTH),
              members=[drinkers, non_drinkers],
              pop_hist_setup=setup_attendance)
    population = len(drinkers) + len(non_drinkers)
github indralab / emmaa / emmaa / model_tests.py View on Github external
if merge:
            groups = group_and_sort_statements(stmts)
            for group in groups:
                group_stmts = group[-1]
                stmt_type = group[0][-1]
                agent_names = group[0][1]
                if len(agent_names) < 2:
                    continue
                if stmt_type == 'Influence':
                    stmt = get_class_from_name(stmt_type, Statement)(
                        Event(Concept(agent_names[0])),
                        Event(Concept(agent_names[1])))
                elif stmt_type == 'Conversion':
                    stmt = get_class_from_name(stmt_type, Statement)(
                        Agent(agent_names[0]),
                        [Agent(ag) for ag in agent_names[1]],
                        [Agent(ag) for ag in agent_names[2]])
                else:
                    try:
                        stmt = get_class_from_name(stmt_type, Statement)(
                            Agent(agent_names[0]), Agent(agent_names[1]))
                    except ValueError:
                        stmt = get_class_from_name(stmt_type, Statement)(
                            [Agent(ag_name) for ag_name in agent_names])
                ea = EnglishAssembler([stmt])
                sentence = ea.make_model()
                stmt_hashes = [gr_st.get_hash() for gr_st in group_stmts]
                url_param = parse.urlencode(
                    {'stmt_hash': stmt_hashes, 'source': 'model_statement',
                     'model': self.model.name}, doseq=True)
                link = f'/evidence?{url_param}'
                sentences.append((link, sentence, ''))
github sorgerlab / indra / indra / sources / virhostnet / processor.py View on Github external
db_ns, db_id = grounding.split(':')
    # Assume UniProt or RefSeq IDs
    assert db_ns in {'uniprotkb', 'refseq', 'ddbj/embl/genbank'}, db_ns
    if db_ns == 'uniprotkb':
        if '-' in db_id:
            up_id, feat_id = db_id.split('-')
            # Assume it's a feature ID
            assert feat_id.startswith('PRO'), feat_id
            db_refs = {'UP': up_id, 'UPPRO': feat_id}
        else:
            db_refs = {'UP': db_id}
    elif db_ns == 'refseq':
        db_refs = {'REFSEQ_PROT': db_id}
    else:
        db_refs = {'GENBANK': db_id}
    agent = Agent(db_id, db_refs=db_refs)
    standardized = standardize_agent_name(agent)
    if up_web_fallback:
        # Handle special case of unreviewed UP entries
        if not standardized and 'UP' in db_refs:
            name = uniprot_client.get_gene_name(db_refs['UP'],
                                                web_fallback=True)
            if name:
                agent.name = name
    return agent
github sorgerlab / indra / models / phase3_eval / read_phosphosite.py View on Github external
position = None

        ps = row['phosphosite']
        kin_upid = row['KIN_ID']
        if not pandas.isnull(kin_upid):
            if kin_upid.find('-') != -1:
                kin_upid = kin_upid.split('-')[0]
            if not uniprot_client.is_human(kin_upid):
                continue
            kin_hgnc_symbol = uniprot_client.get_gene_name(kin_upid)
            kin_hgnc = hgnc_client.get_hgnc_id(kin_hgnc_symbol)
        else:
            kin_hgnc_symbol = row['KINASE_GENE_SYMBOL']
            if pandas.isnull(kin_hgnc_symbol):
                continue
            kin_hgnc_id = hgnc_client.get_hgnc_id(kin_hgnc_symbol)
            kin_upid = hgnc_client.get_uniprot_id(kin_hgnc_id)
            if kin_upid is None:
                continue
        kin = Agent(kin_hgnc_symbol,
                    db_refs={'UP': kin_upid, 'HGNC': kin_hgnc})

        ev = Evidence(source_api='phosphosite')
        st = Phosphorylation(kin, sub, residue, position, evidence = [ev])
        statements.append(st)
    return statements
github sorgerlab / indra / indra / benchmarks / phosphorylations / __init__.py View on Github external
def get_kinase_activities():
    kinase_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               '../../resources/kinases.tsv')
    kinases = []
    with open(kinase_file, 'rt') as fh:
        lines = [l.strip() for l in fh.readlines()]
        for lin in lines[1:]:
            up_id, hgnc_name, _, _ = lin.split('\t')
            hgnc_id = hgnc_client.get_hgnc_id(hgnc_name)
            agent = Agent(hgnc_name, db_refs={'UP': up_id, 'HGNC': hgnc_id})
            kinases.append(agent)
    kin_activities = []
    from indra.statements import HasActivity
    for kin in kinases:
        stmt = HasActivity(kin, 'kinase', True)
        kin_activities.append(stmt)
    return kin_activities
github sorgerlab / indra / models / phase3_eval / read_phosphosite.py View on Github external
db_refs={'UP': sub_upid,'HGNC': sub_hgnc})
        residue = row['Actual_site'][0]
        if len(row['Actual_site']) > 1:
            position = row['Actual_site'][1:]
        else:
            position = None

        ps = row['phosphosite']
        kin_upid = row['KIN_ID']
        if not pandas.isnull(kin_upid):
            if kin_upid.find('-') != -1:
                kin_upid = kin_upid.split('-')[0]
            if not uniprot_client.is_human(kin_upid):
                continue
            kin_hgnc_symbol = uniprot_client.get_gene_name(kin_upid)
            kin_hgnc = hgnc_client.get_hgnc_id(kin_hgnc_symbol)
        else:
            kin_hgnc_symbol = row['KINASE_GENE_SYMBOL']
            if pandas.isnull(kin_hgnc_symbol):
                continue
            kin_hgnc_id = hgnc_client.get_hgnc_id(kin_hgnc_symbol)
            kin_upid = hgnc_client.get_uniprot_id(kin_hgnc_id)
            if kin_upid is None:
                continue
        kin = Agent(kin_hgnc_symbol,
                    db_refs={'UP': kin_upid, 'HGNC': kin_hgnc})

        ev = Evidence(source_api='phosphosite')
        st = Phosphorylation(kin, sub, residue, position, evidence = [ev])
        statements.append(st)
    return statements
github sorgerlab / indra / indra / databases / uniprot_client.py View on Github external
def _build_uniprot_entries():
    up_entries_file = os.path.dirname(os.path.abspath(__file__)) + \
        '/../resources/uniprot_entries.tsv'
    uniprot_gene_name = {}
    uniprot_mnemonic = {}
    uniprot_mnemonic_reverse = {}
    uniprot_mgi = {}
    uniprot_rgd = {}
    uniprot_mgi_reverse = {}
    uniprot_rgd_reverse = {}
    try:
        csv_rows = read_unicode_csv(up_entries_file, delimiter='\t')
        # Skip the header row
        next(csv_rows)
        for row in csv_rows:
            up_id, gene_name, up_mnemonic, rgd, mgi = row
            uniprot_gene_name[up_id] = gene_name
            uniprot_mnemonic[up_id] = up_mnemonic
            uniprot_mnemonic_reverse[up_mnemonic] = up_id
            if mgi:
                mgi_ids = mgi.split(';')
                if mgi_ids:
                    uniprot_mgi[up_id] = mgi_ids[0]
                    uniprot_mgi_reverse[mgi_ids[0]] = up_id
            if rgd:
                rgd_ids = rgd.split(';')
                if rgd_ids:
                    uniprot_rgd[up_id] = rgd_ids[0]