Skip to content

Commit

Permalink
Function to generate basic header
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Nov 24, 2017
1 parent 552442b commit bd44bc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/Bedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Base.convert(::Type{Track}, str::String)
return convert(Track, data)
end

# Check if the track data in four column BED format.
# Check if the track data is in the four column BED format.
function isLikeTrack(line::String) :: Bool
return ismatch(r"^\s*([A-Za-z]+\S*)\s+(\d+)\s+(\d+)\s+(\S*\d)\s*$", line) # Note: is like a Track.
end
Expand Down Expand Up @@ -286,6 +286,17 @@ end

expand(chromStart::DataArrays.DataArray{Any,1}, chromEnd::DataArrays.DataArray{Any,1}, dataValue::DataArrays.DataArray{Any,1}) = expand(nucleotides(chromStart), nucleotides(chromEnd), dataValues(dataValue))

function generateBasicHeader(chrom::String, pos_start::Int, pos_end::Int; bump_forward=true) :: Vector{String}

if bump_forward
pos_start += 1
pos_end += 1
end

return ["browser position $chrom:$pos_start-$pos_end", "track type=bedGraph"]
end


# chrom chromStart chromEnd dataValue
function write(chrom::Vector{String}, chromStart::Vector{Int}, chromEnd::Vector{Int}, dataValue::Vector{T} ; outfile="out.bedgraph") where {T<:Real}

Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const parameter_line_long = "track type=bedGraph name=track_label description=ce
const file = joinpath(@__DIR__, "data.bedgraph")
const file_headerless = joinpath(@__DIR__, "data-headerless.bedgraph")

const header = [browser1, browser2, browser3, browser4, comment1, comment2, comment3, comment4, parameter_line]
const tracks = [Track(track1), Track(line2), Track(line3), Track(line4), Track(line5), Track(line6), Track(line7), Track(line8), Track(line9)]

@testset "I/O" begin
Expand All @@ -73,7 +74,7 @@ end

open(file, "r") do io # Note: reading tracks first to check seek.
@test Bedgraph.readTracks(io) == tracks
@test Bedgraph.readHeader(io) == [browser1, browser2, browser3, browser4, comment1, comment2, comment3, comment4, parameter_line]
@test Bedgraph.readHeader(io) == header
end

open(file_headerless, "r") do io # Note: reading tracks first to check seek.
Expand Down

0 comments on commit bd44bc1

Please sign in to comment.