Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Aug 27, 2017
2 parents b1cbbf0 + 7d235b5 commit 17b124e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -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
13 changes: 7 additions & 6 deletions src/BedgraphFiles.jl
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 17b124e

Please sign in to comment.