gene.query#
Provides methods for handling queries.
- exception gene.query.InvalidParameterException[source]#
Exception for invalid parameter args provided by the user.
- class gene.query.QueryHandler(database)[source]#
Class for normalizer management. Stores reference to database instance and normalizes query input.
- __init__(database)[source]#
Initialize QueryHandler instance. Requires a created database object to initialize. The most straightforward way to do this is via the
create_db
method in thegene.database
module:>>> from gene.query import QueryHandler >>> from gene.database import create_db >>> q = QueryHandler(create_db())
We’ll generally call
create_db
without any arguments in code examples, for the sake of brevity. See the usage page in the docs and thecreate_db
API description for more details.- Parameters:
database (
AbstractDatabase
) – storage backend to search against
- normalize(query)[source]#
Return normalized concept for query.
Use to retrieve normalized gene concept records:
>>> from gene.query import QueryHandler >>> from gene.database import create_db >>> q = QueryHandler(create_db()) >>> result = q.normalize("BRAF") >>> result.normalized_id 'hgnc:1097' >>> result.aliases ['BRAF1', 'RAFB1', 'B-raf', 'NS7', 'B-RAF1']
- Parameters:
query (
str
) – String to find normalized concept for- Return type:
- Returns:
Normalized gene concept
- normalize_unmerged(query)[source]#
Return all source records under the normalized concept for the provided query string.
>>> from gene.query import QueryHandler >>> from gene.database import create_db >>> from gene.schemas import SourceName >>> q = QueryHandler(create_db()) >>> response = q.normalize_unmerged("BRAF") >>> response.match_type <MatchType.CONCEPT_ID: 100> >>> response.source_matches[SourceName.ENSEMBL].concept_id 'ensembl:ENSG00000157764'
- Parameters:
query (
str
) – string to search against- Return type:
- Returns:
Normalized response object
- search(query_str, incl='', excl='', **params)[source]#
Return highest match for each source.
>>> from gene.query import QueryHandler >>> from gene.database import create_db >>> q = QueryHandler(create_db()) >>> result = q.search("BRAF") >>> result.source_matches[0].records[0].concept_id 'ncbigene:673'
- Parameters:
query_str (
str
) – query, a string, to search forincl (
str
) – str containing comma-separated names of sources to use. Will exclude all other sources. Case-insensitive.excl (
str
) – str containing comma-separated names of source to exclude. Will include all other source. Case-insensitive.
- Return type:
- Returns:
SearchService class containing all matches found in sources.
- Raises:
InvalidParameterException – if both incl and excl args are provided, or if invalid source names are given