test_primer3.py 3.94 KB
Newer Older
1
2
3
4
5
6
7
8
9
"""
test_primer3.py
~~~~~~~~~~~~~~~

:copyright: (c) 2018 Sander Bollen
:copyright: (c) 2018 Leiden University Medical Center
:license: MIT
"""
from pathlib import Path
10
11
import pytest
from prinia.primer3 import parse_settings, create_primer3_config
12
13
14
15


data_dir = Path(__file__).parent / Path("data")

16
17

@pytest.fixture
18
19
20
21
def valid_settings():
    return data_dir / Path("valid_settings.json")


22
@pytest.fixture
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def valid_partial_settings():
    return data_dir / Path("valid_partial_settings.json")


def test_none_settings():
    parsed = parse_settings()
    assert parsed == {
        "primer_min_gc": 20,
        "primer_internal_min_gc": 20,
        "primer_opt_gc_percent": 50,
        "primer_max_gc": 80,
        "primer_internal_max_gc": 80,
        "primer_wt_gc_percent_lt": 0,
        "primer_internal_wt_gc_percent_lt": 0,
        "primer_wt_gc_percent_gt": 0,
        "primer_internal_wt_gc_percent_gt": 0,
        "primer_gc_clamp": 0,
        "primer_max_end_gc": 5,
        "primer_opt_size": 25,
        "primer_min_size": 20,
        "primer_max_size": 30,
        "primer_max_ns_accepted": 0,
        "primer_product_size_range": "200-450",
        "primer_product_opt_size": 325,
        "primer_pair_wt_product_size_gt": 0.1,
        "primer_pair_wt_product_size_lt": 0.1,
        "primer_min_tm": 58,
        "primer_max_tm": 62,
        "primer_num_return": 200
    }


def test_complete_settings(valid_settings):
    parsed = parse_settings(valid_settings)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    assert parsed == {
        "primer_min_gc": 30,
        "primer_internal_min_gc": 30,
        "primer_opt_gc_percent": 51,
        "primer_max_gc": 81,
        "primer_internal_max_gc": 81,
        "primer_wt_gc_percent_lt": 0.12,
        "primer_internal_wt_gc_percent_lt": 0.12,
        "primer_wt_gc_percent_gt": 0.12,
        "primer_internal_wt_gc_percent_gt": 0.12,
        "primer_gc_clamp": 1,
        "primer_max_end_gc": 0,
        "primer_opt_size": 21,
        "primer_min_size": 19,
        "primer_max_size": 29,
        "primer_max_ns_accepted": 1,
        "primer_product_size_range": "300-500",
        "primer_product_opt_size": 300,
        "primer_pair_wt_product_size_gt": 0.12,
        "primer_pair_wt_product_size_lt": 0.12,
        "primer_min_tm": 55,
        "primer_max_tm": 75,
        "primer_num_return": 100
    }
81
82
83
84
85


def test_partial_settings(valid_partial_settings):
    parsed = parse_settings(valid_partial_settings)

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    assert parsed == {
        "primer_min_gc": 20,
        "primer_internal_min_gc": 20,
        "primer_opt_gc_percent": 50,
        "primer_max_gc": 80,
        "primer_internal_max_gc": 80,
        "primer_wt_gc_percent_lt": 0,
        "primer_internal_wt_gc_percent_lt": 0,
        "primer_wt_gc_percent_gt": 0,
        "primer_internal_wt_gc_percent_gt": 0,
        "primer_gc_clamp": 1,
        "primer_max_end_gc": 0,
        "primer_opt_size": 21,
        "primer_min_size": 19,
        "primer_max_size": 29,
        "primer_max_ns_accepted": 1,
        "primer_product_size_range": "300-500",
        "primer_product_opt_size": 400,
        "primer_pair_wt_product_size_gt": 0.12,
        "primer_pair_wt_product_size_lt": 0.12,
        "primer_min_tm": 55,
        "primer_max_tm": 75,
        "primer_num_return": 100
    }

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

configuration_data = [
    (None, data_dir / Path("primer3_conf_default.txt")),
    (
        data_dir / Path("valid_settings.json"),
        data_dir / Path("primer3_conf_full_settings.txt")
    ),
    (
        data_dir / Path("valid_partial_settings.json"),
        data_dir / Path("primer3_conf_partial_settings.txt")
    )
]


@pytest.mark.parametrize("settings_json, conf", configuration_data)
def test_primer3_configuration(settings_json, conf):
    parsed_settings = parse_settings(settings_json)
    generated_conf = create_primer3_config(parsed_settings, "ACTG",
                                           "50-60", "50-60")
    with conf.open("r") as chandle:
        expected_conf = chandle.read().strip()

    assert generated_conf == expected_conf