Giter VIP home page Giter VIP logo

bedgraph.jl's Introduction

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)

bedgraph.jl's People

Contributors

ciaranomara avatar tkelman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.