-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from TheJacksonLaboratory/G3-209-add-check-thr…
…eshold-functions-to-geneweaver-core Adding check threshold function and related tests
- Loading branch information
Showing
5 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "geneweaver-core" | ||
version = "0.9.0a6" | ||
version = "0.9.0a7" | ||
description = "The core of the Jax-Geneweaver Python library" | ||
authors = ["Jax Computational Sciences <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""A module for functions dealing with thresholding.""" | ||
|
||
from typing import List | ||
|
||
from geneweaver.core.schema.score import GenesetScoreType | ||
|
||
|
||
def check_threshold(geneset_score: GenesetScoreType, value: float) -> bool: | ||
"""Check to see if a value falls within the score threshold. | ||
:param geneset_score: The geneset score type and threshold arguments. | ||
:param value: The value to check against. | ||
:return: A boolean that indicates if the value falls within the range specified by | ||
the threshold. | ||
""" | ||
score_type = int(geneset_score.score_type) | ||
value = float(value) | ||
|
||
# P and Q values | ||
if score_type == 1 or score_type == 2: | ||
return value <= geneset_score.threshold | ||
|
||
# Correlation and effect scores | ||
elif score_type == 4 or score_type == 5: | ||
return geneset_score.threshold_low <= value <= geneset_score.threshold | ||
|
||
# Binary | ||
else: | ||
return value >= geneset_score.threshold | ||
|
||
|
||
def check_threshold_list( | ||
geneset_score: GenesetScoreType, values: List[float] | ||
) -> List[bool]: | ||
"""Check to see if a list of values falls within the score threshold. | ||
:param geneset_score: The geneset score type and threshold arguments. | ||
:param values: The list of values to check against. | ||
:return: A list of booleans that indicates if the value falls within the range | ||
specified by the threshold. | ||
""" | ||
return [check_threshold(geneset_score, value) for value in values] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for threshold functions.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Test the check_threshold function.""" | ||
|
||
import pytest | ||
from geneweaver.core.schema.score import GenesetScoreType | ||
from geneweaver.core.threshold import check_threshold | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("geneset_score", "value", "expected"), | ||
[ | ||
(GenesetScoreType(score_type=1, threshold=0.05), 0.01, True), | ||
(GenesetScoreType(score_type=1, threshold=0.05), 0.06, False), | ||
(GenesetScoreType(score_type=2, threshold=0.05), 0.01, True), | ||
(GenesetScoreType(score_type=2, threshold=0.05), 0.06, False), | ||
(GenesetScoreType(score_type=3, threshold=0.05), 0.01, False), | ||
( | ||
GenesetScoreType(score_type=4, threshold=0.05, threshold_low=0.01), | ||
0.03, | ||
True, | ||
), | ||
( | ||
GenesetScoreType(score_type=4, threshold=0.05, threshold_low=0.01), | ||
0.06, | ||
False, | ||
), | ||
( | ||
GenesetScoreType(score_type=5, threshold=0.05, threshold_low=0.01), | ||
0.03, | ||
True, | ||
), | ||
], | ||
) | ||
def test_check_threshold(geneset_score, value, expected): | ||
"""Check each parametrized case with valid arguments.""" | ||
assert check_threshold(geneset_score, value) == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Test the check_threshold_list function.""" | ||
|
||
import pytest | ||
from geneweaver.core.schema.score import GenesetScoreType | ||
from geneweaver.core.threshold import check_threshold_list | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("geneset_scores", "values", "expected"), | ||
[ | ||
(GenesetScoreType(score_type=1, threshold=0.05), [0.01, 0.06], [True, False]), | ||
(GenesetScoreType(score_type=2, threshold=0.05), [0.01, 0.06], [True, False]), | ||
(GenesetScoreType(score_type=3, threshold=0.05), [0.01, 0.06], [False, True]), | ||
( | ||
GenesetScoreType(score_type=4, threshold=0.05, threshold_low=0.01), | ||
[0.03, 0.06], | ||
[True, False], | ||
), | ||
( | ||
GenesetScoreType(score_type=5, threshold=0.05, threshold_low=0.01), | ||
[0.03, 0.06], | ||
[True, False], | ||
), | ||
( | ||
GenesetScoreType(score_type="p-value", threshold=0.05), | ||
[0.01, 0.06], | ||
[True, False], | ||
), | ||
( | ||
GenesetScoreType(score_type="q-value", threshold=0.05), | ||
[0.01, 0.06], | ||
[True, False], | ||
), | ||
( | ||
GenesetScoreType(score_type="binary", threshold=0.05), | ||
[0.01, 0.06], | ||
[False, True], | ||
), | ||
( | ||
GenesetScoreType( | ||
score_type="correlation", threshold=0.05, threshold_low=0.01 | ||
), | ||
[0.03, 0.06], | ||
[True, False], | ||
), | ||
( | ||
GenesetScoreType(score_type="effect", threshold=0.05, threshold_low=0.01), | ||
[0.03, 0.06], | ||
[True, False], | ||
), | ||
], | ||
) | ||
def test_check_threshold_list(geneset_scores, values, expected): | ||
"""Check each parametrized case with valid arguments.""" | ||
assert check_threshold_list(geneset_scores, values) == expected |