Stores and extracts items from a single annotation entry of the annotations dictionary.

Exists to support modularity and readibility within the Query class.

Attributes:
  • entry (dict[str, dict[str, dict[str, str] | str]]) –

    Annotations for a single entry in the database.

  • attribute (str) –

    Attribute to extract annotations for.

  • ecodes (list[str]) –

    Permitted evidence codes for annotations.

  • species (str) –

    Species for which to extract annotations for.

  • allowed_sources (set[str] | None) –

    Lowercase source names permitted by the license filter. None means all sources are allowed.

Examples:

>>> from metahq_core.query import UnParsedEntry
>>> entry = {
        'GSM281311': {
            'organism': 'homo sapiens',
            'tissue': {
                'ursa': {
                    'id': 'UBERON:0002113', 'value': 'kidney', 'ecode': 'expert-curated'
                }
            }
        }
    }
>>> UnParsedEntry(
        entry,
        attribute='tissue',
        ecodes=['expert-curated'],
        species='homo sapiens',
        allowed_sources=None,
    )

get_annotations()

Retrieves the ID and value annotations for a single entry.

Returns:
  • tuple[str, str, str]

    ID and value annotations for a given attribute. If there are multiple annotations across sources, then they are concatenated with a | delimiter. If no ID or value annotations exist, NA is returned.

Examples:

>>> from metahq_core.query import UnParsedEntry
>>> entry = {
        'GSM281311': {
            'organism': 'homo sapiens',
            'tissue': {
                'ursa': {
                    'id': 'UBERON:0002113', 'value': 'kidney', 'ecode': 'expert-curated'
                }
            }
        }
    }
>>> unparsed = UnParsedEntry(
        entry,
        attribute='tissue',
        ecodes=['expert-curated'],
        'homo sapiens'
    )
>>> unparsed.get_annotations()
('UBERON:0002113', 'kidney')

is_acceptable()

Checks if the entry is not empty and is an acceptable annotation given the passed attribute, ecode, and species.

Returns:
  • bool

    True or False given the specified attributes.

Examples:

>>> from metahq_core.query import UnParsedEntry
>>> entry = {
        'GSM281311': {
            'organism': 'homo sapiens',
            'tissue': {
                'ursa': {
                    'id': 'UBERON:0002113', 'value': 'kidney', 'ecode': 'expert-curated'
                }
            }
        }
    }
>>> unparsed = UnParsedEntry(
        entry,
        attribute='tissue',
        ecodes=['expert-curated'],
        'homo sapiens'
    )
>>> unparsed.is_acceptable()
True

If an attribute doesn't exist, it will return False.

>>> entry = {
        'GSM315993': {
            'organism': 'homo sapiens',
            'sex': {
                'Johnson 2023': {
                    'id': 'F', 'ecode': 'expert-curated'
                }
            }
        }
    }
>>> unparsed = UnParsedEntry(
        entry,
        attribute='tissue',
        ecodes=['expert-curated'],
        'homo sapiens'
    )
>>> unparsed.is_acceptable()
False

get_id_value(source_anno) staticmethod

Extracts the ID and value for an annotation.

Parameters:
  • source_anno (dict[str, str]) –

    Annotations from a single source. Has keys ['id', 'value', 'ecode'].

Returns:
  • tuple[str, str]

    Tuple of the ID and value for the attribute annotation from a single source.