Skip to content

Commit

Permalink
Merge pull request #337 from monarch-initiative/investigate-qc
Browse files Browse the repository at this point in the history
Fix Q/C reporting
ielis authored Oct 29, 2024
2 parents f20af85 + c1b9acf commit 39e8c81
Showing 11 changed files with 83 additions and 420 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ classifiers = [
]
dependencies = [
"hpo-toolkit>=0.3.0",
"stairval>=0.2.0",
"Jinja2>=3.1.4,<4.0.0",
"protobuf>=3.15.0",
"pandas>=2.0.0,<3.0.0",
10 changes: 7 additions & 3 deletions src/gpsea/model/_cohort.py
Original file line number Diff line number Diff line change
@@ -267,12 +267,16 @@ def __hash__(self) -> int:


class Cohort(typing.Sized, typing.Iterable[Patient]):
"""
Cohort is a collection of individuals that have been preprocessed
and are ready for genotype-phenotype association analysis.
"""

@staticmethod
def from_patients(
members: typing.Iterable[Patient],
include_patients_with_no_HPO: bool = False,
include_patients_with_no_variants: bool = False,
members: typing.Iterable[Patient],
include_patients_with_no_HPO: bool = False,
include_patients_with_no_variants: bool = False,
):
"""
Create a cohort from a sequence of patients.
2 changes: 0 additions & 2 deletions src/gpsea/preprocessing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ._api import PreprocessingValidationResult
from ._api import TranscriptCoordinateService, GeneCoordinateService
from ._api import VariantCoordinateFinder, FunctionalAnnotator, ImpreciseSvFunctionalAnnotator, ProteinMetadataService
from ._audit import Auditor, DataSanityIssue, Level, Notepad, NotepadTree
from ._config import load_phenopacket_folder, load_phenopacket_files, load_phenopackets
from ._config import configure_caching_cohort_creator, configure_cohort_creator
from ._config import configure_default_protein_metadata_service, configure_protein_metadata_service
@@ -27,6 +26,5 @@
'UniprotProteinMetadataService',
'VepFunctionalAnnotator', 'VariantAnnotationCache', 'VarCachingFunctionalAnnotator',
'VVHgvsVariantCoordinateFinder', 'VVMultiCoordinateService',
'Auditor', 'DataSanityIssue', 'Level', 'Notepad', 'NotepadTree',
'DefaultImpreciseSvFunctionalAnnotator',
]
27 changes: 13 additions & 14 deletions src/gpsea/preprocessing/_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import abc
import io
import os
import sys
import typing

from stairval.notepad import Notepad

from gpsea.model import (
VariantCoordinates,
ProteinMetadata,
@@ -13,8 +14,6 @@
ImpreciseSvInfo,
)

from ._audit import NotepadTree

T = typing.TypeVar("T")


@@ -142,7 +141,7 @@ class PreprocessingValidationResult:
def __init__(
self,
policy: str,
notepad: NotepadTree,
notepad: Notepad,
):
self._policy = policy
self._notepad = notepad
@@ -175,7 +174,7 @@ def is_ok(self) -> bool:

def summarize(
self,
file: io.TextIOBase = sys.stdout,
file: typing.TextIO = sys.stdout,
indent: int = 2,
):
"""
@@ -189,13 +188,13 @@ def summarize(
file.write(f"Validated under {self._policy} policy")
file.write(os.linesep)

n_errors = sum(node.error_count() for node in self._notepad.iterate_nodes())
n_warnings = sum(node.warning_count() for node in self._notepad.iterate_nodes())
n_errors = sum(node.error_count() for node in self._notepad.iter_sections())
n_warnings = sum(node.warning_count() for node in self._notepad.iter_sections())
if n_errors > 0 or n_warnings > 0:
file.write("Showing errors and warnings")
file.write(os.linesep)

for node in self._notepad.iterate_nodes():
for node in self._notepad.iter_sections():
if node.has_errors_or_warnings(include_subsections=True):
# We must report the node label even if there are no issues with the node.
l_pad = " " * (node.level * indent)
@@ -207,19 +206,19 @@ def summarize(
file.write(os.linesep)
for error in node.errors():
file.write(
l_pad + " " + error.message + f". {error.solution}"
if error.solution
else ""
l_pad + " ·" + error.message + (
f". {error.solution}" if error.solution else ""
)
)
file.write(os.linesep)
if node.has_warnings():
file.write(l_pad + " warnings:")
file.write(os.linesep)
for warning in node.warnings():
file.write(
l_pad + " ·" + warning.message + f". {warning.solution}"
if warning.solution
else ""
l_pad + " ·" + warning.message + (
f". {warning.solution}" if warning.solution else ""
)
)
file.write(os.linesep)
else:
Loading

0 comments on commit 39e8c81

Please sign in to comment.