@@ -1697,7 +1697,7 @@ def test_alignments_left_right_subinterval(self):
16971697 ts = self .ts ()
16981698 # Use a custom reference and a subinterval [2, 8)
16991699 ref = "A" * 10
1700- got = list (ts .alignments (reference_sequence = ref [ 2 : 8 ] , left = 2 , right = 8 ))
1700+ got = list (ts .alignments (reference_sequence = ref , left = 2 , right = 8 ))
17011701 assert got == ["GAAAAA" , "AAAAAA" , "AAAAAA" , "NNNNNN" ]
17021702
17031703 def test_fasta_reference_sequence (self ):
@@ -1851,17 +1851,19 @@ def build_ts(self):
18511851 def test_whole_window_missing_at_ends (self ):
18521852 ts = self .build_ts ()
18531853 ref = "0123456789"
1854- # Node is isolated outside [3,7): expect missing there; inside use ref, with site overlay at 5
1854+ # Node is isolated outside [3,7): expect missing there; inside use ref,
1855+ # with site overlay at 5
18551856 got = list (ts .alignments (samples = [1 ], reference_sequence = ref ))
18561857 assert got == ["NNN34G6NNN" ]
18571858
18581859 def test_subwindow (self ):
18591860 ts = self .build_ts ()
18601861 ref = "0123456789"
18611862 # Request [2,8): expect missing at 2 and 7, ref inside, site overlay at 5
1862- got = list (ts .alignments (samples = [1 ], reference_sequence = ref [ 2 : 8 ] , left = 2 , right = 8 ))
1863+ got = list (ts .alignments (samples = [1 ], reference_sequence = ref , left = 2 , right = 8 ))
18631864 assert got == ["N34G6N" ]
18641865
1866+
18651867class TestMultiRootExample :
18661868 # 1.00┊ 4 5 ┊
18671869 # ┊ ┏┻┓ ┏┻┓ ┊
@@ -2234,17 +2236,17 @@ def test_reference_length_mismatch(self, ref_length):
22342236 tables = tskit .TableCollection (10 )
22352237 tables .reference_sequence .data = "A" * ref_length
22362238 ts = tables .tree_sequence ()
2237- if ref_length <= tables .sequence_length :
2238- with pytest .raises (ValueError , match = "shorter than" ):
2239- list (ts .alignments ())
2240- else :
2241- # Longer reference sequences are allowed
2239+ with pytest .raises (
2240+ ValueError , match = "must be equal to the tree sequence length"
2241+ ):
22422242 list (ts .alignments ())
22432243
22442244 @pytest .mark .parametrize ("ref" , ["" , "xy" ])
22452245 def test_reference_sequence_length_mismatch (self , ref ):
22462246 ts = self .simplest_ts ()
2247- with pytest .raises (ValueError , match = "shorter than" ):
2247+ with pytest .raises (
2248+ ValueError , match = "must be equal to the tree sequence length"
2249+ ):
22482250 list (ts .alignments (reference_sequence = ref ))
22492251
22502252 @pytest .mark .parametrize ("ref" , ["À" , "┃" , "α" ])
@@ -2308,7 +2310,9 @@ def test_bad_restricted(self):
23082310 tables = tskit .TableCollection (10 )
23092311 tables .reference_sequence .data = "A" * 7
23102312 ts = tables .tree_sequence ()
2311- with pytest .raises (ValueError , match = "sequence ends before" ):
2313+ with pytest .raises (
2314+ ValueError , match = "must be equal to the tree sequence length"
2315+ ):
23122316 list (ts .alignments (right = 8 ))
23132317
23142318 def test_no_samples_default (self ):
@@ -2342,16 +2346,20 @@ def test_reference_sequence_too_short_with_interval(self):
23422346 tables = tskit .TableCollection (10 )
23432347 tables .nodes .add_row (flags = tskit .NODE_IS_SAMPLE , time = 0 )
23442348 ts = tables .tree_sequence ()
2345- with pytest .raises (ValueError , match = "ends before the requested stop position" ):
2346- list (ts .alignments (reference_sequence = "A" * 5 , left = 2 , right = 8 )) # L=6
2349+ with pytest .raises (
2350+ ValueError , match = "must be equal to the tree sequence length"
2351+ ):
2352+ list (ts .alignments (reference_sequence = "A" * 5 , left = 2 , right = 8 ))
23472353
2348- def test_reference_sequence_too_long_with_interval (self ):
2349- # Explicit ref longer than [left,right) span should also error
2354+ def test_reference_sequence_length_must_match_sequence (self ):
2355+ # Explicit ref length must match full sequence length
23502356 tables = tskit .TableCollection (10 )
23512357 tables .nodes .add_row (flags = tskit .NODE_IS_SAMPLE , time = 0 )
23522358 ts = tables .tree_sequence ()
2353- with pytest .raises (ValueError , match = "ends before the requested stop position" ):
2354- list (ts .alignments (reference_sequence = "A" * 7 , left = 2 , right = 8 )) # L=6
2359+ with pytest .raises (
2360+ ValueError , match = "must be equal to the tree sequence length"
2361+ ):
2362+ list (ts .alignments (reference_sequence = "A" * 7 , left = 2 , right = 8 ))
23552363
23562364
23572365class TestAlignmentExamples :
@@ -2412,14 +2420,9 @@ def _reference_alignments(
24122420 else :
24132421 reference_sequence = missing_data_character * L
24142422 if len (reference_sequence ) != L :
2415- if interval .right == int (ts .sequence_length ):
2416- raise ValueError (
2417- "The reference sequence is shorter than the tree sequence length"
2418- )
2419- else :
2420- raise ValueError (
2421- "The reference sequence ends before the requested stop position"
2422- )
2423+ raise ValueError (
2424+ "The reference sequence must be equal to the tree sequence length"
2425+ )
24232426 ref_array = np .frombuffer (reference_sequence .encode ("ascii" ), dtype = np .int8 )
24242427 H , (first_site_id , last_site_id ) = ts ._haplotypes_array (
24252428 interval = interval ,
0 commit comments