Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ GenomicFeatures = "899a7d2d-5c61-547b-bef9-6698a8d05446"
Indexes = "4ffb77ac-cb80-11e8-1b35-4b78cc642f6d"
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"

[weakdeps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"

[extensions]
FileIOExt = "FileIO"

[compat]
Automa = "1"
BGZFStreams = "0.3"
Expand All @@ -30,6 +36,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FormatSpecimens = "3372ea36-2a1a-11e9-3eb7-996970b6ffbd"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"

[targets]
test = ["Distributions", "Documenter", "FormatSpecimens", "Random", "Test"]
test = ["Distributions", "Documenter", "FormatSpecimens", "Random", "Test", "FileIO"]
34 changes: 34 additions & 0 deletions ext/FileIOExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module FileIOExt

using BED, FileIO

function BED.fileio_load(filepath::File{format"BED"})

reader = open(BED.Reader, FileIO.filename(filepath))
records = try
records = [record for record in reader]
catch err
close(reader)
rethrow(err)
end
close(reader)

records
end

function BED.fileio_save(filepath::File{format"BED"}, records)

writer = open(BED.Writer, FileIO.filename(filepath))
try
for record in records
write(writer, record)
end
catch err
close(writer)
rethrow(err)
end
close(writer)
filepath
end

end
4 changes: 4 additions & 0 deletions src/BED.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ include("record.jl")
include("reader.jl")
include("writer.jl")

# placeholder for FileIO interface
fileio_load() = nothing
fileio_save() = nothing

end # module
25 changes: 23 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Distributions
using Documenter
using FormatSpecimens
using GenomicFeatures
using FileIO

import Random
import ColorTypes: RGB
Expand Down Expand Up @@ -130,7 +131,7 @@ end
continue
end

filepath = joinpath(dir_bed, filename(specimen))
filepath = joinpath(dir_bed, FormatSpecimens.filename(specimen))

@test check_bed_parse(filepath)

Expand All @@ -143,7 +144,7 @@ end
continue
end

filepath = joinpath(dir_bed, filename(specimen))
filepath = joinpath(dir_bed, FormatSpecimens.filename(specimen))

@test_throws Exception check_bed_parse(filepath)
end
Expand Down Expand Up @@ -285,6 +286,26 @@ end
@test isa(BED.Reader(path), BED.Reader)
end

@testset "FileIO" begin

dir_bed = path_of_format("BED")

for specimen in list_valid_specimens("BED")
if hastag(specimen, "gzip")
# skip compressed files
continue
end

mktempdir() do dir
filepath = joinpath(dir_bed, FormatSpecimens.filename(specimen))
records = FileIO.load(filepath)

FileIO.save(joinpath(dir, "tmp.bed"), records)
@test [record for record in open(BED.Reader, filepath)] == records
end
end
end

# Include doctests.
DocMeta.setdocmeta!(BED, :DocTestSetup, :(using BED); recursive=true)
doctest(BED; manual = false)
Expand Down
Loading