diff --git a/REQUIRE b/REQUIRE index 8d3832f..33b35bf 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,5 @@ julia 0.6 -IterableTables 0.4.2 +TableTraits 0.0.1 +IterableTables 0.5.0 FileIO 0.5.1 -DataFrames 0.9.1 +DataFrames 0.9.0 diff --git a/src/BedgraphFiles.jl b/src/BedgraphFiles.jl index f62746b..7cbfa9f 100644 --- a/src/BedgraphFiles.jl +++ b/src/BedgraphFiles.jl @@ -1,7 +1,7 @@ module BedgraphFiles # using Bedgraph -using IterableTables, DataValues, DataFrames +using TableTraits, IterableTables, DataValues, DataFrames using FileIO try add_format(format"Bedgraph", (), [".bedgraph"], [:BedgraphFiles]) end # TODO: Remove once BedgraphFiles is registered with FileIO. @@ -14,17 +14,18 @@ function load(f::FileIO.File{FileIO.format"Bedgraph"}) return BedgraphFile(f.filename) end -IterableTables.isiterable(x::BedgraphFile) = true -IterableTables.isiterabletable(x::BedgraphFile) = true +TableTraits.isiterable(x::BedgraphFile) = true +TableTraits.isiterabletable(x::BedgraphFile) = true -function IterableTables.getiterator(file::BedgraphFile) +function TableTraits.getiterator(file::BedgraphFile) # TODO: read using bedgraph package. # df = Bedgraph.read(file.filename, DataFrame) data = readdlm(file.filename) - df = DataFrame(Chromosome=data[:,1], Start=data[:,2], End=data[:,3], Value=data[:,4]) + # Track data format: chrom chromStart chromEnd dataValue + df = DataFrame(chrom=data[:,1], chromStart=data[:,2], chromEnd=data[:,3], dataValue=data[:,4]) it = getiterator(df) @@ -46,7 +47,7 @@ function save(f::FileIO.File{FileIO.format"Bedgraph"}, data) # end try - output = [convert(Array,it.df[:Chromosome]) convert(Array,it.df[:Start]) convert(Array,it.df[:End]) convert(Array,it.df[:Value]) ] + output = [convert(Array,it.df[:chrom]) convert(Array,it.df[:chromStart]) convert(Array,it.df[:chromEnd]) convert(Array,it.df[:dataValue]) ] writedlm(f.filename, output) end diff --git a/test/runtests.jl b/test/runtests.jl index ed66ec0..8162a04 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,10 +10,10 @@ df = load(joinpath(@__DIR__, "data.bedgraph")) |> DataFrame @test size(df) == (9,4) -@test df[:Chromosome] == ["chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19"] -@test df[:Start] == [49302000, 49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400] -@test df[:End] == [49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400, 49304700] -@test df[:Value] == [-1.0, -0.75, -0.50, -0.25, 0.0, 0.25, 0.50, 0.75, 1.00] +@test df[:chrom] == ["chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19"] +@test df[:chromStart] == [49302000, 49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400] +@test df[:chromEnd] == [49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400, 49304700] +@test df[:dataValue] == [-1.0, -0.75, -0.50, -0.25, 0.0, 0.25, 0.50, 0.75, 1.00] output_filename = tempname() * ".bedgraph"