Skip to content

Post processing

PhEvalDiseaseResult dataclass

Bases: PhEvalResult

Minimal data required from tool-specific output for disease prioritisation

Parameters:

Name Type Description Default
disease_name str

Disease name for the result entry

required
disease_identifier str

Identifier for the disease result entry in the OMIM namespace

required
score str

Score for the disease result entry

required
Notes

While we recommend providing the disease identifier in the OMIM namespace, any matching format used in Phenopacket interpretations is acceptable for result matching purposes in the analysis.

Source code in src/pheval/post_processing/post_processing.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@dataclass
class PhEvalDiseaseResult(PhEvalResult):
    """Minimal data required from tool-specific output for disease prioritisation
    Args:
        disease_name (str): Disease name for the result entry
        disease_identifier (str): Identifier for the disease result entry in the OMIM namespace
        score (str): Score for the disease result entry
    Notes:
        While we recommend providing the disease identifier in the OMIM namespace,
        any matching format used in Phenopacket interpretations is acceptable for result matching purposes
        in the analysis.
    """

    disease_name: str
    disease_identifier: str
    score: float

PhEvalGeneResult dataclass

Bases: PhEvalResult

Minimal data required from tool-specific output for gene prioritisation result

Parameters:

Name Type Description Default
gene_symbol str

The gene symbol for the result entry

required
gene_identifier str

The ENSEMBL gene identifier for the result entry

required
score float

The score for the gene result entry

required
Notes

While we recommend providing the gene identifier in the ENSEMBL namespace, any matching format used in Phenopacket interpretations is acceptable for result matching purposes in the analysis.

Source code in src/pheval/post_processing/post_processing.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@dataclass
class PhEvalGeneResult(PhEvalResult):
    """Minimal data required from tool-specific output for gene prioritisation result
    Args:
        gene_symbol (str): The gene symbol for the result entry
        gene_identifier (str): The ENSEMBL gene identifier for the result entry
        score (float): The score for the gene result entry
    Notes:
        While we recommend providing the gene identifier in the ENSEMBL namespace,
        any matching format used in Phenopacket interpretations is acceptable for result matching purposes
        in the analysis.
    """

    gene_symbol: str
    gene_identifier: str
    score: float

PhEvalResult dataclass

Base class for PhEval results.

Source code in src/pheval/post_processing/post_processing.py
24
25
26
@dataclass
class PhEvalResult:
    """Base class for PhEval results."""

PhEvalVariantResult dataclass

Bases: PhEvalResult

Minimal data required from tool-specific output for variant prioritisation

Parameters:

Name Type Description Default
chromosome str

The chromosome position of the variant recommended to be provided in the following format.

required
start int

The start position of the variant

required
end int

The end position of the variant

required
ref str

The reference allele of the variant

required
alt str

The alternate allele of the variant

required
score float

The score for the variant result entry

required
Notes

While we recommend providing the variant's chromosome in the specified format, any matching format used in Phenopacket interpretations is acceptable for result matching purposes in the analysis.

Source code in src/pheval/post_processing/post_processing.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@dataclass
class PhEvalVariantResult(PhEvalResult):
    """Minimal data required from tool-specific output for variant prioritisation
    Args:
        chromosome (str): The chromosome position of the variant recommended to be provided in the following format.
        This includes numerical designations from 1 to 22 representing autosomal chromosomes,
        as well as the sex chromosomes X and Y, and the mitochondrial chromosome MT.
        start (int): The start position of the variant
        end (int): The end position of the variant
        ref (str): The reference allele of the variant
        alt (str): The alternate allele of the variant
        score (float): The score for the variant result entry
    Notes:
        While we recommend providing the variant's chromosome in the specified format,
        any matching format used in Phenopacket interpretations is acceptable for result matching purposes
        in the analysis.
    """

    chromosome: str
    start: int
    end: int
    ref: str
    alt: str
    score: float

RankedPhEvalDiseaseResult dataclass

Bases: PhEvalDiseaseResult

PhEval disease result with corresponding rank

Parameters:

Name Type Description Default
rank int

The rank for the result entry

required
Source code in src/pheval/post_processing/post_processing.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
@dataclass
class RankedPhEvalDiseaseResult(PhEvalDiseaseResult):
    """PhEval disease result with corresponding rank
    Args:
        rank (int): The rank for the result entry
    """

    rank: int

    @staticmethod
    def from_disease_result(pheval_disease_result: PhEvalDiseaseResult, rank: int):
        """Return RankedPhEvalDiseaseResult from a PhEvalDiseaseResult and rank
        Args:
            pheval_disease_result (PhEvalDiseaseResult): The disease result entry
            rank (int): The corresponding rank for the result entry

        Returns:
            RankedPhEvalDiseaseResult: The result as a RankedPhEvalDiseaseResult
        """
        return RankedPhEvalDiseaseResult(
            disease_name=pheval_disease_result.disease_name,
            disease_identifier=pheval_disease_result.disease_identifier,
            score=pheval_disease_result.score,
            rank=rank,
        )

from_disease_result(pheval_disease_result, rank) staticmethod

Return RankedPhEvalDiseaseResult from a PhEvalDiseaseResult and rank

Parameters:

Name Type Description Default
pheval_disease_result PhEvalDiseaseResult

The disease result entry

required
rank int

The corresponding rank for the result entry

required

Returns:

Name Type Description
RankedPhEvalDiseaseResult

The result as a RankedPhEvalDiseaseResult

Source code in src/pheval/post_processing/post_processing.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
@staticmethod
def from_disease_result(pheval_disease_result: PhEvalDiseaseResult, rank: int):
    """Return RankedPhEvalDiseaseResult from a PhEvalDiseaseResult and rank
    Args:
        pheval_disease_result (PhEvalDiseaseResult): The disease result entry
        rank (int): The corresponding rank for the result entry

    Returns:
        RankedPhEvalDiseaseResult: The result as a RankedPhEvalDiseaseResult
    """
    return RankedPhEvalDiseaseResult(
        disease_name=pheval_disease_result.disease_name,
        disease_identifier=pheval_disease_result.disease_identifier,
        score=pheval_disease_result.score,
        rank=rank,
    )

RankedPhEvalGeneResult dataclass

Bases: PhEvalGeneResult

PhEval gene result with corresponding rank

Parameters:

Name Type Description Default
rank int

The rank for the result entry

required
Source code in src/pheval/post_processing/post_processing.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@dataclass
class RankedPhEvalGeneResult(PhEvalGeneResult):
    """PhEval gene result with corresponding rank
    Args:
        rank (int): The rank for the result entry
    """

    rank: int

    @staticmethod
    def from_gene_result(pheval_gene_result: PhEvalGeneResult, rank: int):
        """Return RankedPhEvalGeneResult from a PhEvalGeneResult and rank
        Args:
            pheval_gene_result (PhEvalGeneResult): The gene result entry
            rank (int): The corresponding rank for the result entry

        Returns:
            RankedPhEvalGeneResult: The result as a RankedPhEvalGeneResult
        """
        return RankedPhEvalGeneResult(
            gene_symbol=pheval_gene_result.gene_symbol,
            gene_identifier=pheval_gene_result.gene_identifier,
            score=pheval_gene_result.score,
            rank=rank,
        )

from_gene_result(pheval_gene_result, rank) staticmethod

Return RankedPhEvalGeneResult from a PhEvalGeneResult and rank

Parameters:

Name Type Description Default
pheval_gene_result PhEvalGeneResult

The gene result entry

required
rank int

The corresponding rank for the result entry

required

Returns:

Name Type Description
RankedPhEvalGeneResult

The result as a RankedPhEvalGeneResult

Source code in src/pheval/post_processing/post_processing.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@staticmethod
def from_gene_result(pheval_gene_result: PhEvalGeneResult, rank: int):
    """Return RankedPhEvalGeneResult from a PhEvalGeneResult and rank
    Args:
        pheval_gene_result (PhEvalGeneResult): The gene result entry
        rank (int): The corresponding rank for the result entry

    Returns:
        RankedPhEvalGeneResult: The result as a RankedPhEvalGeneResult
    """
    return RankedPhEvalGeneResult(
        gene_symbol=pheval_gene_result.gene_symbol,
        gene_identifier=pheval_gene_result.gene_identifier,
        score=pheval_gene_result.score,
        rank=rank,
    )

RankedPhEvalVariantResult dataclass

Bases: PhEvalVariantResult

PhEval variant result with corresponding rank

Parameters:

Name Type Description Default
rank int

The rank for the result entry

required
Source code in src/pheval/post_processing/post_processing.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@dataclass
class RankedPhEvalVariantResult(PhEvalVariantResult):
    """PhEval variant result with corresponding rank
    Args:
        rank (int): The rank for the result entry
    """

    rank: int

    @staticmethod
    def from_variant_result(pheval_variant_result: PhEvalVariantResult, rank: int):
        """Return RankedPhEvalVariantResult from a PhEvalVariantResult and rank
        Args:
            pheval_variant_result (PhEvalVariantResult): The variant result entry
            rank (int): The corresponding rank for the result entry

        Returns:
            RankedPhEvalVariantResult: The result as a RankedPhEvalVariantResult
        """
        return RankedPhEvalVariantResult(
            chromosome=pheval_variant_result.chromosome,
            start=pheval_variant_result.start,
            end=pheval_variant_result.end,
            ref=pheval_variant_result.ref,
            alt=pheval_variant_result.alt,
            score=pheval_variant_result.score,
            rank=rank,
        )

from_variant_result(pheval_variant_result, rank) staticmethod

Return RankedPhEvalVariantResult from a PhEvalVariantResult and rank

Parameters:

Name Type Description Default
pheval_variant_result PhEvalVariantResult

The variant result entry

required
rank int

The corresponding rank for the result entry

required

Returns:

Name Type Description
RankedPhEvalVariantResult

The result as a RankedPhEvalVariantResult

Source code in src/pheval/post_processing/post_processing.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@staticmethod
def from_variant_result(pheval_variant_result: PhEvalVariantResult, rank: int):
    """Return RankedPhEvalVariantResult from a PhEvalVariantResult and rank
    Args:
        pheval_variant_result (PhEvalVariantResult): The variant result entry
        rank (int): The corresponding rank for the result entry

    Returns:
        RankedPhEvalVariantResult: The result as a RankedPhEvalVariantResult
    """
    return RankedPhEvalVariantResult(
        chromosome=pheval_variant_result.chromosome,
        start=pheval_variant_result.start,
        end=pheval_variant_result.end,
        ref=pheval_variant_result.ref,
        alt=pheval_variant_result.alt,
        score=pheval_variant_result.score,
        rank=rank,
    )

ResultSorter

Class for sorting PhEvalResult instances based on a given sort order.

Source code in src/pheval/post_processing/post_processing.py
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
class ResultSorter:
    """Class for sorting PhEvalResult instances based on a given sort order."""

    def __init__(self, pheval_results: [PhEvalResult], sort_order: SortOrder):
        """
        Initialise ResultSorter

        Args:
            pheval_results ([PhEvalResult]): List of PhEvalResult instances to be sorted
            sort_order (SortOrder): Sorting order to be applied
        """
        self.pheval_results = pheval_results
        self.sort_order = sort_order

    def _sort_by_decreasing_score(self) -> [PhEvalResult]:
        """
        Sort results in descending order based on the score

        Returns:
            [PhEvalResult]: Sorted list of PhEvalResult instances.
        """
        return sorted(self.pheval_results, key=operator.attrgetter("score"), reverse=True)

    def _sort_by_increasing_score(self) -> [PhEvalResult]:
        """
        Sort results in ascending order based on the score

        Returns:
            [PhEvalResult]: Sorted list of PhEvalResult instances.
        """
        return sorted(self.pheval_results, key=operator.attrgetter("score"), reverse=False)

    def sort_pheval_results(self) -> [PhEvalResult]:
        """
        Sort results based on the specified sort order.

        Returns:
            [PhEvalResult]: Sorted list of PhEvalResult instances.
        """
        return (
            self._sort_by_increasing_score()
            if self.sort_order == SortOrder.ASCENDING
            else self._sort_by_decreasing_score()
        )

__init__(pheval_results, sort_order)

Initialise ResultSorter

Parameters:

Name Type Description Default
pheval_results [PhEvalResult]

List of PhEvalResult instances to be sorted

required
sort_order SortOrder

Sorting order to be applied

required
Source code in src/pheval/post_processing/post_processing.py
187
188
189
190
191
192
193
194
195
196
def __init__(self, pheval_results: [PhEvalResult], sort_order: SortOrder):
    """
    Initialise ResultSorter

    Args:
        pheval_results ([PhEvalResult]): List of PhEvalResult instances to be sorted
        sort_order (SortOrder): Sorting order to be applied
    """
    self.pheval_results = pheval_results
    self.sort_order = sort_order

sort_pheval_results()

Sort results based on the specified sort order.

Returns:

Type Description
[PhEvalResult]

[PhEvalResult]: Sorted list of PhEvalResult instances.

Source code in src/pheval/post_processing/post_processing.py
216
217
218
219
220
221
222
223
224
225
226
227
def sort_pheval_results(self) -> [PhEvalResult]:
    """
    Sort results based on the specified sort order.

    Returns:
        [PhEvalResult]: Sorted list of PhEvalResult instances.
    """
    return (
        self._sort_by_increasing_score()
        if self.sort_order == SortOrder.ASCENDING
        else self._sort_by_decreasing_score()
    )

SortOrder

Bases: Enum

Enumeration representing sorting orders.

Source code in src/pheval/post_processing/post_processing.py
175
176
177
178
179
180
181
class SortOrder(Enum):
    """Enumeration representing sorting orders."""

    ASCENDING = 1
    """Ascending sort order."""
    DESCENDING = 2
    """Descending sort order."""

ASCENDING = 1 class-attribute

Ascending sort order.

DESCENDING = 2 class-attribute

Descending sort order.

calculate_end_pos(variant_start, variant_ref)

Calculate the end position for a variant

Parameters:

Name Type Description Default
variant_start int

The start position of the variant

required
variant_ref str

The reference allele of the variant

required

Returns:

Name Type Description
int int

The end position of the variant

Source code in src/pheval/post_processing/post_processing.py
12
13
14
15
16
17
18
19
20
21
def calculate_end_pos(variant_start: int, variant_ref: str) -> int:
    """Calculate the end position for a variant
    Args:
        variant_start (int): The start position of the variant
        variant_ref (str): The reference allele of the variant

    Returns:
        int: The end position of the variant
    """
    return variant_start + len(variant_ref) - 1

generate_pheval_result(pheval_result, sort_order_str, output_dir, tool_result_path)

Generate PhEval variant, gene or disease TSV result based on input results.

Parameters:

Name Type Description Default
pheval_result [PhEvalResult]

List of PhEvalResult instances to be processed.

required
sort_order_str str

String representation of the desired sorting order.

required
output_dir Path

Path to the output directory.

required
tool_result_path Path

Path to the tool-specific result file.

required

Raises:

Type Description
ValueError

If the results are not all the same type or an error occurs during file writing.

Source code in src/pheval/post_processing/post_processing.py
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
def generate_pheval_result(
    pheval_result: [PhEvalResult],
    sort_order_str: str,
    output_dir: Path,
    tool_result_path: Path,
) -> None:
    """
    Generate PhEval variant, gene or disease TSV result based on input results.

    Args:
        pheval_result ([PhEvalResult]): List of PhEvalResult instances to be processed.
        sort_order_str (str): String representation of the desired sorting order.
        output_dir (Path): Path to the output directory.
        tool_result_path (Path): Path to the tool-specific result file.

    Raises:
        ValueError: If the results are not all the same type or an error occurs during file writing.
    """
    if not pheval_result:
        info_log.warning(f"No results found for {tool_result_path.name}")
        return
    ranked_pheval_result = _create_pheval_result(pheval_result, sort_order_str)
    if all(isinstance(result, PhEvalGeneResult) for result in pheval_result):
        _write_pheval_gene_result(ranked_pheval_result, output_dir, tool_result_path)
    elif all(isinstance(result, PhEvalVariantResult) for result in pheval_result):
        _write_pheval_variant_result(ranked_pheval_result, output_dir, tool_result_path)
    elif all(isinstance(result, PhEvalDiseaseResult) for result in pheval_result):
        _write_pheval_disease_result(ranked_pheval_result, output_dir, tool_result_path)
    else:
        raise ValueError("Results are not all of the same type.")