-
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
SamBuilder.add_single()
cannot create a record without sequence or base qualities
#211
Comments
@msto I've been confused by this too. Although the SAM spec has a "null value" for these attributes ( |
I have never seen pysam create an Though not well documented, my understanding is that pysam represents missing base qualities or sequences as I can verify this behavior with an example read that lacks both sequence and qualities: In [1]: from pysam import AlignmentFile
In [2]: sam = AlignmentFile("51510.sam")
In [3]: record = next(sam)
In [4]: record.query_qualities is None
Out[4]: True There are a number of differences between the in-memory representation of an alignment record and the ASCII rendering of a record in a SAM or BAM file, and I believe this is one of them. (FWIW I find this to be sensible behavior, otherwise there would be an excessive amount of boilerplate and easy-to-miss bugs, e.g. |
Here's the code in question. Query sequenceIf the length of the query sequence on the corresponding struct is zero, Query qualitiesAs far as I can tell (I'll admit to having some trouble tracing everything through |
And to the question at hand, I like the suggestion that instead of In [4]: record = builder.add_single(bases="*")
In [5]: record.query_sequence is None
Out[5]: False
In [6]: record.query_sequence
Out[6]: '*'
In [7]: record.query_qualities
Out[7]: array('B', [30]) |
^ Writing a Lines 1468 to 1469 in 7055cb5
Personally, in the future I'll probably be defensive when accessing these attributes and probably do both a |
Summary
When attempting to construct a test record with no query sequence or qualities, I found that
SamBuilder.add_single()
constructs a record with the default base/quality values instead of a record withNone
in these attributes.Suggested solution
I think this originates from using
None
as a sentinel value for "use the defaults" in this method.Instead, we could:
None
None
is specified as a value for these parameters, return a record wherequery_sequence
andquery_qualities
are NoneThe text was updated successfully, but these errors were encountered: