Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docs/user-guide/analyses/phenotype-classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 17 additions & 14 deletions src/gpsea/analysis/pcats/_impl.py
Original file line number Diff line number Diff line change
@@ -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"
"""
Expand All @@ -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.
Expand All @@ -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(
Expand All @@ -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

Expand Down
Loading