Skip to content

Commit

Permalink
Loosen type requirements for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed May 1, 2023
1 parent 5d6c21e commit a4af60a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/coverage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ GenomicIntervalCollection{GenomicInterval{UInt32}} with 5 intervals:
"""
function coverage(stream, groupname_isless::Function=isless)
cov = GenomicIntervalCollection{UInt32}()
return coverage!(cov, stream, groupname_isless)
end

function coverage!(cov::GenomicIntervalCollection{GenomicInterval{N}}, stream, groupname_isless::Function=isless) where N <: Integer
lasts = Int64[]

stream_next = iterate(stream)
Expand Down Expand Up @@ -84,7 +88,7 @@ function coverage(stream, groupname_isless::Function=isless)
current_coverage -= 1
else
@assert pos >= coverage_first
push!(cov, GenomicInterval{UInt32}(coverage_groupname, coverage_first, pos, STRAND_BOTH, current_coverage))
push!(cov, GenomicInterval{N}(coverage_groupname, coverage_first, pos, STRAND_BOTH, current_coverage))
current_coverage -= 1
coverage_first = pos + 1
end
Expand All @@ -96,7 +100,7 @@ function coverage(stream, groupname_isless::Function=isless)
current_coverage += 1
else
if current_coverage > 0
push!(cov, GenomicInterval{UInt32}(coverage_groupname, coverage_first, leftposition(interval) - 1, STRAND_BOTH, current_coverage))
push!(cov, GenomicInterval{N}(coverage_groupname, coverage_first, leftposition(interval) - 1, STRAND_BOTH, current_coverage))
end
current_coverage += 1
coverage_first = leftposition(interval)
Expand All @@ -118,14 +122,14 @@ function coverage(stream, groupname_isless::Function=isless)
end

# Helper function for coverage. Process remaining interval end points after all intervals have been read.
function coverage_process_lasts_heap!(cov::GenomicIntervalCollection{GenomicInterval{UInt32}}, current_coverage, coverage_groupname, coverage_first, lasts)
function coverage_process_lasts_heap!(cov::GenomicIntervalCollection{GenomicInterval{N}}, current_coverage, coverage_groupname, coverage_first, lasts) where N <: Integer
while !isempty(lasts)
pos = DataStructures.heappop!(lasts)
if pos == coverage_first - 1
current_coverage -= 1
else
@assert pos >= coverage_first
push!(cov, GenomicInterval{UInt32}(coverage_groupname, coverage_first, pos, STRAND_BOTH, current_coverage))
push!(cov, GenomicInterval{N}(coverage_groupname, coverage_first, pos, STRAND_BOTH, current_coverage))
current_coverage -= 1
coverage_first = pos + 1
end
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ end #testset Constructor Conversions
end

@test sort(simple_coverage(intervals)) == sort(collect(coverage(ic)))

# Check coverage operation with different Integer type.
cov = GenomicIntervalCollection{GenomicInterval{Int64}}()
@test sort(simple_coverage(intervals)) == collect(GenomicFeatures.coverage!(cov, ic))
end

@testset "eachoverlap" begin
Expand Down

0 comments on commit a4af60a

Please sign in to comment.