Skip to content

Commit babc010

Browse files
committed
Added more helper functions
1 parent b477eea commit babc010

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/test_read_simulator/test_cover_dataset.py

+54
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,57 @@ def test_fragment_mean_st_dev_combinations():
9999
read1, _ = cover_dataset(read_pool, span_length, target_vector, options, fragment_model)
100100
except Exception as e:
101101
pytest.fail(f"Test failed for mean={mean}, st_dev={st_dev} with exception: {e}")
102+
103+
def test_coverage_ploidy_combinations():
104+
"""Test cover_dataset with various combinations of coverage and ploidy values to ensure no errors"""
105+
read_pool = [10] * 2000
106+
span_length = 100
107+
target_vector = np.full(100, fill_value=10, dtype=int)
108+
options = Options(rng_seed=0)
109+
options.paired_ended = True
110+
options.read_len = 101
111+
options.fragment_mean = 250
112+
options.fragment_st_dev = 100
113+
options.output.overwrite_output = True
114+
fragment_model = FragmentLengthModel(rng=options.rng)
115+
116+
coverage_values = [1, 2, 5, 10, 25, 50, 100]
117+
ploidy_values = [1, 1.5, 2]
118+
119+
for coverage in coverage_values:
120+
for ploidy in ploidy_values:
121+
options.coverage = coverage
122+
options.ploidy = ploidy # Assuming your model or function supports a 'ploidy' option
123+
read1, read2 = cover_dataset(read_pool, span_length, target_vector, options, fragment_model)
124+
coverage_check = []
125+
for i in range(span_length):
126+
# paired ended test, need both read1 and read2
127+
cover = [x for x in read1 + read2 if i in range(x[0], x[1])]
128+
coverage_check.append(len(cover))
129+
assert sum(coverage_check) / len(
130+
coverage_check) > coverage, f"Coverage check failed for coverage {coverage} and ploidy {ploidy}"
131+
132+
def test_single_ended_mode():
133+
"""Test cover_dataset in single-ended mode for various configurations"""
134+
read_pool = [10] * 2000
135+
span_length = 100
136+
target_vector = np.full(100, fill_value=10, dtype=int)
137+
options = Options(rng_seed=0)
138+
options.read_len = 101
139+
options.paired_ended = False
140+
options.fragment_mean = 250
141+
options.fragment_st_dev = 100
142+
options.coverage = 10
143+
options.output.overwrite_output = True
144+
fragment_model = FragmentLengthModel(rng=options.rng)
145+
146+
try:
147+
read1, _ = cover_dataset(read_pool, span_length, target_vector, options, fragment_model)
148+
coverage_check = []
149+
for i in range(span_length):
150+
# Single-ended test, only need read1
151+
cover = [x for x in read1 if i in range(x[0], x[1])]
152+
coverage_check.append(len(cover))
153+
assert sum(coverage_check) / len(coverage_check) > options.coverage, "Coverage check failed in single-ended mode"
154+
except Exception as e:
155+
pytest.fail(f"Test failed in single-ended mode with exception: {e}")

0 commit comments

Comments
 (0)