dummy-link

Bedgraph

Read and write support for bedGraph file format.

Readme

Bedgraph.jl

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

This project will try to follow the semver pro forma.

Description

This package provides read and write support for Bedgraph files, as well as other useful utilities.

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.generateBasicHeader(records)

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

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

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

Compression and decompression of data

Compress data values

Compress data to chromosome coordinates of the zero-based, half-open format.

using Bedgraph

chrom "chr1"
n = 49302000:49304700
decompressed_values = [-1.0, -1.0, -1.0, ..., 1.00, 1.00, 1.00]

compressed_records = Bedgraph.compress(chrom, n, decompressed_values)
using Bedgraph

const records = [Record("chr19", 49302000, 49302300, -1.0), Record("chr19", 49302300, 49302600, -1.75)]

compressed_records = Bedgraph.compress("chr19", n, decompressed_value)

Decompress record data

Decompress chromosome coordinates from the zero-based, half-open format.

Note: please be aware of the order of returned items.

using Bedgraph

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]

(n, decompressed_values, decompressed_chroms) = Bedgraph.expand(chroms, firsts, lasts, values)


using Bedgraph

const records = [Record("chr19", 49302000, 49302300, -1.0), Record("chr19", 49302300, 49302600, -1.75)]

n, decompressed_values, decompressed_chroms = Bedgraph.expand(records)

First Commit

08/17/2017

Last Touched

about 1 month ago

Commits

149 commits

Requires:

Used By: