Bedgraph.jl

Read and write support for bedGraph file format.
Author CiaranOMara
Popularity
0 Stars
Updated Last
8 Months Ago
Started In
August 2017

Bedgraph.jl

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Unit Tests codecov

This project follows the semver pro forma and uses the git-flow branching model.

Description

This package provides read and write support for Bedgraph files.

Note: this package does not currently handle bedGraph meta data such as the track definition or browser lines.

Installation

You can install Bedgraph from the Julia REPL. Press ] to enter pkg mode, then enter the following:

add Bedgraph

If you are interested in the cutting edge of the development, please check out the develop branch to try new features before release.

Usage

Reading and writing bedGraph files

See source for optional bump_back, bump_forward, and right_open key values. These options are included in the pertinent read/write functions to handle quirks of the zero-based and half-open nature of the bedGraph format.

Read header/meta

using Bedgraph

header = read(file, BedgraphHeader{Vector{String}})

Read records

Read all records at once.

using Bedgraph

records = read(file, Vector{Bedgraph.Record})
using Bedgraph

records = open(file, "r") do io
    return read(io, Vector{Bedgraph.Record})
end

Alternatively you may want to read and process records individually.

open(file, "r") do io
    while !eof(seek(io, Bedgraph.Record))
        record = read(io, Bedgraph.Record) #Note: no protection.
        # Process record.
    end
end

Write a bedGraph file

Bedgraph.jl currently provides two write functions: one for Bedgraph.BedgraphHeader, and one for Bedgraph.Record, which also accepts Vector{Bedgraph.Record}.

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]

records = Bedgraph.Record.(chroms, firsts, lasts, values)

sort!(records)

header = Bedgraph.generate_basic_header(records)

write("data.bedgraph", header, records)
using Bedgraph

records = [Record("chr19", 49302000, 49302300, -1.0), Record("chr19", 49302300, 49302600, -1.75)]
header = Bedgraph.generate_basic_header("chr19", records[1].first, records[end].last, bump_forward=false)

open(output_file, "w") do io
    write(io, header, records)
end

Converting records

Below are some examples of Bedgraph.Record conversions provided by this package.

using Bedgraph

record = Record("chr1", 10, 20)

# Convert record to NamedTuple.
nt = convert(NamedTuple, record)

# Convert record to NamedTuple and rename fields.
nt = convert(NamedTuple{(:chrom, :left, :right, :value)}, record)

Required Packages

No packages found.

Used By Packages