Miscellaneous Client APIs (Mostly Deprecated)

There are some, generally archaic, client functions which use both readonly and principal resources. I make no guarantee that these will work.

Get Datasets (indra_db.client.datasets)

An early attempt at something very like the indra_db.client.readonly.interactions approach to getting superficial data out of the database.

indra_db.client.datasets.export_relation_dict_to_tsv(relation_dict, out_base, out_types=None)[source]

Export a relation dict (from get_relation_dict) to a tsv.

Available output types are:

  • “full_tsv” : get a tsv with directed pairs of entities (e.g. HGNC symbols), the type of relation (e.g. Phosphorylation) and the hash of the preassembled statement. Columns are agent_1, agent_2 (where agent_1 affects agent_2), type, hash.

  • “short_tsv” : like the above, but without the hashes, so only one instance of each pair and type trio occurs. However, the information cannot be traced. Columns are agent_1, agent_2, type, where agent_1 affects agent_2.

  • “pairs_tsv” : like the above, but without the relation type. Similarly, each row is unique. In addition, the agents are undirected. Thus this is purely a list of pairs of related entities. The columns are just agent_1 and agent_2, where nothing is implied by the ordering.

Parameters
  • relation_dict (dict) – This should be the output from get_relation_dict, or something equivalently constructed.

  • out_base (str) – The base-name for the output files.

  • out_types (list[str]) – A list of the types of tsv to output. See above for details.

indra_db.client.datasets.get_relation_dict(db, groundings=None, with_evidence_count=False, with_support_count=False)[source]

Get a dictionary of entity interactions from the database.

Use only metadata from the database to rapidly get simple interaction data. This is much faster than handling the full Statement jsons, while providing some basic valuable functionality.

Parameters
  • db (DatabaseManager instance) – An instance of a database manager.

  • groundings (list[str] or None) – Select which types of grounding namespaces to include, e.g. HGNC, or FPLX, or both. Only agent refs with these groundings will be selected. If None, only HGNC is used.

  • with_evidence_count (bool) – Default is False. If True, an additional query will be made for each statement to get the count of supporting evidence, which is a useful proxy for belief.

  • with_support_count (bool) – Default is False. Like with_evidence_count, except the number of supporting statements is counted.

indra_db.client.datasets.get_statement_essentials(clauses, count=1000, db=None, preassembled=True)[source]

Get the type, agents, and id data for the specified statements.

This function is useful for light-weight searches of basic mechanistic information, without the need to follow as many links in the database to populate the Statement objects.

To get full statements, use get_statements.

Parameters
  • clauses (list) – list of sqlalchemy WHERE clauses to pass to the filter query.

  • count (int) – Number of statements to retrieve and process in each batch.

  • db (DatabaseManager) – Optionally specify a database manager that attaches to something besides the primary database, for example a local database instance.

  • preassembled (bool) – If true, statements will be selected from the table of pre-assembled statements. Otherwise, they will be selected from the raw statements. Default is True.

Returns

(uuid, sid, hash, type, (agent_1, agent_2, …)).

Return type

A list of tuples containing

Get Statements (indra_db.client.statements)

The first round of tools written to get Statements out of the database, utilizing far too many queries and taking absurdly long to complete. Most of their functions have been outmoded, with the exception of getting PA Statements from the principal database, which (as of this writing) has yet to be implemented.

indra_db.client.statements.get_evidence(pa_stmt_list, db=None, fix_refs=True, use_views=True)[source]

Fill in the evidence for a list of pre-assembled statements.

Parameters
  • pa_stmt_list (list[Statement]) – A list of unique statements, generally drawn from the database pa_statement table (via get_statemetns).

  • db (DatabaseManager instance or None) – An instance of a database manager. If None, defaults to the “primary” database, as defined in the db_config.ini file in .config/indra.

  • fix_refs (bool) – The paper refs within the evidence objects are not populated in the database, and thus must be filled using the relations in the database. If True (default), the pmid field of each Statement Evidence object is set to the correct PMIDs, or None if no PMID is available. If False, the pmid field defaults to the value populated by the reading system.

Return type

None - modifications are made to the Statements “in-place”.

indra_db.client.statements.get_statements(clauses, count=1000, do_stmt_count=False, db=None, preassembled=True, with_support=False, fix_refs=True, with_evidence=True)[source]

Select statements according to a given set of clauses.

Parameters
  • clauses (list) – list of sqlalchemy WHERE clauses to pass to the filter query.

  • count (int) – Number of statements to retrieve and process in each batch.

  • do_stmt_count (bool) – Whether or not to perform an initial statement counting step to give more meaningful progress messages.

  • db (DatabaseManager) – Optionally specify a database manager that attaches to something besides the primary database, for example a local database instance.

  • preassembled (bool) – If true, statements will be selected from the table of pre-assembled statements. Otherwise, they will be selected from the raw statements. Default is True.

  • with_support (bool) – Choose whether to populate the supports and supported_by list attributes of the Statement objects. General results in slower queries.

  • with_evidence (bool) – Choose whether or not to populate the evidence list attribute of the Statements. As with with_support, setting this to True will take longer.

  • fix_refs (bool) – The paper refs within the evidence objects are not populated in the database, and thus must be filled using the relations in the database. If True (default), the pmid field of each Statement Evidence object is set to the correct PMIDs, or None if no PMID is available. If False, the pmid field defaults to the value populated by the reading system.

Return type

list of Statements from the database corresponding to the query.

indra_db.client.statements.get_statements_by_gene_role_type(agent_id=None, agent_ns='HGNC-SYMBOL', role=None, stmt_type=None, count=1000, db=None, do_stmt_count=False, preassembled=True, fix_refs=True, with_evidence=True, with_support=False, essentials_only=False)[source]

Get statements from the DB by stmt type, agent, and/or agent role.

WARNING: This function will be removed in the future. Please look to indra_db.client.readonly.query and indra_db.client.principal.raw_statements for alternatives.

Parameters
  • agent_id (str) – String representing the identifier of the agent from the given namespace. Note: if the agent namespace argument, agent_ns, is set to ‘HGNC-SYMBOL’, this function will treat agent_id as an HGNC gene symbol and perform an internal lookup of the corresponding HGNC ID. Default is ‘HGNC-SYMBOL’.

  • agent_ns (str) – Namespace for the identifier given in agent_id.

  • role (str) – String corresponding to the role of the agent in the statement. Options are ‘SUBJECT’, ‘OBJECT’, or ‘OTHER’ (in the case of Complex, SelfModification, and ActiveForm Statements).

  • stmt_type (str) – Name of the Statement class.

  • count (int (DEPRECATED)) – Number of statements to retrieve in each batch (passed to get_statements()).

  • db (DatabaseManager) – Optionally specify a database manager that attaches to something besides the primary database, for example a local databse instance.

  • do_stmt_count (bool (DEPRECATED)) – Whether or not to perform an initial statement counting step to give more meaningful progress messages.

  • preassembled (bool (DEPRECATED)) – If true, statements will be selected from the table of pre-assembled statements. Otherwise, they will be selected from the raw statements. Default is True.

  • with_support (bool (DEPRECATED)) – Choose whether to populate the supports and supported_by list attributes of the Statement objects. Generally results in slower queries. DEFAULT IS CURRENTLY False.

  • with_evidence (bool) – Choose whether or not to populate the evidence list attribute of the Statements. As with with_support, setting this to True will take longer.

  • fix_refs (bool (DEPRECATED)) – The paper refs within the evidence objects are not populated in the database, and thus must be filled using the relations in the database. If True (default), the pmid field of each Statement Evidence object is set to the correct PMIDs, or None if no PMID is available. If False, the pmid field defaults to the value populated by the reading system.

  • essentials_only (bool (DEPRECATED)) – Default is False. If True, retrieve only some metadata regarding the statements. Implicitly with_support, with_evidence, fix_refs, and do_stmt_count are all False, as none of the relevant features apply.

Returns

  • if essentials_only is False – list of Statements from the database corresponding to the query.

  • else – list of tuples containing basic data from the statements.

indra_db.client.statements.get_statements_by_paper(id_list, id_type='pmid', db=None, preassembled=True)[source]

Get the statements from a list of paper ids.

WARNING: This function will be removed in the future. Please look to indra_db.client.readonly.query and indra_db.client.principal.raw_statements for alternatives.

Parameters
  • id_list (list or set) – A list of ints or strs that are ids of papers of type id_type.

  • id_type (str) – The type of id used (default is pmid). Options include pmid, pmcid, doi, pii, url, or manuscript_id. Note that pmid is generally the best means of getting a paper.

  • db (DatabaseManager) – Optionally specify a database manager that attaches to something besides the primary database, for example a local databse instance.

  • preassembled (bool) – If True, statements will be selected from the table of pre-assembled statements. Otherwise, they will be selected from the raw statements. Default is True.

Returns

stmt_dict – A dict of Statements from the database keyed the paper id given. Papers that yielded no statements are not included. If preassembled is True, there may be ids which were not present in the original dataset, and there may be a key None for statements that has evidence from refs that did not have that id_type of reference.

Return type

dict

indra_db.client.statements.get_statements_from_hashes(statement_hashes, preassembled=True, db=None, **kwargs)[source]

Retrieve statement objects given only statement hashes.

WARNING: This function will be removed in the future. Please look to indra_db.client.readonly.query and indra_db.client.principal.raw_statements for alternatives.

indra_db.client.statements.get_support(statements, db=None, recursive=False)[source]

Populate the supports and supported_by lists of the given statements.