-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sum_of_base_qualities
raises TypeError
if the received record has no base qualities
#210
Comments
I would be in favor of (1), because then the following works as expected and does not require additional boilerplate to guard against an exception: record.set_tag("ms", sum_of_base_qualities(record))
|
sum_of_base_qualities
raises TypeError
if the received record is unmappedsum_of_base_qualities
raises TypeError
if the received record has no base qualities
Note that testing this issue will be blocked by #211 |
After empirically testing the results of I think it's therefore most appropriate if the function returns 0 in that case. |
@clintval I'm carrying over your question from the client repo about why mypy didn't catch this. I also would have expected mypy to catch this. Pysam types In my IDE (VS Code), the pylance/pyright extension correctly infers the type of However, when including fgpyo/sam/__init__.py:867: note: Revealed type is "array.array[Any]" It's obviously a very simple function and I don't see anything that would be narrowing the type. This might be a bug in mypy? |
Summary
sum_of_base_qualities()
accesses the input record'squery_qualities
without first checking if the record has base qualities.When the record does not have base qualities, this attribute is
None
, and the attempted comprehension fails with aTypeError: 'NoneType' object is not iterable
.fgpyo/fgpyo/sam/__init__.py
Lines 849 to 863 in b0b4227
Suggested solution
After empirically testing the results of
samtools fixmate -m
on the real read pair that originated this error, I found that samtools will assign a mate score of 0 when the read has no base qualities. (h/t @clintval for the suggestion)I think it's therefore most appropriate if the function returns 0 in that case.
Original suggestion
Either of the following could be appropriate:1. Changing the signature of the function to returnint | None
, and returningNone
when the input record has no base qualities2. RaisingValueError
with a more specific error message when the input record has no base qualitiesThe text was updated successfully, but these errors were encountered: