Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciarán O’Mara authored and Ciarán O’Mara committed Aug 28, 2017
2 parents b1cbbf0 + 4802230 commit ac9f602
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.md
@@ -1,10 +1,11 @@
# BedgraphFiles
# BedgraphFiles.jl

[![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)

## Overview

Expand Down
5 changes: 3 additions & 2 deletions 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
14 changes: 8 additions & 6 deletions src/BedgraphFiles.jl
@@ -1,8 +1,9 @@
module BedgraphFiles

# using Bedgraph
using IterableTables, DataValues, DataFrames
using TableTraits, DataValues, DataFrames
using FileIO
import IterableTables

try add_format(format"Bedgraph", (), [".bedgraph"], [:BedgraphFiles]) end # TODO: Remove once BedgraphFiles is registered with FileIO.

Expand All @@ -14,17 +15,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 +48,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
43 changes: 34 additions & 9 deletions test/runtests.jl
@@ -1,28 +1,53 @@
using FileIO
using IterableTables
using BedgraphFiles
using TableTraits
using DataFrames
using Base.Test

try add_format(format"Bedgraph", (), [".bedgraph"], [:BedgraphFiles]) end # TODO: Remove once files is registered with FileIO.

@testset "BedgraphFiles" begin

df = load(joinpath(@__DIR__, "data.bedgraph")) |> DataFrame
const chrom = ["chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19", "chr19"]
const chromStart = [49302000, 49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400]
const chromEnd = [49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400, 49304700]
const dataValue = [-1.0, -0.75, -0.50, -0.25, 0.0, 0.25, 0.50, 0.75, 1.00]

file = joinpath(@__DIR__, "data.bedgraph")

@test isfile(file)

# Load tests.
loaded = load(file)
@test isiterable(loaded) == true

## DataFrame
df = DataFrame(loaded)

@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] == chrom
@test df[:chromStart] == chromStart
@test df[:chromEnd] == chromEnd
@test df[:dataValue] == dataValue

## Query DataFrame
df2 = loaded |> DataFrame
@test size(df2) == (9,4)

@test df2[:chrom] == chrom
@test df2[:chromStart] == chromStart
@test df2[:chromEnd] == chromEnd
@test df2[:dataValue] == dataValue

# Save test.
output_filename = tempname() * ".bedgraph"

try
df |> save(output_filename)

df2 = load(output_filename) |> DataFrame
loaded_df = load(output_filename) |> DataFrame

@test df == df2
@test df == loaded_df
finally
gc()
rm(output_filename)
Expand Down

0 comments on commit ac9f602

Please sign in to comment.