Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/pmotools/pmo_engine/pmo_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": [],
Expand All @@ -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
Expand Down Expand Up @@ -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"] = []
Expand All @@ -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)

Expand All @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions tests/test_pmo_engine/test_pmo_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading