Skip to content

Commit

Permalink
attempted to optimize, but little effect
Browse files Browse the repository at this point in the history
  • Loading branch information
lh3 committed May 11, 2020
1 parent 54ece74 commit db4ad26
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
|:-------|:---------|:--------|--------------------:|---------------------:|--------------------:|---------------------:|
|[bedcov\_c1\_cgr.c](bedcov/bedcov_c1_cgr.c) |C |[cgranges.h](lib/cgranges.h)| 5.5| 138.4 | 10.7| 19.1 |
|[bedcov\_nim1\_klib.nim](bedcov/bedcov_nim1_klib.nim)|Nim |[klib.nim](lib/klib.nim) | 16.9| 497.7 | 25.7| 69.1 |
|[bedcov\_jl1\_klib.jl](bedcov/bedcov_jl1_klib.jl) |Julia |[Klib.jl](lib/Klib.jl) | 48.7| 6769.9 | 77.1| 290.4 |
|[bedcov\_jl1\_klib.jl](bedcov/bedcov_jl1_klib.jl) |Julia |[Klib.jl](lib/Klib.jl) | 45.2| 3657.7 | 77.4| 288.8 |
|[bedcov\_js1\_k8.js](bedcov/bedcov_js1_k8.jl) |Javascript| | 75.4| 2219.9 | 87.2| 316.8 |
|[bedcov\_lua1.lua](bedcov/bedcov_lua1.lua) |LuaJIT | |174.1| 2668.0 |217.6| 364.6 |

Expand Down
3 changes: 2 additions & 1 deletion bedcov/bedcov_jl1_klib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ function main(args)
for ctg in keys(bed)
Klib.it_index!(bed[ctg])
end
b = Vector{Klib.Interval{Int}}()
for line in eachline(args[2])
t = split(line, "\t")
if get(bed, t[1], nothing) == nothing
println(t[1], "\t", t[2], "\t", t[3], "\t", 0, "\t", 0)
else
a = bed[t[1]]
st0, en0 = parse(Int, t[2]), parse(Int, t[3])
b = Klib.it_overlap(a, st0, en0)
Klib.it_overlap!(a, st0, en0, b)
cov_st, cov_en, cov = 0, 0, 0
for i = 1:length(b)
st1 = max(b[i].st, st0)
Expand Down
8 changes: 4 additions & 4 deletions lib/Klib.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Klib

export getopt, GzFile, close, Bufio, readbyte, readuntil!, FastxReader, FastxRecord
export Interval, it_index, it_overlap
export Interval, it_index, it_overlap!

#
# Getopt iterator
Expand Down Expand Up @@ -383,9 +383,10 @@ function it_index!(a::Vector{Interval{T}}) where T<:Number
end
end

function it_overlap(a::Vector{Interval{T}}, st::Int, en::Int) where T<:Number
b = Vector{Interval{T}}()
function it_overlap!(a::Vector{Interval{T}}, st::Int, en::Int, b::Vector{Interval{T}}) where T<:Number
resize!(b, 0)
stack = Vector{Tuple{Int,Int,Int}}()
sizehint!(stack, 128)
h = 0
while (1<<h <= length(a)) h += 1 end
h -= 1
Expand All @@ -412,7 +413,6 @@ function it_overlap(a::Vector{Interval{T}}, st::Int, en::Int) where T<:Number
push!(stack, (x + (1<<(h-1)), h - 1, 0))
end
end
return b
end

end # module Klib

0 comments on commit db4ad26

Please sign in to comment.