Skip to content

Commit

Permalink
Updated qc_checkers/error_rate file to show if index reads
Browse files Browse the repository at this point in the history
  • Loading branch information
nkongenelly committed Feb 27, 2025
1 parent 8d1b752 commit c24929c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
19 changes: 13 additions & 6 deletions checkQC/qc_checkers/error_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,41 @@ def error_rate(
or error_threshold > warning_threshold
)

def _qualify_error(error, lane, read):
def _qualify_error(error, lane, read, is_index_read):
data = {
"lane": lane,
"read": read,
"error": error,
}
msg = "Error rate {error} > {threshold} on lane {lane} for read {read}."
read_or_index_text = "read (I)" if is_index_read else "read"
msg = "Error rate {error} > {threshold} on lane {lane} for {read_or_index_text} {read}."

match error:
case error if (np.isnan(error) or error == 0.) and not allow_missing_error_rate:
return QCErrorFatal(
f"Error rate is {error} on lane {lane} for read {read}. "
f"Error rate is {error} on lane {lane} for {read_or_index_text} {read}. "
"This may be because no PhiX was loaded on this lane. "
"Use \"allow_missing_error_rate: true\" to disable this error message.",
data=data,
)
case error if error_threshold != "unknown" and error > error_threshold:
data["threshold"] = error_threshold
return QCErrorFatal(msg.format(**data), data=data)
return QCErrorFatal(
msg.format(**data, read_or_index_text=read_or_index_text),
data=data
)
case error if warning_threshold != "unknown" and error > warning_threshold:
data["threshold"] = warning_threshold
return QCErrorWarning(msg.format(**data), data=data)
return QCErrorWarning(
msg.format(**data, read_or_index_text=read_or_index_text),
data=data
)

return [
qc_report
for lane, lane_data in qc_data.sequencing_metrics.items()
for read, read_data in lane_data["reads"].items()
if (qc_report := _qualify_error(read_data["mean_error_rate"], lane, read))
if (qc_report := _qualify_error(read_data["mean_error_rate"], lane, read, read_data["is_index"]))
]


14 changes: 7 additions & 7 deletions tests/qc_checkers/test_error_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ def qc_data_and_exp_val():
{
1: {
"reads": {
1: {"mean_error_rate": 0.},
2: {"mean_error_rate": 110.},
3: {"mean_error_rate": np.nan},
1: {"mean_error_rate": 0., "is_index": True},
2: {"mean_error_rate": 110., "is_index": False},
3: {"mean_error_rate": np.nan, "is_index": False},
},
},
2: {
"reads": {
1: {"mean_error_rate": 11.},
2: {"mean_error_rate": 110.},
3: {"mean_error_rate": 9.},
1: {"mean_error_rate": 11., "is_index": False},
2: {"mean_error_rate": 110., "is_index": False},
3: {"mean_error_rate": 9., "is_index": False},
},
},
}
),
{
1: {
1: QCErrorFatal(
"Error rate is 0.0 on lane 1 for read 1. "
"Error rate is 0.0 on lane 1 for read (I) 1. "
"This may be because no PhiX was loaded on this lane. "
"Use \"allow_missing_error_rate: true\" to disable this error message.",
data={"lane": 1, "read": 1, "error": 0.},
Expand Down

0 comments on commit c24929c

Please sign in to comment.