Skip to content

Commit

Permalink
Add Base.print(::IO, ::Index)
Browse files Browse the repository at this point in the history
This allows the user to turn an `Index` into a string easily, and also makes it
easier to test the indices.
  • Loading branch information
jakobnissen committed Sep 24, 2023
1 parent 36e42cd commit d0eb7ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/fasta/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ function Base.write(io::IO, index::Index)
n
end

function Base.print(io::IO, index::Index)
buffer = IOBuffer()
write(buffer, index)
String(take!(buffer))
end

index_fasta_actions = Dict(
:mark => :(@mark),
:countline => :(linenum += 1),
Expand Down Expand Up @@ -357,4 +363,4 @@ function faidx(fnapath::AbstractString, faidxpath::AbstractString; check::Bool=t
index
end

faidx(path::AbstractString; check::Bool=true) = faidx(path, path * ".fai"; check=check)
faidx(path::AbstractString; check::Bool=true) = faidx(path, path * ".fai"; check=check)
3 changes: 2 additions & 1 deletion test/fasta/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function test_same_index(a::Index, b::Index)
@test a.lengths == b.lengths
@test a.offsets == b.offsets
@test a.encoded_linebases == b.encoded_linebases
@test string(a) == string(b)
end

@testset "Parsing index" begin
Expand Down Expand Up @@ -253,4 +254,4 @@ UUGC
@test extract(reader, "seq1", 3:5) == "GAA"
end

end # testset Index
end # testset Index

0 comments on commit d0eb7ea

Please sign in to comment.