Skip to content

Commit 309acaf

Browse files
Expand merge unit tests for multi-ref and report paths
1 parent 7be3da1 commit 309acaf

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

tests/unit/test_merge.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,67 @@ def fake_gff_factory(gff_file=None, logger=None):
145145
report_output = report.getvalue()
146146
self.assertIn("# Number of WA loci", report_output)
147147
self.assertIn("Change_log", report_output)
148+
self.assertIn("OTHER", report_output)
149+
150+
def test_multi_ref_path_records_multi_ref_transcript_count(self):
151+
wa_root, wa_child = self._make_root_with_child("geneM", child_status="active", child_replace=["T1"])
152+
wa_gff = FakeGff([wa_root, wa_child])
153+
154+
ref_tx1 = {
155+
"line_type": "feature",
156+
"type": "mRNA",
157+
"line_status": "active",
158+
"line_raw": "raw-ref-tx1",
159+
"attributes": {"ID": "ref_tx1", "Name": "ref_tx1"},
160+
"children": [],
161+
"parents": [],
162+
}
163+
ref_tx2 = {
164+
"line_type": "feature",
165+
"type": "mRNA",
166+
"line_status": "active",
167+
"line_raw": "raw-ref-tx2",
168+
"attributes": {"ID": "ref_tx2", "Name": "ref_tx2"},
169+
"children": [],
170+
"parents": [],
171+
}
172+
ref_root = {
173+
"line_type": "feature",
174+
"type": "gene",
175+
"attributes": {"ID": "ref_gene"},
176+
"children": [ref_tx1, ref_tx2],
177+
}
178+
ref_tx1["parents"] = [[ref_root]]
179+
ref_tx2["parents"] = [[ref_root]]
180+
other_gff = FakeGff([ref_root, ref_tx1, ref_tx2])
181+
182+
class GroupsWithTagMap(FakeGroups):
183+
def __init__(self, **kwargs):
184+
super().__init__(**kwargs)
185+
self.mapName2ID["T1"] = "ref_tx1"
186+
187+
def fake_gff_factory(gff_file=None, logger=None):
188+
if gff_file == "WA_sorted.gff":
189+
return wa_gff
190+
if gff_file == "other_sorted.gff":
191+
return other_gff
192+
raise AssertionError(f"Unexpected gff file: {gff_file}")
193+
194+
report = io.StringIO()
195+
with mock.patch.object(merge.gff3_sort, "main", autospec=True), \
196+
mock.patch.object(merge.replace_OGS, "Groups", GroupsWithTagMap), \
197+
mock.patch.object(merge, "Gff3", side_effect=fake_gff_factory), \
198+
mock.patch.object(merge, "remove_files_from_list", autospec=True):
199+
merge.main(
200+
gff_file1="wa.gff3",
201+
gff_file2="other.gff3",
202+
output_gff="final.gff3",
203+
report_fh=report,
204+
)
205+
206+
report_output = report.getvalue()
207+
self.assertIn("ok", report_output)
208+
self.assertIn("# Number of transcripts with multi-ref replacement: 1", report_output)
148209

149210

150211
if __name__ == "__main__":

0 commit comments

Comments
 (0)