diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 061961a2..256322aa 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -332,11 +332,12 @@ Statistical testing Now we can perform the testing and evaluate the results. ->>> result = analysis.compare_genotype_vs_phenotypes( +>>> result = analysis.compare_genotype_vs_phenotypes( # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE ... cohort=cohort, ... gt_clf=gt_clf, ... pheno_clfs=pheno_clfs, ... ) +HPO terms processed: ... >>> result.total_tests 30 diff --git a/docs/user-guide/analyses/phenotype-classes.rst b/docs/user-guide/analyses/phenotype-classes.rst index 41785f31..27c838cb 100644 --- a/docs/user-guide/analyses/phenotype-classes.rst +++ b/docs/user-guide/analyses/phenotype-classes.rst @@ -287,11 +287,12 @@ Analysis We can now test associations between the genotype classes and the HPO terms: ->>> result = analysis.compare_genotype_vs_phenotypes( +>>> result = analysis.compare_genotype_vs_phenotypes( # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE ... cohort=cohort, ... gt_clf=gt_clf, ... pheno_clfs=pheno_clfs, ... ) +HPO terms processed: ... >>> len(result.phenotypes) 369 >>> result.total_tests diff --git a/src/gpsea/analysis/pcats/_impl.py b/src/gpsea/analysis/pcats/_impl.py index 2bcbc382..64c5dd00 100644 --- a/src/gpsea/analysis/pcats/_impl.py +++ b/src/gpsea/analysis/pcats/_impl.py @@ -1,24 +1,22 @@ import abc +import collections.abc import os +import sys import typing - from collections import Counter import hpotk import numpy as np import pandas as pd - +import tqdm from statsmodels.stats import multitest from gpsea.model import Patient -from ..clf import GenotypeClassifier -from ..clf import P, PhenotypeClassifier +from .._base import MultiPhenotypeAnalysisResult, StatisticResult +from ..clf import GenotypeClassifier, P, PhenotypeClassifier from ..mtc_filter import PhenotypeMtcFilter, PhenotypeMtcResult - from .stats import CountStatistic -from .._base import MultiPhenotypeAnalysisResult, StatisticResult - DEFAULT_MTC_PROCEDURE = "fdr_bh" """ @@ -27,12 +25,12 @@ def apply_classifiers_on_individuals( - individuals: typing.Iterable[Patient], + individuals: collections.abc.Iterable[Patient], gt_clf: GenotypeClassifier, - pheno_clfs: typing.Sequence[PhenotypeClassifier[P]], -) -> typing.Tuple[ - typing.Sequence[int], - typing.Sequence[pd.DataFrame], + pheno_clfs: collections.abc.Sequence[PhenotypeClassifier[P]], +) -> tuple[ + collections.abc.Sequence[int], + collections.abc.Sequence[pd.DataFrame], ]: """ Classify individuals with the genotype and phenotype classifiers. @@ -57,7 +55,12 @@ def apply_classifiers_on_individuals( # Apply genotype and phenotype predicates count_dict = {} - for ph_predicate in pheno_clfs: + for ph_predicate in tqdm.tqdm( + pheno_clfs, + desc="HPO terms processed", + file=sys.stdout, + unit=" terms", + ): if ph_predicate.phenotype not in count_dict: # Make an empty frame for keeping track of the counts. count_dict[ph_predicate.phenotype] = pd.DataFrame( @@ -83,7 +86,7 @@ def apply_classifiers_on_individuals( # Convert dicts to numpy arrays n_usable_patients = [n_usable_patient_counter[ph_predicate.phenotype] for ph_predicate in pheno_clfs] - counts = [count_dict[ph_predicate.phenotype] for ph_predicate in pheno_clfs] + counts: list[pd.DataFrame] = [count_dict[ph_predicate.phenotype] for ph_predicate in pheno_clfs] return n_usable_patients, counts