Skip to content

Commit 8d2fdc8

Browse files
authored
Merge pull request #408 from monarch-initiative/fix_fp_error_in_doctests
Add numtest and use doctest.ELLIPSIS_MARKER to fix doctest errors when doing floating point number comparisons
2 parents 675b279 + be04858 commit 8d2fdc8

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55

6+
67
# -- General configuration ------------------------------------------------
78

89
# If your documentation needs a minimal Sphinx version, state it here.
@@ -217,4 +218,4 @@
217218
copybutton_exclude = '.linenos, .gp, .go'
218219

219220
# -- Sphinx Dark Mode setup --------------------------------------------------
220-
# default_dark_mode = False
221+
# default_dark_mode = False

docs/user-guide/analyses/phenotype-scores.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ This is a non-parametric test that compares the medians of the two classes to de
3939
>>> r = stats.mannwhitneyu(x=class1, y=class2, alternative = 'two-sided')
4040
>>> p_value = r.pvalue
4141
>>> float(p_value)
42-
6.348081479150902e-06
42+
6.348081479150...e-06
4343

4444

45-
p value of `6.348081479150901e-06` suggests a significant difference between the classes.
45+
p value of `6.348081479150e-06` suggests a significant difference between the classes.
4646

4747

4848
****************
@@ -73,7 +73,7 @@ from a `JSON file <https://github.com/monarch-initiative/gpsea/tree/main/docs/co
7373
The cohort was prepared from phenopackets as described in :ref:`create-a-cohort` section,
7474
and then serialized as a JSON file following the instructions in :ref:`cohort-persistence` section.
7575

76-
..
76+
..
7777
Prepare the JSON file by running the tests in `tests/tests/test_generate_doc_cohorts.py`.
7878
7979
>>> import json
@@ -99,8 +99,8 @@ Genotype predicate
9999
------------------
100100

101101
*Jordan et al.* compare phenotype of individuals harboring point mutations
102-
with the individuals carrying loss of function mutations.
103-
Let's create a predicate for testing if the variant
102+
with the individuals carrying loss of function mutations.
103+
Let's create a predicate for testing if the variant
104104
is a point mutation or a loss of function mutation.
105105

106106
In this example, the point mutation is a mutation that meets the following conditions:
@@ -158,7 +158,7 @@ As far as GPSEA framework is concerned, the phenotype score must be a floating p
158158
or a `NaN` value if the score cannot be computed for an individual.
159159
This is the essence of the :class:`~gpsea.analysis.pscore.PhenotypeScorer` class.
160160

161-
GPSEA ships with several builtin phenotype scorers which can be used as
161+
GPSEA ships with several builtin phenotype scorers which can be used as
162162

163163
+------------------------------------------------------------+---------------------------------------------+
164164
| Name | Description |
@@ -189,7 +189,7 @@ from the following 5 categories:
189189

190190
For example, an individual with a congenital heart defect would be assigned a score of `1`,
191191
an individual with congenital heart defect and a renal anomaly would be assigned a score of `2`,
192-
and so on. If an individual had two heart defects (e.g., atrial septal defect and ventricular septal defect),
192+
and so on. If an individual had two heart defects (e.g., atrial septal defect and ventricular septal defect),
193193
a score of 1 (not 2) would be assigned for the heart defect category.
194194

195195
The :class:`~gpsea.analysis.pscore.CountingPhenotypeScorer` automatizes this scoring method
@@ -245,7 +245,7 @@ We will put the final analysis together into :class:`~gpsea.analysis.pscore.Phen
245245

246246
>>> from gpsea.analysis.pscore import PhenotypeScoreAnalysis
247247
>>> score_analysis = PhenotypeScoreAnalysis(
248-
... score_statistic=score_statistic,
248+
... score_statistic=score_statistic,
249249
... )
250250

251251

@@ -265,8 +265,8 @@ In case of the *RERE* cohort, the analysis shows a significant difference
265265
between the number of structural defects in individuals
266266
with point vs. loss-of-function mutations.
267267

268-
>>> result.pval
269-
0.012074957610483744
268+
>>> result.pval # doctest: +ELLIPSIS
269+
0.0120749576...
270270

271271

272272
To explore further, we can access a data frame with genotype categories and phenotype counts:

docs/user-guide/analyses/survival.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ from a `JSON file <https://github.com/monarch-initiative/gpsea/tree/main/docs/co
2727
The cohort was prepared from phenopackets as described in :ref:`create-a-cohort` section,
2828
and then serialized as a JSON file following the instructions in :ref:`cohort-persistence` section.
2929

30-
..
30+
..
3131
Prepare the JSON file by running the tests in `tests/tests/test_generate_doc_cohorts.py`.
3232
3333
>>> import json
@@ -127,7 +127,7 @@ We execute the analysis by running
127127
... )
128128

129129
>>> result.pval
130-
0.06200425830044376
130+
0.062004258300...
131131

132132

133133
Kaplan-Meier curves
@@ -145,7 +145,7 @@ We can plot Kaplan-Meier curves:
145145
... )
146146
>>> _ = ax.xaxis.set(
147147
... # Show X axis in years ...
148-
... major_formatter=mpl.ticker.FuncFormatter(lambda x, pos: f"{x / Age.DAYS_IN_YEAR:.0f}"),
148+
... major_formatter=mpl.ticker.FuncFormatter(lambda x, pos: f"{x / Age.DAYS_IN_YEAR:.0f}"),
149149
... # ... with a tick for every decade
150150
... major_locator=mpl.ticker.MultipleLocator(10 * Age.DAYS_IN_YEAR),
151151
... )
@@ -164,7 +164,7 @@ We can plot Kaplan-Meier curves:
164164
:hide:
165165

166166
>>> if _overwrite: fig.savefig('docs/user-guide/analyses/report/umod_km_curves.png')
167-
167+
168168

169169
Raw data
170170
--------
@@ -174,7 +174,7 @@ The `result` includes the survival values for all cohort members:
174174
>>> survivals = result.data.sort_index()
175175
>>> survivals.head() # doctest: +NORMALIZE_WHITESPACE
176176
genotype phenotype
177-
patient_id
177+
patient_id
178178
AII.1[PMID_22034507_AII_1] 0 Survival(value=18262.5, is_censored=True)
179179
AII.2[PMID_22034507_AII_2] 0 None
180180
AII.3[PMID_22034507_AII_3] 0 Survival(value=16436.25, is_censored=True)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ dynamic = ["version"]
5151
[project.optional-dependencies]
5252
test = [
5353
"pytest>=7.0.0,<8.0.0",
54-
"pytest-cov",
54+
"pytest-cov"
5555
]
5656
docs = [
5757
"sphinx>=7.0.0",
5858
"sphinx-rtd-theme>=1.3.0",
5959
"sphinx-rtd-dark-mode>=1.3.0",
60-
"sphinx-copybutton>=0.5.0",
60+
"sphinx-copybutton>=0.5.0",
6161
]
6262

6363
[project.urls]

0 commit comments

Comments
 (0)