@@ -563,6 +563,7 @@ cdef AlignedSegment makeAlignedSegment(bam1_t *src,
563
563
cdef AlignedSegment dest = AlignedSegment.__new__ (AlignedSegment)
564
564
dest._delegate = bam_dup1(src)
565
565
dest.header = header
566
+ dest._clear_cached_query_sequences()
566
567
dest._clear_cached_query_qualities()
567
568
return dest
568
569
@@ -947,9 +948,8 @@ cdef class AlignedSegment:
947
948
self ._delegate.core.mpos = - 1
948
949
949
950
# caching for selected fields
951
+ self ._clear_cached_query_sequences()
950
952
self ._clear_cached_query_qualities()
951
- self .cache_query_sequence = None
952
- self .cache_query_alignment_sequence = None
953
953
954
954
self .header = header
955
955
@@ -1097,6 +1097,7 @@ cdef class AlignedSegment:
1097
1097
cdef AlignedSegment dest = cls .__new__ (cls )
1098
1098
dest._delegate = < bam1_t* > calloc(1 , sizeof(bam1_t))
1099
1099
dest.header = header
1100
+ dest._clear_cached_query_sequences()
1100
1101
dest._clear_cached_query_qualities()
1101
1102
1102
1103
cdef kstring_t line
@@ -1379,6 +1380,10 @@ cdef class AlignedSegment:
1379
1380
def __set__ (self , isize ):
1380
1381
self ._delegate.core.isize = isize
1381
1382
1383
+ cdef void _clear_cached_query_sequences(self ):
1384
+ self .cache_query_sequence = NotImplemented
1385
+ self .cache_query_alignment_sequence = NotImplemented
1386
+
1382
1387
property query_sequence :
1383
1388
""" read sequence bases, including :term:`soft clipped` bases
1384
1389
(None if not present).
@@ -1396,14 +1401,15 @@ cdef class AlignedSegment:
1396
1401
has aligned the read to the reverse strand.)
1397
1402
"""
1398
1403
def __get__ (self ):
1399
- if self .cache_query_sequence:
1404
+ if self .cache_query_sequence is not NotImplemented :
1400
1405
return self .cache_query_sequence
1401
1406
1402
1407
cdef bam1_t * src
1403
1408
cdef char * s
1404
1409
src = self ._delegate
1405
1410
1406
1411
if src.core.l_qseq == 0 :
1412
+ self .cache_query_sequence = None
1407
1413
return None
1408
1414
1409
1415
self .cache_query_sequence = force_str(getSequenceInRange(
@@ -1460,7 +1466,7 @@ cdef class AlignedSegment:
1460
1466
p = pysam_bam_get_qual(src)
1461
1467
memset(p, 0xff , l)
1462
1468
1463
- self .cache_query_sequence = force_str(seq )
1469
+ self ._clear_cached_query_sequences( )
1464
1470
self ._clear_cached_query_qualities()
1465
1471
1466
1472
cdef void _clear_cached_query_qualities(self ):
@@ -1765,7 +1771,7 @@ cdef class AlignedSegment:
1765
1771
"""
1766
1772
1767
1773
def __get__ (self ):
1768
- if self .cache_query_alignment_sequence:
1774
+ if self .cache_query_alignment_sequence is not NotImplemented :
1769
1775
return self .cache_query_alignment_sequence
1770
1776
1771
1777
cdef bam1_t * src
@@ -1774,13 +1780,13 @@ cdef class AlignedSegment:
1774
1780
src = self ._delegate
1775
1781
1776
1782
if src.core.l_qseq == 0 :
1783
+ self .cache_query_alignment_sequence = None
1777
1784
return None
1778
1785
1779
1786
start = getQueryStart(src)
1780
1787
end = getQueryEnd(src)
1781
1788
1782
- self .cache_query_alignment_sequence = force_str(
1783
- getSequenceInRange(src, start, end))
1789
+ self .cache_query_alignment_sequence = force_str(getSequenceInRange(src, start, end))
1784
1790
return self .cache_query_alignment_sequence
1785
1791
1786
1792
property query_alignment_qualities :
0 commit comments