From 723dd5ba075b9f44f149e30deb8a20452f986917 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Sun, 24 Sep 2023 17:17:04 +0200 Subject: [PATCH] Add Base.print(::IO, ::Index) This allows the user to turn an `Index` into a string easily, and also makes it easier to test the indices. --- src/fasta/index.jl | 8 +++++++- test/fasta/index.jl | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/fasta/index.jl b/src/fasta/index.jl index 4e770fe..e6a4c35 100644 --- a/src/fasta/index.jl +++ b/src/fasta/index.jl @@ -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), @@ -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) \ No newline at end of file +faidx(path::AbstractString; check::Bool=true) = faidx(path, path * ".fai"; check=check) diff --git a/test/fasta/index.jl b/test/fasta/index.jl index c6506eb..41aa320 100644 --- a/test/fasta/index.jl +++ b/test/fasta/index.jl @@ -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 @@ -253,4 +254,4 @@ UUGC @test extract(reader, "seq1", 3:5) == "GAA" end -end # testset Index \ No newline at end of file +end # testset Index