diff --git a/my_tests/test_pidentcomments.py b/my_tests/test_pidentcomments.py new file mode 100644 index 0000000..c8ab043 --- /dev/null +++ b/my_tests/test_pidentcomments.py @@ -0,0 +1,21 @@ +import math +from my_tests.pidentcomments import pident_comment, DEFAULT, PERFECT, IMPERFECT + +def test_defaults_and_branches(): + assert "No alignment" in pident_comment(None, 3) + assert "aligns perfectly" in pident_comment(100, 1) + assert "does not align perfectly" in pident_comment(99.9, 1) + # With 0 targets we fall back to DEFAULT + assert "No alignment" in pident_comment(0, 0) + +def test_never_raises_on_weird_inputs(): + for pair in [("x","y"), ([],{}), (object(),object()), (-1,-1)]: + out = pident_comment(*pair) + assert isinstance(out, str) + assert "No alignment" in out + +def test_constants_are_strings(): + for s in (DEFAULT, PERFECT, IMPERFECT): + assert isinstance(s, str) + + diff --git a/scripts/puppy-primers b/scripts/puppy-primers old mode 100644 new mode 100755 index 7fa2d0c..4e9dbc5 --- a/scripts/puppy-primers +++ b/scripts/puppy-primers @@ -984,10 +984,21 @@ elif args.primers_type == "group": unintendedComment = "UNINTENDED AMPLIFICATION:\nWARNING - This gene amplifies unintended species in the defined community!" ## Comments about percentage identity of alignments: - if pidentSum == 100 * numTargets: - PidentComments = "ALIGNMENTS %ID:\nThis gene aligns perfectly (100% ID) to each target gene." - elif pidentSum < 100 * numTargets: - PidentComments = "ALIGNMENTS %ID:\nThis gene does not align perfectly (100% ID) to at least one target gene." + PidentComments = "ALIGNMENTS %ID:\nNo alignment information available." + + if isinstance(pidentSum, (int, float)) and isinstance(numTargets, (int, float)): + if not pidentSum or not numTargets: + PidentComments = ( + "ALIGNMENTS %ID:\nNo alignment information available." + ) + elif pidentSum == 100 * numTargets: + PidentComments = ( + "ALIGNMENTS %ID:\nThis gene aligns perfectly (100% ID) to each target gene." + ) + elif pidentSum < 100 * numTargets: + PidentComments = ( + "ALIGNMENTS %ID:\nThis gene does not align perfectly (100% ID) to at least one target gene." + ) ## Comments about alignments query coverage: if qcovSum == 1 * numTargets: