Skip to content

ValidationResult

A helper class to store the results of validation

Parameters:

Name Type Description Default
phenopacket_id str

Identifier of the phenopacket being validated

required
message str

description of the error/warning

required
errorlevel ErrorLevel

whether this result is an error or a warning

required
category Category

type of QcError

required
term HpTerm

HpTerm that caused the error

None
Source code in pyphetools/validation/validation_result.py
class ValidationResult:
    """
    A helper class to store the results of validation
    :param phenopacket_id: Identifier of the phenopacket being validated
    :type phenopacket_id: str
    :param message: description of the error/warning
    :type message: str
    :param errorlevel: whether this result is an error or a warning
    :type errorlevel: ErrorLevel
    :param category: type of QcError
    :type category: Category
    :param term: HpTerm that caused the error
    :type term: HpTerm

    """
    def __init__(self, phenopacket_id:str, message:str, errorlevel:ErrorLevel, category:Category, term:HpTerm=None):
        self._phenopacket_id = phenopacket_id
        self._message = message
        self._error_level = errorlevel
        self._category = category
        self._term = term

    @property
    def id(self):
        return self._phenopacket_id

    @property
    def message(self) -> str:
        """
        :returns: description of the cause of ValidationResult
        :rtype: str
        """
        return self._message

    @property
    def error_level(self)-> str:
        """
        :returns: the name of the ErrorLevel this ValidationResult is about
        :rtype: str
        """
        return self._error_level.name

    @property
    def term(self) -> Optional[HpTerm]:
        """
        :returns: A string representation of the HPO term this ValidationResult is about, if applicable, or empty string
        :rtype: Optional[str]
        """
        return self._term

    @property
    def category(self) -> str:
        """
        :returns: the name of the Category this ValidationResult is about
        :rtype: str
        """
        return self._category.name

    def is_error(self) -> bool:
        return self._error_level == ErrorLevel.ERROR

    def is_warning(self) -> bool:
        return self._error_level == ErrorLevel.WARNING

    def is_unfixable_error(self) -> bool:
        """Some errors cannot be fixed automatically and require manual attention.

        :returns: True iff this ValidationResult cannot be fixed automatically.
        :rtype: bool
        """
        return self._category in {Category.INSUFFICIENT_HPOS,
                                Category.INCORRECT_ALLELE_COUNT,
                                Category.INCORRECT_VARIANT_COUNT,
                                Category.MALFORMED_ID,
                                Category.MALFORMED_LABEL,
                                Category.OBSERVED_AND_EXCLUDED
                                }

    def get_items_as_array(self) -> List[str]:
        """
        :returns: A list of items (strings) intended for display
        :rtype: List[str]
        """
        if self._term is None:
            term = ""
        elif isinstance(self._term, HpTerm):
            term = self._term.hpo_term_and_id
        else:
            term = f"{self._term.name} ({self._term.identifier.value})"
        return [self.id, self.error_level, self.category, self.message, term]

    def __repr__(self):
        return f"{self._error_level}: {self._message}"


    @staticmethod
    def get_header_fields():
        return ["ID", "Level", "Category", "Message", "HPO Term"]

category: str property

Returns:

Type Description
str

the name of the Category this ValidationResult is about

error_level: str property

Returns:

Type Description
str

the name of the ErrorLevel this ValidationResult is about

message: str property

Returns:

Type Description
str

description of the cause of ValidationResult

term: Optional[HpTerm] property

Returns:

Type Description
Optional[str]

A string representation of the HPO term this ValidationResult is about, if applicable, or empty string

get_items_as_array()

Returns:

Type Description
List[str]

A list of items (strings) intended for display

Source code in pyphetools/validation/validation_result.py
def get_items_as_array(self) -> List[str]:
    """
    :returns: A list of items (strings) intended for display
    :rtype: List[str]
    """
    if self._term is None:
        term = ""
    elif isinstance(self._term, HpTerm):
        term = self._term.hpo_term_and_id
    else:
        term = f"{self._term.name} ({self._term.identifier.value})"
    return [self.id, self.error_level, self.category, self.message, term]

is_unfixable_error()

Some errors cannot be fixed automatically and require manual attention.

Returns:

Type Description
bool

True iff this ValidationResult cannot be fixed automatically.

Source code in pyphetools/validation/validation_result.py
def is_unfixable_error(self) -> bool:
    """Some errors cannot be fixed automatically and require manual attention.

    :returns: True iff this ValidationResult cannot be fixed automatically.
    :rtype: bool
    """
    return self._category in {Category.INSUFFICIENT_HPOS,
                            Category.INCORRECT_ALLELE_COUNT,
                            Category.INCORRECT_VARIANT_COUNT,
                            Category.MALFORMED_ID,
                            Category.MALFORMED_LABEL,
                            Category.OBSERVED_AND_EXCLUDED
                            }