pypath.inputs.uniprot.UniprotQuery§

class pypath.inputs.uniprot.UniprotQuery(*query, fields: str | Iterable[str] | None = None, **kwargs)[source]§

Bases: object

__init__(*query, fields: str | Iterable[str] | None = None, **kwargs)[source]§

Constructs a query for the UniProt REST API.

Parameters:
  • query – Query elements: can be a ready query or its components, bypassing the processing in this function or performing only simple concatenation. Alternatively, it can be a nested structure of lists and dicts describing more complex queries. See the examples below.

  • kwargs – Same as passing a dict to query.

Details:

The query can be built in several ways: - Simple string or concatenation of strings:

query_builder(‘kinase AND organism_id:9606’) query_builder(‘kinase’, ‘organism_id:9606’) query_builder(‘kinase’, organism_id = 9606) The above 3 examples all return the same query: kinase AND organism_id:9606

  • The default operator within lists is OR and within dicts is AND: query_builder(organism = [9606, 10090, 10116]) organism_id:9606 OR organism_id:10090 OR organism_id:10116 query_builder({‘organism_id’: 9606, ‘reviewed’: True}) organism_id:9606 AND reviewed:true

  • These default operators can be changed by including the op key in dicts or including the operator with an underscore in lists: query_builder({‘length’: (500,), ‘mass’: (50000,), ‘op’: ‘OR’}) length:[500 TO *] OR mass:[50000 TO *] query_builder(lit_author = [‘Huang’, ‘Kovac’, ‘_AND’]) lit_author:Huang AND lit_author:Kovac

  • The nested structures translate into nested parentheses in the query: query_builder({‘organism_id’: [9606, 10090], ‘reviewed’: True}) (organism_id:9606 OR organism_id:10090) AND reviewed:true

  • Values are converted to strings, intervals can be provided as tuples: query_builder({‘length’: (100, None), ‘organism_id’: 9606}) length:[100 TO *] AND organism_id:9606

For a complete reference of the available parameters, see https://www.uniprot.org/help/query-fields and https://www.uniprot.org/help/text-search for additional syntax elements.

For the available fields refer to the _FIELD_SYNONYMS attribute of this class or the UniProt website: https://www.uniprot.org/help/return_fields

__iter__()[source]§

Perform the query and iterate over the lines in the results, skipping the header and the empty lines, stripping the linebreaks and splitting by tab.

Yields:

A list of fields for each line.

fail_on_empty§

If set to True, an error will be raised if the UniProt API returns empty response. By default no error is raised.

name_process§

If set to True, a different processing will be applied on the results. This is appropriate especially for identifier type fields.

Methods

__init__(*query[, fields])

Constructs a query for the UniProt REST API.

perform()

Perform the query and preprocess the result.

Attributes

url

UniProt REST API URL (urlencoded).

url_plain

UniProt REST API URL (plain).

perform() list[str] | dict[str, str] | dict[str, dict[str, str]][source]§

Perform the query and preprocess the result.

Returns:

  • A list of UniProt IDs if no fields were provided.

  • A dict of UniProt IDs and corresponding field values if exactly one field was provided.

  • A dict with field names as top level keys and dicts of the kind described in the previous point as values.

property url: str§

UniProt REST API URL (urlencoded).

Returns:

A valid query suitable for the UniProt REST API.

property url_plain: str§

UniProt REST API URL (plain).