From 374e14ee980deee4c0f9b5efe47e6ed729c95d81 Mon Sep 17 00:00:00 2001 From: Nicholas Hathaway Date: Mon, 29 Jun 2026 10:38:47 -0700 Subject: [PATCH 1/2] small fixes for mutation of input data for filter_pmo_by_target_ids; --- src/pmotools/pmo_engine/pmo_processor.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pmotools/pmo_engine/pmo_processor.py b/src/pmotools/pmo_engine/pmo_processor.py index cef95fb..651600a 100644 --- a/src/pmotools/pmo_engine/pmo_processor.py +++ b/src/pmotools/pmo_engine/pmo_processor.py @@ -646,8 +646,6 @@ def filter_pmo_by_library_sample_ids(pmodata, library_sample_ids: set[int]): if "targeted_genomes" in pmodata: pmo_out["targeted_genomes"] = copy.deepcopy(pmodata["targeted_genomes"]) - if "read_counts_by_stage" in pmodata: - pmo_out["read_counts_by_stage"] = [] # need to update read_counts_by_stage, library_sample_info, specimen_info, detected_microhaplotypes # specimen_info @@ -703,6 +701,7 @@ def filter_pmo_by_library_sample_ids(pmodata, library_sample_ids: set[int]): pmo_out["detected_microhaplotypes"].append(new_detected_microhaplotypes) # read_counts_by_stage if "read_counts_by_stage" in pmodata: + pmo_out["read_counts_by_stage"] = [] for read_count in pmodata["read_counts_by_stage"]: new_read_count = { "read_counts_by_library_sample_by_stage": [], @@ -725,6 +724,7 @@ def filter_pmo_by_library_sample_ids(pmodata, library_sample_ids: set[int]): ]["library_sample_id"] = library_id_index_key[ sample["library_sample_id"] ] + pmo_out["read_counts_by_stage"].append(new_read_count) return pmo_out @staticmethod @@ -884,11 +884,12 @@ def filter_pmo_by_target_ids(pmodata, target_ids: set[int]): pmo_out["representative_microhaplotypes"]["targets"] ) # update new target_id index - microhap_info["target_id"] = target_info_index_key[ + microhap_info_copy = copy.deepcopy(microhap_info) + microhap_info_copy["target_id"] = target_info_index_key[ microhap_info["target_id"] ] pmo_out["representative_microhaplotypes"]["targets"].append( - copy.deepcopy(microhap_info) + microhap_info_copy ) # representative_microhaplotypes pmo_out["detected_microhaplotypes"] = [] @@ -908,10 +909,11 @@ def filter_pmo_by_target_ids(pmodata, target_ids: set[int]): for target in sample["target_results"]: if target["mhaps_target_id"] in mhaps_target_id_new_key: # update with new mhaps_target_id id - target["mhaps_target_id"] = mhaps_target_id_new_key[ + target_copy = copy.deepcopy(target) + target_copy["mhaps_target_id"] = mhaps_target_id_new_key[ target["mhaps_target_id"] ] - new_sample["target_results"].append(copy.deepcopy(target)) + new_sample["target_results"].append(target_copy) new_detected_microhaplotypes["library_samples"].append(new_sample) pmo_out["detected_microhaplotypes"].append(new_detected_microhaplotypes) @@ -938,11 +940,12 @@ def filter_pmo_by_target_ids(pmodata, target_ids: set[int]): for target in sample["read_counts_for_targets"]: if target["target_id"] in target_ids: # update with new target_id index - target["target_id"] = target_info_index_key[ + target_copy = copy.deepcopy(target) + target_copy["target_id"] = target_info_index_key[ target["target_id"] ] new_samples["read_counts_for_targets"].append( - copy.deepcopy(target) + target_copy ) new_read_counts_by_bioid[ "read_counts_by_library_sample_by_stage" From 6ad954b3d6e5c6436f662f8f03f06829d9e41cd1 Mon Sep 17 00:00:00 2001 From: Nicholas Hathaway Date: Mon, 29 Jun 2026 11:08:18 -0700 Subject: [PATCH 2/2] update the hashes because now reads_by_stage is now properly exported so the old hashes were wrong; --- tests/test_pmo_engine/test_pmo_processor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_pmo_engine/test_pmo_processor.py b/tests/test_pmo_engine/test_pmo_processor.py index 2c4a41b..bce394b 100755 --- a/tests/test_pmo_engine/test_pmo_processor.py +++ b/tests/test_pmo_engine/test_pmo_processor.py @@ -358,7 +358,7 @@ def test_filter_pmo_by_library_sample_ids(self): ) with open(output_fnp, "w") as f: json.dump(pmo_data_select_targets, f) - self.assertEqual("4a2c7b9d84322cc43adf2b9f0c518244", md5sum_of_fnp(output_fnp)) + self.assertEqual("36d5cb8a79962707374fae86ba1a6f90", md5sum_of_fnp(output_fnp)) # check pmo extracted against PMO schema checker = PMOChecker(self.pmo_jsonschema_data) checker.validate_pmo_json(pmo_data_select_targets) @@ -374,7 +374,7 @@ def test_filter_pmo_by_library_sample_names(self): ) with open(output_fnp, "w") as f: json.dump(pmo_data_select_library_sample_names, f) - self.assertEqual("ffdaeb6b57ed9a5c51e56cfaa4621796", md5sum_of_fnp(output_fnp)) + self.assertEqual("6bd4e6367a62f1eb3c73f481a5ae9013", md5sum_of_fnp(output_fnp)) # check pmo extracted against PMO schema checker = PMOChecker(self.pmo_jsonschema_data) checker.validate_pmo_json(pmo_data_select_library_sample_names) @@ -388,7 +388,7 @@ def test_filter_pmo_by_specimen_ids(self): ) with open(output_fnp, "w") as f: json.dump(pmo_data_select_targets, f) - self.assertEqual("f3dd2e0aee9afa82336ff48475a3c69c", md5sum_of_fnp(output_fnp)) + self.assertEqual("664de0f14180de852f3f5d8942454004", md5sum_of_fnp(output_fnp)) # check pmo extracted against PMO schema checker = PMOChecker(self.pmo_jsonschema_data) checker.validate_pmo_json(pmo_data_select_targets) @@ -402,7 +402,7 @@ def test_filter_pmo_by_specimen_names(self): ) with open(output_fnp, "w") as f: json.dump(pmo_data_select_targets, f) - self.assertEqual("f3dd2e0aee9afa82336ff48475a3c69c", md5sum_of_fnp(output_fnp)) + self.assertEqual("664de0f14180de852f3f5d8942454004", md5sum_of_fnp(output_fnp)) # check pmo extracted against PMO schema checker = PMOChecker(self.pmo_jsonschema_data) checker.validate_pmo_json(pmo_data_select_targets) @@ -420,7 +420,7 @@ def test_extract_from_pmo_samples_with_meta_groupings(self): with open(output_fnp, "w") as f: json.dump(pmo_data_select_meta, f) - self.assertEqual("f0f67e399885824a7aa318ead8b3d09c", md5sum_of_fnp(output_fnp)) + self.assertEqual("9deb0bccc0017593697190d45ae6c0a4", md5sum_of_fnp(output_fnp)) # check pmo extracted against PMO schema checker = PMOChecker(self.pmo_jsonschema_data) checker.validate_pmo_json(pmo_data_select_meta)