From ca0340bf3824c52f21e2e2feb9f41a14ddba94ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 27 Feb 2019 15:25:46 +1100 Subject: [PATCH 01/10] Return data when saving Returning the data when saving allows for piping like records = f(data) |> save(file). --- src/BedgraphFiles.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/BedgraphFiles.jl b/src/BedgraphFiles.jl index 7cecf8d..ca8e76e 100644 --- a/src/BedgraphFiles.jl +++ b/src/BedgraphFiles.jl @@ -111,11 +111,14 @@ function Vector{Bedgraph.Record}(x::T) :: Vector{Bedgraph.Record} where {T} #TOD end end -function save(file::BedgraphFileFormat, header::Bedgraph.BedgraphHeader, records::Vector{Bedgraph.Record}) +function save(file::BedgraphFileFormat, header::Bedgraph.BedgraphHeader, records::Vector{Bedgraph.Record}) :: Vector{Bedgraph.Record} + write(file.filename, header, records) + + return records #Note: this return is useful when piping (e.g., records = some_operation | save(file)). end -function save(file::BedgraphFileFormat, records::Vector{Bedgraph.Record}; bump_forward = true) +function save(file::BedgraphFileFormat, records::Vector{Bedgraph.Record}; bump_forward = true) :: Vector{Bedgraph.Record} sort!(records) @@ -130,7 +133,9 @@ function save(file::BedgraphFileFormat, data; bump_forward = true) records = Vector{Bedgraph.Record}(it) - return save(file, records, bump_forward = bump_forward) + save(file, records, bump_forward = bump_forward) + + return data #Note: this return is usful when piping. end end # module From 7fdf4fcf3712f87de72392fe38e74e8295224e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Mon, 28 Jan 2019 11:54:40 +1100 Subject: [PATCH 02/10] Improve constants bag --- test/runtests.jl | 56 ++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 248b6dc..6fb073e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,22 +13,33 @@ using Logging # old_logger = global_logger(ConsoleLogger(stdout, Logging.Debug)) module Bag + +using Bedgraph + const chroms = ["chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19"] const firsts = [49302000, 49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400] const lasts = [49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400, 49304700] const values = [-1.0, -0.75, -0.50, -0.25, 0.0, 0.25, 0.50, 0.75, 1.00] +const record = Bedgraph.Record("chr1", 1, 1, 0) +const records = convert(Vector{Bedgraph.Record}, Bag.chroms, Bag.firsts, Bag.lasts, Bag.values) + const file = joinpath(@__DIR__, "data.bedgraph") const file_headerless = joinpath(@__DIR__, "data-headerless.bedgraph") + +const tmp_output_path = tempname() * ".bedgraph" + end # module Bag + +using .Bag + + @testset "BedgraphFiles" begin @test isfile(Bag.file) @test isfile(Bag.file_headerless) -tmp_output_path = tempname() * ".bedgraph" - # Load tests. loader = load(Bag.file) @test IteratorInterfaceExtensions.isiterable(loader) == true @@ -44,37 +55,36 @@ loader_from_headerless = load(Bag.file_headerless) loaded_from_headerless = Vector{Bedgraph.Record}(loader_from_headerless) @test Vector{Bedgraph.Record} == typeof(loaded_from_headerless) -records = convert(Vector{Bedgraph.Record}, Bag.chroms, Bag.firsts, Bag.lasts, Bag.values) -@test IteratorInterfaceExtensions.isiterable(records) == true -@test TableTraits.isiterabletable(records) == true +@test IteratorInterfaceExtensions.isiterable(Bag.records) == true +@test TableTraits.isiterabletable(Bag.records) == true -@test records == loaded -@test records == loaded_from_headerless +@test Bag.records == loaded +@test Bag.records == loaded_from_headerless # Save and load from Vector{Bedgraph.Record}. -save(tmp_output_path, records) +save(Bag.tmp_output_path, Bag.records) @debug "direct load into Vector{Bedgraph.Record} - commencing" -@test records == Vector{Bedgraph.Record}(load(tmp_output_path)) +@test Bag.records == Vector{Bedgraph.Record}(load(Bag.tmp_output_path)) @debug "direct load into Vector{Bedgraph.Record} - complete" -@test records == load(tmp_output_path) |> Vector{Bedgraph.Record} +@test Bag.records == load(Bag.tmp_output_path) |> Vector{Bedgraph.Record} -# Save using query. -records |> save(tmp_output_path) -@test records == Vector{Bedgraph.Record}(load(tmp_output_path)) -@test records == load(tmp_output_path) |> Vector{Bedgraph.Record} +# Save usign query. +Bag.records |> save(Bag.tmp_output_path) +@test Bag.records == Vector{Bedgraph.Record}(load(Bag.tmp_output_path)) +@test Bag.records == load(Bag.tmp_output_path) |> Vector{Bedgraph.Record} # Check return of data from save method. -@test records == records |> save(tmp_output_path) +@test Bag.records == Bag.records |> save(Bag.tmp_output_path) # Check piping/continuations through Query.jl. -load("data.bedgraph") |> @filter(_.chrom == "chr19" && _.first > 49302900 && _.last < 49303800) |> save(tmp_output_path) -@test [Bedgraph.Record("chr19", 49303200, 49303500, 0.0)] == load(tmp_output_path) |> Vector{Bedgraph.Record} +load("data.bedgraph") |> @filter(_.chrom == "chr19" && _.first > 49302900 && _.last < 49303800) |> save(Bag.tmp_output_path) +@test [Bedgraph.Record("chr19", 49303200, 49303500, 0.0)] == load(Bag.tmp_output_path) |> Vector{Bedgraph.Record} @testset "DataFrames" begin # DataFrame from Vector{Bedgraph.Record}. -df = DataFrame(records) +df = DataFrame(Bag.records) @test typeof(df) == DataFrame @test size(df) == (9,4) @@ -84,7 +94,7 @@ df = DataFrame(records) @test df[:last] == Bag.lasts @test df[:value] == Bag.values -@test DataFrame(records) == records |> DataFrame +@test DataFrame(Bag.records) == Bag.records |> DataFrame # DataFrame from bedGraph file. df2 = DataFrame(loader) @@ -112,11 +122,11 @@ df3 = DataFrame(loader_from_headerless) @test DataFrame(loader_from_headerless) == loader_from_headerless |> DataFrame # Save and load from DataFrame. -save(tmp_output_path, df) -@test df == load(tmp_output_path) |> DataFrame +save(Bag.tmp_output_path, df) +@test df == load(Bag.tmp_output_path) |> DataFrame -df |> save(tmp_output_path) -@test df == load(tmp_output_path) |> DataFrame +df |> save(Bag.tmp_output_path) +@test df == load(Bag.tmp_output_path) |> DataFrame end # test DataFrames From 049f1a783910301b8ace392ba28a0a172245309a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Mon, 28 Jan 2019 11:58:40 +1100 Subject: [PATCH 03/10] Extract DataFrames as an integration --- Manifest.toml | 100 --------------------------- Project.toml | 7 +- REQUIRE | 1 - src/BedgraphFiles.jl | 22 ++---- src/integrations/DataFrames.jl | 16 +++++ test/REQUIRE | 1 + test/integrations/test-DataFrames.jl | 54 +++++++++++++++ test/runtests.jl | 51 +------------- 8 files changed, 84 insertions(+), 168 deletions(-) create mode 100644 src/integrations/DataFrames.jl create mode 100644 test/REQUIRE create mode 100644 test/integrations/test-DataFrames.jl diff --git a/Manifest.toml b/Manifest.toml index fa342c1..f5ceb53 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -9,48 +9,6 @@ git-tree-sha1 = "039106453269e691fb54fb14e2b40f6c26091f62" uuid = "0bcc2ff6-69eb-520d-bede-0374fc5bd2fd" version = "1.1.0" -[[BinaryProvider]] -deps = ["Libdl", "Pkg", "SHA", "Test"] -git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" -uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" -version = "0.5.3" - -[[CategoricalArrays]] -deps = ["Compat", "Future", "Missings", "Printf", "Reexport", "Requires"] -git-tree-sha1 = "94d16e77dfacc59f6d6c1361866906dbb65b6f6b" -uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" -version = "0.5.2" - -[[CodecZlib]] -deps = ["BinaryProvider", "Libdl", "Test", "TranscodingStreams"] -git-tree-sha1 = "e3df104c84dfc108f0ca203fd7f5bbdc98641ae9" -uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.5.1" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "49269e311ffe11ac5b334681d212329002a9832a" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "1.5.1" - -[[DataFrames]] -deps = ["CategoricalArrays", "CodecZlib", "Compat", "DataStreams", "Dates", "InteractiveUtils", "IteratorInterfaceExtensions", "LinearAlgebra", "Missings", "Printf", "Random", "Reexport", "SortingAlgorithms", "Statistics", "StatsBase", "TableTraits", "Tables", "Test", "TranscodingStreams", "Unicode", "WeakRefStrings"] -git-tree-sha1 = "9cfed75401d25d281076eb5d82de148ac2933f9e" -uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -version = "0.17.1" - -[[DataStreams]] -deps = ["Dates", "Missings", "Test", "WeakRefStrings"] -git-tree-sha1 = "69c72a1beb4fc79490c361635664e13c8e4a9548" -uuid = "9a8bc11e-79be-5b39-94d7-1ccc349a1a85" -version = "0.4.1" - -[[DataStructures]] -deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] -git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.15.0" - [[DataValues]] deps = ["Dates", "InteractiveUtils", "LinearAlgebra", "Random", "Test"] git-tree-sha1 = "05e4a87fe52a2af1b4a1ffd3ab2fc996c038b192" @@ -61,10 +19,6 @@ version = "0.4.7" deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - [[Distributed]] deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" @@ -75,10 +29,6 @@ git-tree-sha1 = "c94b0787956629036fb2b20fccde9e52b89d079a" uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" version = "1.0.5" -[[Future]] -deps = ["Random"] -uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" - [[InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" @@ -127,12 +77,6 @@ version = "0.4.0" [[Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" -[[OrderedCollections]] -deps = ["Random", "Serialization", "Test"] -git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.0.2" - [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -149,12 +93,6 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" deps = ["Serialization"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -[[Reexport]] -deps = ["Pkg"] -git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" -uuid = "189a3867-3050-52da-a836-e630ba90ab69" -version = "0.2.0" - [[Requires]] deps = ["Test"] git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" @@ -167,33 +105,13 @@ uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" [[Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - [[Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" -[[SortingAlgorithms]] -deps = ["DataStructures", "Random", "Test"] -git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" -uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" -version = "0.3.1" - [[SparseArrays]] deps = ["LinearAlgebra", "Random"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[StatsBase]] -deps = ["DataStructures", "DelimitedFiles", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] -git-tree-sha1 = "6479f15167b434c765d3508524264bfd63ded7c8" -uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" -version = "0.28.0" - [[TableShowUtils]] deps = ["DataValues", "Dates", "JSON", "Markdown", "Test"] git-tree-sha1 = "14c54e1e96431fb87f0d2f5983f090f1b9d06457" @@ -212,31 +130,13 @@ git-tree-sha1 = "55133a5476b61ec31060e555ffe12da27ac13682" uuid = "382cd787-c1b6-5bf2-a167-d5b971a19bda" version = "0.4.0" -[[Tables]] -deps = ["IteratorInterfaceExtensions", "LinearAlgebra", "Requires", "TableTraits", "Test"] -git-tree-sha1 = "5aa45584645393c1717e0cc1f0362c2ea81470a9" -uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "0.1.17" - [[Test]] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -[[TranscodingStreams]] -deps = ["Pkg", "Random", "Test"] -git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" -uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.8.1" - [[UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[WeakRefStrings]] -deps = ["Missings", "Random", "Test"] -git-tree-sha1 = "cf70c71939e621a3fac4156a8bfb3c80d745794a" -uuid = "ea10d353-3f73-51f8-a26c-33c1cb351aa5" -version = "0.5.7" diff --git a/Project.toml b/Project.toml index 15bb30f..741229c 100644 --- a/Project.toml +++ b/Project.toml @@ -5,11 +5,11 @@ version = "2.1.0" [deps] Bedgraph = "0bcc2ff6-69eb-520d-bede-0374fc5bd2fd" -DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" DataValues = "e7dc6d0d-1eca-5fa6-8ad6-5aecde8b7ea5" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" IterableTables = "1c8ee90f-4401-5389-894e-7a04a3dc0f4d" IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" +Requires = "ae029012-a4dd-5104-9daa-d747884805df" TableShowUtils = "5e66a065-1f0a-5976-b372-e0b8c017ca10" TableTraits = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" TableTraitsUtils = "382cd787-c1b6-5bf2-a167-d5b971a19bda" @@ -18,8 +18,9 @@ TableTraitsUtils = "382cd787-c1b6-5bf2-a167-d5b971a19bda" Bedgraph = "^1.1" [extras] -Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1" +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1" [targets] -test = ["Test", "Query"] +test = ["DataFrames", "Test", "Query"] diff --git a/REQUIRE b/REQUIRE index 09d9876..ae8fb44 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,5 @@ julia 0.7 Bedgraph 1.1.0 -DataFrames 0.9.0 FileIO 1.0.1 IterableTables 0.9.0 IteratorInterfaceExtensions 0.1.1 diff --git a/src/BedgraphFiles.jl b/src/BedgraphFiles.jl index ca8e76e..20d6d25 100644 --- a/src/BedgraphFiles.jl +++ b/src/BedgraphFiles.jl @@ -1,10 +1,11 @@ __precompile__() module BedgraphFiles + using FileIO +using Requires using Bedgraph -using DataFrames using IteratorInterfaceExtensions, TableTraits, TableTraitsUtils using TableShowUtils @@ -12,6 +13,10 @@ using TableShowUtils import IterableTables +function __init__() + @require DataFrames="a93c6f00-e57d-5684-b7b6-d8193f3e46c0" include(joinpath(@__DIR__, "integrations","DataFrames.jl")) +end + const BedgraphFileFormat = File{format"bedGraph"} struct BedgraphFile @@ -19,21 +24,6 @@ struct BedgraphFile keywords end -function Base.convert(::Type{Bedgraph.Record}, row::DataFrameRow) :: Bedgraph.Record - return Bedgraph.Record(row[1], row[2], row[3], row[4]) # Note: using index to allow flexible column names. -end - -function Base.convert(::Type{Vector{Bedgraph.Record}}, df::DataFrame) :: Vector{Bedgraph.Record} - - records = Vector{Bedgraph.Record}(undef, size(df)[1]) - - for (i, row) in enumerate(eachrow(df)) - records[i] = convert(Bedgraph.Record, row) - end - - return records -end - function Base.show(io::IO, source::BedgraphFile) TableShowUtils.printtable(io, getiterator(source), "bedGraph file") end diff --git a/src/integrations/DataFrames.jl b/src/integrations/DataFrames.jl new file mode 100644 index 0000000..14056c3 --- /dev/null +++ b/src/integrations/DataFrames.jl @@ -0,0 +1,16 @@ +@info "BedgraphFiles loading DataFrames integration." + +function Base.convert(::Type{Bedgraph.Record}, row::DataFrames.DataFrameRow) :: Bedgraph.Record + return Bedgraph.Record(row[1], row[2], row[3], row[4]) # Note: using index to allow flexible column names. +end + +function Base.convert(::Type{Vector{Bedgraph.Record}}, df::DataFrames.DataFrame) :: Vector{Bedgraph.Record} + + records = Vector{Bedgraph.Record}(undef, size(df)[1]) + + for (i, row) in enumerate(eachrow(df)) + records[i] = convert(Bedgraph.Record, row) + end + + return records +end diff --git a/test/REQUIRE b/test/REQUIRE new file mode 100644 index 0000000..3b8f98b --- /dev/null +++ b/test/REQUIRE @@ -0,0 +1 @@ +DataFrames 0.9.0 diff --git a/test/integrations/test-DataFrames.jl b/test/integrations/test-DataFrames.jl new file mode 100644 index 0000000..883ab8f --- /dev/null +++ b/test/integrations/test-DataFrames.jl @@ -0,0 +1,54 @@ +@testset "DataFrames" begin + + using DataFrames + + + # DataFrame from Vector{Bedgraph.Record}. + df = DataFrame(Bag.records) + + @test typeof(df) == DataFrame + @test size(df) == (9,4) + + @test df[:chrom] == Bag.chroms + @test df[:first] == Bag.firsts + @test df[:last] == Bag.lasts + @test df[:value] == Bag.values + + @test DataFrame(Bag.records) == Bag.records |> DataFrame + + + # DataFrame from bedGraph file. + df2 = DataFrame(load(Bag.file)) + + @test typeof(df2) == DataFrame + @test size(df2) == (9,4) + + @test df2[:chrom] == Bag.chroms + @test df2[:first] == Bag.firsts + @test df2[:last] == Bag.lasts + @test df2[:value] == Bag.values + + @test DataFrame(load(Bag.file)) == load(Bag.file) |> DataFrame + + + # DataFrame from headerless bedGraph file. + df3 = DataFrame(load(Bag.file_headerless)) + @test typeof(df3) == DataFrame + @test size(df3) == (9,4) + + @test df3[:chrom] == Bag.chroms + @test df3[:first] == Bag.firsts + @test df3[:last] == Bag.lasts + @test df3[:value] == Bag.values + + @test DataFrame(load(Bag.file_headerless)) == load(Bag.file_headerless) |> DataFrame + + + # Save and load from DataFrame. + save(Bag.tmp_output_path, df) + @test df == load(Bag.tmp_output_path) |> DataFrame + + df |> save(Bag.tmp_output_path) + @test df == load(Bag.tmp_output_path) |> DataFrame + +end # test DataFrames diff --git a/test/runtests.jl b/test/runtests.jl index 6fb073e..fcd1cb4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,54 +82,9 @@ Bag.records |> save(Bag.tmp_output_path) load("data.bedgraph") |> @filter(_.chrom == "chr19" && _.first > 49302900 && _.last < 49303800) |> save(Bag.tmp_output_path) @test [Bedgraph.Record("chr19", 49303200, 49303500, 0.0)] == load(Bag.tmp_output_path) |> Vector{Bedgraph.Record} -@testset "DataFrames" begin -# DataFrame from Vector{Bedgraph.Record}. -df = DataFrame(Bag.records) - -@test typeof(df) == DataFrame -@test size(df) == (9,4) - -@test df[:chrom] == Bag.chroms -@test df[:first] == Bag.firsts -@test df[:last] == Bag.lasts -@test df[:value] == Bag.values - -@test DataFrame(Bag.records) == Bag.records |> DataFrame - -# DataFrame from bedGraph file. -df2 = DataFrame(loader) - -@test typeof(df2) == DataFrame -@test size(df2) == (9,4) - -@test df2[:chrom] == Bag.chroms -@test df2[:first] == Bag.firsts -@test df2[:last] == Bag.lasts -@test df2[:value] == Bag.values - -@test DataFrame(loader) == loader |> DataFrame - -# DataFrame from headerless bedGraph file. -df3 = DataFrame(loader_from_headerless) -@test typeof(df3) == DataFrame -@test size(df3) == (9,4) - -@test df3[:chrom] == Bag.chroms -@test df3[:first] == Bag.firsts -@test df3[:last] == Bag.lasts -@test df3[:value] == Bag.values - -@test DataFrame(loader_from_headerless) == loader_from_headerless |> DataFrame - -# Save and load from DataFrame. -save(Bag.tmp_output_path, df) -@test df == load(Bag.tmp_output_path) |> DataFrame - -df |> save(Bag.tmp_output_path) -@test df == load(Bag.tmp_output_path) |> DataFrame - -end # test DataFrames - +@testset "Integrations" begin + include("integrations/test-DataFrames.jl") +end # testset Transformers println() show(load(Bag.file)) From bcd0058b400b5351da259db0e887dfa2331a9ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Thu, 31 Jan 2019 14:47:36 +1100 Subject: [PATCH 04/10] Base.read for BedgraphFile --- src/BedgraphFiles.jl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/BedgraphFiles.jl b/src/BedgraphFiles.jl index ca8e76e..797a6a7 100644 --- a/src/BedgraphFiles.jl +++ b/src/BedgraphFiles.jl @@ -38,6 +38,14 @@ function Base.show(io::IO, source::BedgraphFile) TableShowUtils.printtable(io, getiterator(source), "bedGraph file") end +function Base.read(file::BedgraphFile) :: Vector{Bedgraph.Record} + # Read file using Bedgraph package. + return open(file.filename, "r") do io + Bedgraph.readRecords(io) + end + +end + function load(f::BedgraphFileFormat; args...) return BedgraphFile(f.filename, args) end @@ -47,14 +55,6 @@ TableTraits.isiterabletable(x::BedgraphFile) = true IteratorInterfaceExtensions.isiterable(x::Vector{Bedgraph.Record}) = true #Note: Vector{Bedgraph.Record} is iterable by default. TableTraits.isiterabletable(x::Vector{Bedgraph.Record}) = true - -function _loaddata(path) :: Vector{Bedgraph.Record} - # Read file using bedgraph package. - return open(path, "r") do io - Bedgraph.readRecords(io) - end -end - function IteratorInterfaceExtensions.getiterator(records::Vector{Bedgraph.Record}) columns = [ @@ -73,7 +73,7 @@ end function IteratorInterfaceExtensions.getiterator(file::BedgraphFile) - records = _loaddata(file.filename) + records = read(file) #TODO: Generate iterator from first record? it = getiterator(records) @@ -97,7 +97,7 @@ end function Vector{Bedgraph.Record}(file::B) :: Vector{Bedgraph.Record} where {B<:BedgraphFile} @debug "Vector{Bedgraph.Record}(file::BedgraphFile)" - return _loaddata(file.filename) + return read(file) end function Vector{Bedgraph.Record}(x::T) :: Vector{Bedgraph.Record} where {T} #TODO: consider formalising Records function in bedgraph (e.g. Bedgraph.Records, Bedgraph.Bedgraph.Records) that returns Vector{Bedgraph.Record}. From c8f32cb553b64ca846ac3fe9d4d5d882843d3c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Thu, 28 Feb 2019 08:30:32 +1100 Subject: [PATCH 05/10] Revert badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc400a7..8979c4b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![Build Status](https://travis-ci.org/CiaranOMara/BedgraphFiles.jl.svg?branch=master)](https://travis-ci.org/CiaranOMara/BedgraphFiles.jl) [![Build status](https://ci.appveyor.com/api/projects/status/jny2ep4u3cmly8pj/branch/master?svg=true)](https://ci.appveyor.com/project/CiaranOMara/Bedgraphfiles-jl/branch/master) -[![BedgraphFiles](http://pkg.julialang.org/badges/BedgraphFiles_0.7.svg)](http://pkg.julialang.org/?pkg=BedgraphFiles) +[![BedgraphFiles](http://pkg.julialang.org/badges/BedgraphFiles_0.6.svg)](http://pkg.julialang.org/?pkg=BedgraphFiles) [![codecov.io](http://codecov.io/github/CiaranOMara/BedgraphFiles.jl/coverage.svg?branch=master)](http://codecov.io/github/CiaranOMara/BedgraphFiles.jl?branch=master) [![Coverage Status](https://coveralls.io/repos/github/CiaranOMara/BedgraphFiles.jl/badge.svg?branch=master)](https://coveralls.io/github/CiaranOMara/BedgraphFiles.jl?branch=master) From e11c3badb70b11bb47447c6a0be625e5a8f13598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Mon, 11 Mar 2019 19:48:41 +1100 Subject: [PATCH 06/10] =?UTF-8?q?Don=E2=80=99t=20announce=20integrations?= =?UTF-8?q?=20unless=20debugging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/integrations/DataFrames.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrations/DataFrames.jl b/src/integrations/DataFrames.jl index 14056c3..33b5191 100644 --- a/src/integrations/DataFrames.jl +++ b/src/integrations/DataFrames.jl @@ -1,4 +1,4 @@ -@info "BedgraphFiles loading DataFrames integration." +@debug "BedgraphFiles loading DataFrames integration." function Base.convert(::Type{Bedgraph.Record}, row::DataFrames.DataFrameRow) :: Bedgraph.Record return Bedgraph.Record(row[1], row[2], row[3], row[4]) # Note: using index to allow flexible column names. From 5be4d4165e68e845286f5e16360469fd3962bf2c Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Mon, 13 May 2019 11:06:58 -0700 Subject: [PATCH 07/10] Delete REQUIRE files --- REQUIRE | 8 -------- test/REQUIRE | 1 - 2 files changed, 9 deletions(-) delete mode 100644 REQUIRE delete mode 100644 test/REQUIRE diff --git a/REQUIRE b/REQUIRE deleted file mode 100644 index ae8fb44..0000000 --- a/REQUIRE +++ /dev/null @@ -1,8 +0,0 @@ -julia 0.7 -Bedgraph 1.1.0 -FileIO 1.0.1 -IterableTables 0.9.0 -IteratorInterfaceExtensions 0.1.1 -TableShowUtils 0.2.0 -TableTraits 0.4.0 -TableTraitsUtils 0.3.0 diff --git a/test/REQUIRE b/test/REQUIRE deleted file mode 100644 index 3b8f98b..0000000 --- a/test/REQUIRE +++ /dev/null @@ -1 +0,0 @@ -DataFrames 0.9.0 From 59132e1c08ff37285b3d7cd5ed50211118b362ef Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Mon, 13 May 2019 11:07:27 -0700 Subject: [PATCH 08/10] Update [compat] in Project.toml --- Project.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Project.toml b/Project.toml index 741229c..358423e 100644 --- a/Project.toml +++ b/Project.toml @@ -15,7 +15,14 @@ TableTraits = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" TableTraitsUtils = "382cd787-c1b6-5bf2-a167-d5b971a19bda" [compat] +julia = "0.7, ^1" Bedgraph = "^1.1" +FileIO = "^1.0.1" +IteratorInterfaceExtensions = "^0.1.1, ^1" +IterableTables = ">=0.9.0" +TableShowUtils = "^0.2.0" +TableTraits = "^0.4, ^1" +TableTraitsUtils = "^0.3, ^0.4" [extras] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" From 66dd8cbe61a74257ca24344ac4148e2a29aa178f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Thu, 23 May 2019 15:26:08 +1000 Subject: [PATCH 09/10] Remove badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 8979c4b..13204e3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![Build Status](https://travis-ci.org/CiaranOMara/BedgraphFiles.jl.svg?branch=master)](https://travis-ci.org/CiaranOMara/BedgraphFiles.jl) [![Build status](https://ci.appveyor.com/api/projects/status/jny2ep4u3cmly8pj/branch/master?svg=true)](https://ci.appveyor.com/project/CiaranOMara/Bedgraphfiles-jl/branch/master) -[![BedgraphFiles](http://pkg.julialang.org/badges/BedgraphFiles_0.6.svg)](http://pkg.julialang.org/?pkg=BedgraphFiles) [![codecov.io](http://codecov.io/github/CiaranOMara/BedgraphFiles.jl/coverage.svg?branch=master)](http://codecov.io/github/CiaranOMara/BedgraphFiles.jl?branch=master) [![Coverage Status](https://coveralls.io/repos/github/CiaranOMara/BedgraphFiles.jl/badge.svg?branch=master)](https://coveralls.io/github/CiaranOMara/BedgraphFiles.jl?branch=master) From 30c80502fab51ad7257e668c34588ca6ba61b8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Thu, 23 May 2019 15:29:35 +1000 Subject: [PATCH 10/10] Increment version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 358423e..e2bd1f8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BedgraphFiles" uuid = "85eb9095-274b-55ce-be28-9e90f41ac741" authors = ["CiarĂ¡n O'Mara "] -version = "2.1.0" +version = "2.1.1" [deps] Bedgraph = "0bcc2ff6-69eb-520d-bede-0374fc5bd2fd"