|
1 | 1 | """Run liftover tests.""" |
2 | 2 |
|
| 3 | +import re |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
3 | 7 | from agct import Assembly, Converter, LiftoverResult, Strand |
4 | 8 |
|
5 | 9 |
|
6 | 10 | def test_hg19_to_hg38(): |
7 | 11 | """Test hg19 to hg38 lifter.""" |
8 | 12 | converter = Converter(Assembly.HG19, Assembly.HG38) |
9 | 13 |
|
10 | | - result = converter.convert_coordinate("chr7", 140439611) |
| 14 | + result = converter.convert_coordinate("chr7", 140439611, 140439611) |
11 | 15 | assert len(result) == 1 |
12 | | - assert result[0] == LiftoverResult("chr7", 140739811, Strand.POSITIVE) |
| 16 | + assert result[0] == LiftoverResult("chr7", 140739811, 140739811, Strand.POSITIVE) |
13 | 17 |
|
14 | | - result = converter.convert_coordinate("chr7", 140439746) |
| 18 | + result = converter.convert_coordinate("chr7", 140439746, 140439746) |
15 | 19 | assert len(result) == 1 |
16 | | - assert result[0] == LiftoverResult("chr7", 140739946, Strand.POSITIVE) |
| 20 | + assert result[0] == LiftoverResult("chr7", 140739946, 140739946, Strand.POSITIVE) |
17 | 21 |
|
18 | | - result = converter.convert_coordinate("chr7", 140439703) |
| 22 | + result = converter.convert_coordinate("chr7", 140439703, 140439703) |
19 | 23 | assert len(result) == 1 |
20 | | - assert result[0] == LiftoverResult("chr7", 140739903, Strand.POSITIVE) |
| 24 | + assert result[0] == LiftoverResult("chr7", 140739903, 140739903, Strand.POSITIVE) |
21 | 25 |
|
22 | | - result = converter.convert_coordinate("chr7", 140453136) |
| 26 | + result = converter.convert_coordinate("chr7", 140453136, 140453136) |
23 | 27 | assert len(result) == 1 |
24 | | - assert result[0] == LiftoverResult("chr7", 140753336, Strand.POSITIVE) |
| 28 | + assert result[0] == LiftoverResult("chr7", 140753336, 140753336, Strand.POSITIVE) |
25 | 29 |
|
26 | | - result = converter.convert_coordinate("chr1", 206072707) |
| 30 | + result = converter.convert_coordinate("chr1", 206072707, 206072708) |
27 | 31 | assert len(result) == 1 |
28 | | - assert result[0] == LiftoverResult("chr1", 206268644, Strand.NEGATIVE) |
| 32 | + assert result[0] == LiftoverResult("chr1", 206268644, 206268643, Strand.NEGATIVE) |
29 | 33 |
|
30 | 34 | # coordinate exceeds bounds |
31 | | - result = converter.convert_coordinate("chr7", 14040053136) |
| 35 | + result = converter.convert_coordinate("chr7", 14040053136, 14040053136) |
32 | 36 | assert result == [] |
33 | 37 |
|
34 | 38 |
|
35 | 39 | def test_hg38_to_hg19(): |
36 | 40 | """Test hg38 to hg19 lifter.""" |
37 | 41 | converter = Converter(Assembly.HG38, Assembly.HG19) |
38 | 42 |
|
39 | | - result = converter.convert_coordinate("chr7", 140739811) |
| 43 | + result = converter.convert_coordinate("chr7", 140739811, 140739811) |
| 44 | + assert len(result) == 1 |
| 45 | + assert result[0] == LiftoverResult("chr7", 140439611, 140439611, Strand.POSITIVE) |
| 46 | + |
| 47 | + result = converter.convert_coordinate("chr7", 140759820, 140759820) |
| 48 | + assert len(result) == 1 |
| 49 | + assert result[0] == LiftoverResult("chr7", 140459620, 140459620, Strand.POSITIVE) |
| 50 | + |
| 51 | + result = converter.convert_coordinate("chr7", 60878240, 60878240) |
40 | 52 | assert len(result) == 1 |
41 | | - assert result[0] == LiftoverResult("chr7", 140439611, Strand.POSITIVE) |
| 53 | + assert result[0] == LiftoverResult("chr7", 61646115, 61646115, Strand.POSITIVE) |
42 | 54 |
|
43 | | - result = converter.convert_coordinate("chr7", 140759820) |
| 55 | + result = converter.convert_coordinate("chr7", 60878240, 60878240) |
44 | 56 | assert len(result) == 1 |
45 | | - assert result[0] == LiftoverResult("chr7", 140459620, Strand.POSITIVE) |
| 57 | + assert result[0] == LiftoverResult("chr7", 61646115, 61646115, Strand.POSITIVE) |
46 | 58 |
|
47 | | - result = converter.convert_coordinate("chr7", 60878240) |
| 59 | + result = converter.convert_coordinate("chr7", 60878240, 60878245) |
48 | 60 | assert len(result) == 1 |
49 | | - assert result[0] == LiftoverResult("chr7", 61646115, Strand.POSITIVE) |
| 61 | + assert result[0] == LiftoverResult("chr7", 61646115, 61646120, Strand.POSITIVE) |
| 62 | + |
| 63 | + |
| 64 | +def test_interval_input(): |
| 65 | + """Test that invalid intervals raise errors""" |
| 66 | + converter = Converter(Assembly.HG38, Assembly.HG19) |
| 67 | + |
| 68 | + with pytest.raises( |
| 69 | + ValueError, |
| 70 | + match=re.escape( |
| 71 | + "`end` must be less than `start` on the positive strand: start=140739811, end=140739809" |
| 72 | + ), |
| 73 | + ): |
| 74 | + converter.convert_coordinate("chr7", 140739811, 140739809) |
| 75 | + |
| 76 | + with pytest.raises( |
| 77 | + ValueError, |
| 78 | + match=re.escape( |
| 79 | + "`start` must be less than `end` on the negative strand: start=206268644, end=206268645" |
| 80 | + ), |
| 81 | + ): |
| 82 | + converter.convert_coordinate( |
| 83 | + "chr1", 206268644, 206268645, strand=Strand.NEGATIVE |
| 84 | + ) |
0 commit comments