@@ -7,7 +7,7 @@ struct OverlapIterator{T}
77 interval:: UnitRange{Int}
88end
99
10- function Base. iteratorsize (:: Type{OverlapIterator{T}} ) where T
10+ function Base. IteratorSize (:: Type{OverlapIterator{T}} ) where T
1111 return Base. SizeUnknown ()
1212end
1313
@@ -45,43 +45,39 @@ mutable struct OverlapIteratorState
4545 record:: Record
4646end
4747
48- function Base. start (iter:: OverlapIterator )
49- refindex = findfirst (iter. reader . refseqnames , iter. refname )
48+ function Base. iterate (iter:: OverlapIterator )
49+ refindex = findfirst (isequal ( iter. refname) , iter. reader . refseqnames )
5050 if refindex == 0
5151 throw (ArgumentError (" sequence name $(iter. refname) is not found in the header" ))
5252 end
53- @assert ! isnull ( iter. reader. index)
54- chunks = GenomicFeatures. Indexes. overlapchunks (get ( iter. reader. index) . index, refindex, iter. interval)
53+ @assert iter. reader. index != = nothing
54+ chunks = GenomicFeatures. Indexes. overlapchunks (iter. reader. index. index, refindex, iter. interval)
5555 if ! isempty (chunks)
5656 seek (iter. reader, first (chunks). start)
5757 end
58- return OverlapIteratorState (refindex, chunks, 1 , Record ())
58+ state = OverlapIteratorState (refindex, chunks, 1 , Record ())
59+ return iterate (iter, state)
5960end
6061
61- function Base. done (iter:: OverlapIterator , state)
62- while state. chunkid ≤ endof (state. chunks)
62+ function Base. iterate (iter:: OverlapIterator , state)
63+ while state. chunkid ≤ lastindex (state. chunks)
6364 chunk = state. chunks[state. chunkid]
6465 while BGZFStreams. virtualoffset (iter. reader. stream) < chunk. stop
6566 read! (iter. reader, state. record)
6667 c = compare_intervals (state. record, (state. refindex, iter. interval))
6768 if c == 0
68- # overlapping
69- return false
69+ return copy (state. record), state
7070 elseif c > 0
7171 # no more overlapping records in this chunk since records are sorted
7272 break
7373 end
7474 end
7575 state. chunkid += 1
76- if state. chunkid ≤ endof (state. chunks)
76+ if state. chunkid ≤ lastindex (state. chunks)
7777 seek (iter. reader, state. chunks[state. chunkid]. start)
7878 end
7979 end
80- return true
81- end
82-
83- function Base. next (:: OverlapIterator , state)
84- return copy (state. record), state
80+ return nothing
8581end
8682
8783function compare_intervals (record:: Record , interval:: Tuple{Int,UnitRange{Int}} )
0 commit comments