Skip to content

Commit ea7c372

Browse files
committed
Write the contents of the stage1 JSON file only once
1 parent fe65bc9 commit ea7c372

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

meteor/counter.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,17 @@ def get_aligned_nucleotides(self, element: AlignedSegment) -> Iterator[int]:
8989
assert element.cigartuples is not None
9090
yield from (item[1] for item in element.cigartuples if item[0] < 3)
9191

92-
def set_counter_config(self, counted_reads: float, count_file: Path) -> dict:
92+
def set_counter_config(self, total_read_count: int, counted_reads: float, count_file: Path) -> dict:
9393
"""Save in the json essential info
94-
:param counted_read: (float) Number of reads counted
94+
:param total_read_count: (int) Number of reads mapped on the catalogue
95+
:param counted_read: (float) Number of reads counted after filtering
9596
:param count_file: (Path) Count file
9697
:return: (Dict) dictionnary data
9798
"""
9899
return {
99100
"counting": {
100101
"counted_reads": counted_reads,
102+
"final_mapping_rate": round(100 * counted_reads / total_read_count, 2),
101103
"identity_threshold": round(self.identity_threshold, 2),
102104
"count_file": count_file.name,
103105
}
@@ -452,7 +454,8 @@ def launch_counting(
452454
abundance = self.compute_abs_total(database, genes)
453455
self.write_stat(count_file, abundance, database)
454456
counted_reads = len(reads)
455-
config = self.set_counter_config(counted_reads, count_file)
457+
total_read_count = stage1_json_data["mapping"]["total_read_count"]
458+
config = self.set_counter_config(total_read_count, counted_reads, count_file)
456459
stage1_json_data.update(config)
457460
self.save_config(stage1_json_data, stage1_json)
458461
if self.keep_filtered_alignments:
@@ -556,20 +559,6 @@ def execute(self) -> None:
556559
stage1_json_data,
557560
stage1_json,
558561
)
559-
# Add final mapping rate
560-
stage1_json_data = self.read_json(stage1_json)
561-
stage1_json_data["counting"]["final_mapping_rate"] = (
562-
round(
563-
stage1_json_data["counting"]["counted_reads"]
564-
/ stage1_json_data["mapping"]["total_read_count"]
565-
* 100,
566-
2
567-
)
568-
)
569-
self.save_config(
570-
stage1_json_data,
571-
stage1_json
572-
)
573562
logging.info("Completed counting in %f seconds", perf_counter() - start)
574563
if not self.keep_all_alignments:
575564
logging.info(

0 commit comments

Comments
 (0)