From ed2a245f47cbf4a970ca177c021550b198124278 Mon Sep 17 00:00:00 2001 From: Yasemin Bridges Date: Thu, 7 Dec 2023 10:54:33 +0000 Subject: [PATCH 1/3] implement check for empty results and print out warning message --- src/pheval/post_processing/post_processing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pheval/post_processing/post_processing.py b/src/pheval/post_processing/post_processing.py index c80d1f2ef..923ed3973 100644 --- a/src/pheval/post_processing/post_processing.py +++ b/src/pheval/post_processing/post_processing.py @@ -256,7 +256,10 @@ def generate_pheval_result( output_dir: Path, tool_result_path: Path, ): - """Generate either a PhEval variant or PhEval gene tsv result.""" + """Generate either a PhEval variant, gene, or disease tsv result.""" + if not pheval_result: + print(f"Warning: No results found for {tool_result_path.name}") + pass ranked_pheval_result = _create_pheval_result(pheval_result, sort_order_str) if all(isinstance(result, RankedPhEvalGeneResult) for result in ranked_pheval_result): _write_pheval_gene_result(ranked_pheval_result, output_dir, tool_result_path) From 5d818c466a88bf4cd31ced3b3321d51bbd2a7e8e Mon Sep 17 00:00:00 2001 From: Yasemin Bridges Date: Thu, 7 Dec 2023 16:29:29 +0000 Subject: [PATCH 2/3] using log in place of print statement --- src/pheval/post_processing/post_processing.py | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/pheval/post_processing/post_processing.py b/src/pheval/post_processing/post_processing.py index 73b908dc3..737929d27 100644 --- a/src/pheval/post_processing/post_processing.py +++ b/src/pheval/post_processing/post_processing.py @@ -2,9 +2,11 @@ from dataclasses import dataclass from enum import Enum from pathlib import Path - +import logging import pandas as pd +info_log = logging.getLogger("info") + def calculate_end_pos(variant_start: int, variant_ref: str) -> int: """Calculate the end position for a variant @@ -179,7 +181,6 @@ class SortOrder(Enum): class ResultSorter: - """Class for sorting PhEvalResult instances based on a given sort order.""" def __init__(self, pheval_results: [PhEvalResult], sort_order: SortOrder): @@ -259,11 +260,11 @@ def _check_rank_order(self, round_score: float) -> None: ValueError: If results are not correctly sorted. """ if self.sort_order == SortOrder.ASCENDING and round_score < self.current_score != float( - "inf" + "inf" ): raise ValueError("Results are not correctly sorted!") elif self.sort_order == SortOrder.DESCENDING and round_score > self.current_score != float( - "inf" + "inf" ): raise ValueError("Results are not correctly sorted!") @@ -362,7 +363,7 @@ def _create_pheval_result(pheval_result: [PhEvalResult], sort_order_str: str) -> def _write_pheval_gene_result( - ranked_pheval_result: [PhEvalResult], output_dir: Path, tool_result_path: Path + ranked_pheval_result: [PhEvalResult], output_dir: Path, tool_result_path: Path ) -> None: """ Write ranked PhEval gene results to a TSV file @@ -384,7 +385,7 @@ def _write_pheval_gene_result( def _write_pheval_variant_result( - ranked_pheval_result: [PhEvalResult], output_dir: Path, tool_result_path: Path + ranked_pheval_result: [PhEvalResult], output_dir: Path, tool_result_path: Path ) -> None: """ Write ranked PhEval variant results to a TSV file @@ -396,8 +397,8 @@ def _write_pheval_variant_result( """ ranked_result = pd.DataFrame([data.__dict__ for data in ranked_pheval_result]) pheval_variant_output = ranked_result.loc[ - :, ["rank", "score", "chromosome", "start", "end", "ref", "alt"] - ] + :, ["rank", "score", "chromosome", "start", "end", "ref", "alt"] + ] pheval_variant_output.to_csv( output_dir.joinpath( "pheval_variant_results/" + tool_result_path.stem + "-pheval_variant_result.tsv" @@ -408,7 +409,7 @@ def _write_pheval_variant_result( def _write_pheval_disease_result( - ranked_pheval_result: [RankedPhEvalDiseaseResult], output_dir: Path, tool_result_path: Path + ranked_pheval_result: [RankedPhEvalDiseaseResult], output_dir: Path, tool_result_path: Path ) -> None: """ Write ranked PhEval disease results to a TSV file @@ -420,8 +421,8 @@ def _write_pheval_disease_result( """ ranked_result = pd.DataFrame([data.__dict__ for data in ranked_pheval_result]) pheval_disease_output = ranked_result.loc[ - :, ["rank", "score", "disease_name", "disease_identifier"] - ] + :, ["rank", "score", "disease_name", "disease_identifier"] + ] pheval_disease_output.to_csv( output_dir.joinpath( "pheval_disease_results/" + tool_result_path.stem + "-pheval_disease_result.tsv" @@ -432,10 +433,10 @@ def _write_pheval_disease_result( def generate_pheval_result( - pheval_result: [PhEvalResult], - sort_order_str: str, - output_dir: Path, - tool_result_path: Path, + 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. @@ -450,7 +451,7 @@ def generate_pheval_result( ValueError: If the results are not all the same type or an error occurs during file writing. """ if not pheval_result: - print(f"Warning: No results found for {tool_result_path.name}") + info_log.warning(f"No results found for {tool_result_path.name}") pass ranked_pheval_result = _create_pheval_result(pheval_result, sort_order_str) if all(isinstance(result, RankedPhEvalGeneResult) for result in ranked_pheval_result): From 55001d13e560281333e2e6e7848cbf3942932408 Mon Sep 17 00:00:00 2001 From: Yasemin Bridges Date: Thu, 7 Dec 2023 16:30:58 +0000 Subject: [PATCH 3/3] tox lint --- src/pheval/post_processing/post_processing.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/pheval/post_processing/post_processing.py b/src/pheval/post_processing/post_processing.py index 737929d27..5d1e3b9ea 100644 --- a/src/pheval/post_processing/post_processing.py +++ b/src/pheval/post_processing/post_processing.py @@ -1,8 +1,9 @@ +import logging import operator from dataclasses import dataclass from enum import Enum from pathlib import Path -import logging + import pandas as pd info_log = logging.getLogger("info") @@ -260,11 +261,11 @@ def _check_rank_order(self, round_score: float) -> None: ValueError: If results are not correctly sorted. """ if self.sort_order == SortOrder.ASCENDING and round_score < self.current_score != float( - "inf" + "inf" ): raise ValueError("Results are not correctly sorted!") elif self.sort_order == SortOrder.DESCENDING and round_score > self.current_score != float( - "inf" + "inf" ): raise ValueError("Results are not correctly sorted!") @@ -363,7 +364,7 @@ def _create_pheval_result(pheval_result: [PhEvalResult], sort_order_str: str) -> def _write_pheval_gene_result( - ranked_pheval_result: [PhEvalResult], output_dir: Path, tool_result_path: Path + ranked_pheval_result: [PhEvalResult], output_dir: Path, tool_result_path: Path ) -> None: """ Write ranked PhEval gene results to a TSV file @@ -385,7 +386,7 @@ def _write_pheval_gene_result( def _write_pheval_variant_result( - ranked_pheval_result: [PhEvalResult], output_dir: Path, tool_result_path: Path + ranked_pheval_result: [PhEvalResult], output_dir: Path, tool_result_path: Path ) -> None: """ Write ranked PhEval variant results to a TSV file @@ -397,8 +398,8 @@ def _write_pheval_variant_result( """ ranked_result = pd.DataFrame([data.__dict__ for data in ranked_pheval_result]) pheval_variant_output = ranked_result.loc[ - :, ["rank", "score", "chromosome", "start", "end", "ref", "alt"] - ] + :, ["rank", "score", "chromosome", "start", "end", "ref", "alt"] + ] pheval_variant_output.to_csv( output_dir.joinpath( "pheval_variant_results/" + tool_result_path.stem + "-pheval_variant_result.tsv" @@ -409,7 +410,7 @@ def _write_pheval_variant_result( def _write_pheval_disease_result( - ranked_pheval_result: [RankedPhEvalDiseaseResult], output_dir: Path, tool_result_path: Path + ranked_pheval_result: [RankedPhEvalDiseaseResult], output_dir: Path, tool_result_path: Path ) -> None: """ Write ranked PhEval disease results to a TSV file @@ -421,8 +422,8 @@ def _write_pheval_disease_result( """ ranked_result = pd.DataFrame([data.__dict__ for data in ranked_pheval_result]) pheval_disease_output = ranked_result.loc[ - :, ["rank", "score", "disease_name", "disease_identifier"] - ] + :, ["rank", "score", "disease_name", "disease_identifier"] + ] pheval_disease_output.to_csv( output_dir.joinpath( "pheval_disease_results/" + tool_result_path.stem + "-pheval_disease_result.tsv" @@ -433,10 +434,10 @@ def _write_pheval_disease_result( def generate_pheval_result( - pheval_result: [PhEvalResult], - sort_order_str: str, - output_dir: Path, - tool_result_path: Path, + 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.